diff options
author | ERAMOTO Masaya <eramoto.masaya@jp.fujitsu.com> | 2017-12-28 14:44:15 +0900 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2018-01-02 14:15:49 -0200 |
commit | 529790b6a5d599b961469a7c800b164a2e5d3388 (patch) | |
tree | 1aa45c6b8bb314ae6f62ce53cbf35d018b519e97 /gdbus/client.c | |
parent | 6be85ab3bf67a54b8ce71ab0c3ffeb3707f66ded (diff) | |
download | bluez-529790b6a5d599b961469a7c800b164a2e5d3388.tar.gz |
gdbus: Introduce g_dbus_proxy_path_lookup()
g_dbus_proxy_path_lookup() returns the path of the proxy that matches the
passed path. It also returns the index of the proxy coming next to the
matched proxy in the passed list.
Diffstat (limited to 'gdbus/client.c')
-rw-r--r-- | gdbus/client.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/gdbus/client.c b/gdbus/client.c index f9095574d..9364be7ae 100644 --- a/gdbus/client.c +++ b/gdbus/client.c @@ -26,6 +26,7 @@ #endif #include <stdio.h> +#include <string.h> #include <glib.h> #include <dbus/dbus.h> @@ -376,6 +377,26 @@ GDBusProxy *g_dbus_proxy_lookup(GList *list, int *index, const char *path, return NULL; } +char *g_dbus_proxy_path_lookup(GList *list, int *index, const char *path) +{ + int len = strlen(path); + GList *l; + + for (l = g_list_nth(list, index ? *index : 0); l; l = g_list_next(l)) { + GDBusProxy *proxy = l->data; + + const char *proxy_path = g_dbus_proxy_get_path(proxy); + + if (index) + (*index)++; + + if (!strncasecmp(proxy_path, path, len)) + return strdup(proxy_path); + } + + return NULL; +} + static gboolean properties_changed(DBusConnection *conn, DBusMessage *msg, void *user_data) { |