diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2010-05-13 14:24:32 +0200 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2010-05-13 14:24:32 +0200 |
commit | 83a6632160cc24de958206623264772e532b254a (patch) | |
tree | 28dc6d47e7fbdd1ab7295a205c4897ced4c8fe6b | |
parent | 4b4d04c50a07db309b03e8000a4a165a102c97d6 (diff) | |
download | connman-83a6632160cc24de958206623264772e532b254a.tar.gz connman-83a6632160cc24de958206623264772e532b254a.tar.bz2 connman-83a6632160cc24de958206623264772e532b254a.zip |
Add initial support for LookupService helper method
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | doc/manager-api.txt | 14 | ||||
-rw-r--r-- | src/connman.h | 1 | ||||
-rw-r--r-- | src/manager.c | 20 | ||||
-rw-r--r-- | src/service.c | 28 | ||||
-rwxr-xr-x | test/find-service | 17 |
6 files changed, 81 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index 6be9e482..4797b878 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 8eaededd..1aeb0557 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 9cdd71e8..0ddb3ade 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 6561a78c..b806ba29 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 7c349236..c3338186 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 00000000..e9aad177 --- /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 <pattern>" % (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) |