From: Marcel Holtmann Date: Thu, 13 May 2010 12:24:32 +0000 (+0200) Subject: Add initial support for LookupService helper method X-Git-Tag: accepted/2.0alpha-wayland/20121110.002834~2749 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=83a6632160cc24de958206623264772e532b254a;p=profile%2Fivi%2Fconnman.git Add initial support for LookupService helper method --- diff --git a/Makefile.am b/Makefile.am index 6be9e48..4797b87 100644 --- a/Makefile.am +++ b/Makefile.am @@ -143,7 +143,7 @@ test_scripts = test/get-state test/list-profiles test/list-services \ test/test-manager test/test-connman test/monitor-connman \ test/connect-vpn test/disconnect-vpn test/list-providers \ test/monitor-manager test/test-counter test/set-ip-method \ - test/set-nameservers test/set-domains + test/set-nameservers test/set-domains test/find-service if TEST testdir = $(pkglibdir)/test diff --git a/doc/manager-api.txt b/doc/manager-api.txt index 8eaeded..1aeb055 100644 --- a/doc/manager-api.txt +++ b/doc/manager-api.txt @@ -69,6 +69,20 @@ Methods dict GetProperties() Possible Errors: [service].Error.InvalidArguments + object LookupService(string pattern) + + Lookup a service matching the specific pattern. + + Examples are interface names like "eth0", "wlan0" + etc. or service names like "hotspot" etc. + + In case of multiple services match the the pattern + an error is returned. + + Possible Errors: [service].Error.InvalidArguments + [service].Error.NotUnique + [service].Error.NotFound + object ConnectService(dict network) Connect to a network specified by the given diff --git a/src/connman.h b/src/connman.h index 9cdd71e..0ddb3ad 100644 --- a/src/connman.h +++ b/src/connman.h @@ -413,6 +413,7 @@ int __connman_service_indicate_error(struct connman_service *service, enum connman_service_error error); int __connman_service_indicate_default(struct connman_service *service); +int __connman_service_lookup(const char *pattern, const char **path); int __connman_service_connect(struct connman_service *service); int __connman_service_disconnect(struct connman_service *service); int __connman_service_create_and_connect(DBusMessage *msg); diff --git a/src/manager.c b/src/manager.c index 6561a78..b806ba2 100644 --- a/src/manager.c +++ b/src/manager.c @@ -413,6 +413,25 @@ static DBusMessage *disable_technology(DBusConnection *conn, return NULL; } +static DBusMessage *lookup_service(DBusConnection *conn, + DBusMessage *msg, void *data) +{ + const char *pattern, *path; + int err; + + DBG("conn %p", conn); + + dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern, + DBUS_TYPE_INVALID); + + err = __connman_service_lookup(pattern, &path); + if (err < 0) + return __connman_error_failed(msg, -err); + + return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &path, + DBUS_TYPE_INVALID); +} + static DBusMessage *connect_service(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -596,6 +615,7 @@ static GDBusMethodTable manager_methods[] = { G_DBUS_METHOD_FLAG_ASYNC }, { "DisableTechnology", "s", "", disable_technology, G_DBUS_METHOD_FLAG_ASYNC }, + { "LookupService", "s", "o", lookup_service, }, { "ConnectService", "a{sv}", "o", connect_service, G_DBUS_METHOD_FLAG_ASYNC }, { "ConnectProvider", "a{sv}", "o", connect_provider, diff --git a/src/service.c b/src/service.c index 7c34923..c333818 100644 --- a/src/service.c +++ b/src/service.c @@ -2115,6 +2115,34 @@ int __connman_service_disconnect(struct connman_service *service) } /** + * __connman_service_lookup: + * @pattern: search pattern + * @path: return object path + * + * Look up a service path from a search pattern + */ +int __connman_service_lookup(const char *pattern, const char **path) +{ + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init(&iter, service_hash); + + while (g_hash_table_iter_next(&iter, &key, &value) == TRUE) { + GSequenceIter *iter = value; + struct connman_service *service = g_sequence_get(iter); + + if (g_strcmp0(service->identifier, pattern) == 0 || + g_strcmp0(service->name, pattern) == 0) { + *path = (const char *) service->path; + return 0; + } + } + + return -ENXIO; +} + +/** * lookup_by_identifier: * @identifier: service identifier * diff --git a/test/find-service b/test/find-service new file mode 100755 index 0000000..e9aad17 --- /dev/null +++ b/test/find-service @@ -0,0 +1,17 @@ +#!/usr/bin/python + +import sys +import dbus + +if (len(sys.argv) < 2): + print "Usage: %s " % (sys.argv[0]) + sys.exit(1) + +bus = dbus.SystemBus() + +manager = dbus.Interface(bus.get_object('org.moblin.connman', '/'), + 'org.moblin.connman.Manager') + +path = manager.LookupService(sys.argv[1]) + +print "Service is %s" % (path)