gdbus: Make proxy_lookup() global
Also adds the following feature to g_dbus_proxy_lookup().
- It is more robust even if a proxy is NULL.
- It checks if the passed interface is NULL.
- It looks up from the position of the list specified by the index.
diff --git a/gdbus/client.c b/gdbus/client.c
index ab40596..f909557 100644
--- a/gdbus/client.c
+++ b/gdbus/client.c
@@ -352,16 +352,24 @@
dbus_message_unref(msg);
}
-static GDBusProxy *proxy_lookup(GList *list, const char *path,
+GDBusProxy *g_dbus_proxy_lookup(GList *list, int *index, const char *path,
const char *interface)
{
GList *l;
- for (l = g_list_first(list); l; l = g_list_next(l)) {
- GDBusProxy *proxy = l->data;
+ if (!interface)
+ return NULL;
- if (g_str_equal(proxy->interface, interface) == TRUE &&
- g_str_equal(proxy->obj_path, path) == TRUE)
+ for (l = g_list_nth(list, index ? *index : 0); l; l = g_list_next(l)) {
+ GDBusProxy *proxy = l->data;
+ const char *proxy_iface = g_dbus_proxy_get_interface(proxy);
+ const char *proxy_path = g_dbus_proxy_get_path(proxy);
+
+ if (index)
+ (*index)++;
+
+ if (g_str_equal(proxy_iface, interface) == TRUE &&
+ g_str_equal(proxy_path, path) == TRUE)
return proxy;
}
@@ -519,7 +527,8 @@
if (client == NULL)
return NULL;
- proxy = proxy_lookup(client->proxy_list, path, interface);
+ proxy = g_dbus_proxy_lookup(client->proxy_list, NULL,
+ path, interface);
if (proxy)
return g_dbus_proxy_ref(proxy);
@@ -992,7 +1001,8 @@
if (g_str_equal(interface, DBUS_INTERFACE_PROPERTIES) == TRUE)
return;
- proxy = proxy_lookup(client->proxy_list, path, interface);
+ proxy = g_dbus_proxy_lookup(client->proxy_list, NULL,
+ path, interface);
if (proxy && !proxy->pending) {
update_properties(proxy, iter, FALSE);
return;
diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index e37385f..85cb968 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -339,6 +339,9 @@
gboolean g_dbus_proxy_get_property(GDBusProxy *proxy, const char *name,
DBusMessageIter *iter);
+GDBusProxy *g_dbus_proxy_lookup(GList *list, int *index, const char *path,
+ const char *interface);
+
gboolean g_dbus_proxy_refresh_property(GDBusProxy *proxy, const char *name);
typedef void (* GDBusResultFunction) (const DBusError *error, void *user_data);