summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2012-12-29 12:29:50 -0800
committerMarcel Holtmann <marcel@holtmann.org>2012-12-29 14:50:14 -0800
commit886cd42f6c975aefa7a551da50ebff62be459310 (patch)
tree655e3cfd76ca9e30bcf08a336ba90e55fcc1a0ba
parent7e9f37e245ce06037c99ca2362c2ecf06c2bddb2 (diff)
downloadneard-886cd42f6c975aefa7a551da50ebff62be459310.tar.gz
neard-886cd42f6c975aefa7a551da50ebff62be459310.tar.bz2
neard-886cd42f6c975aefa7a551da50ebff62be459310.zip
gdbus: Add support for proxy property change notifications
-rw-r--r--gdbus/client.c23
-rw-r--r--gdbus/gdbus.h11
2 files changed, 30 insertions, 4 deletions
diff --git a/gdbus/client.c b/gdbus/client.c
index b46d5e4..4c3bad6 100644
--- a/gdbus/client.c
+++ b/gdbus/client.c
@@ -60,6 +60,8 @@ struct GDBusProxy {
char *interface;
GHashTable *prop_list;
char *match_rule;
+ GDBusPropertyFunction prop_func;
+ void *prop_data;
};
struct prop_entry {
@@ -215,6 +217,9 @@ static void add_property(GDBusProxy *proxy, const char *name,
prop_entry_update(prop, &value);
+ if (proxy->prop_func)
+ proxy->prop_func(proxy, name, &value, proxy->prop_data);
+
if (client == NULL)
return;
@@ -229,6 +234,9 @@ static void add_property(GDBusProxy *proxy, const char *name,
return;
g_hash_table_replace(proxy->prop_list, prop->name, prop);
+
+ if (proxy->prop_func)
+ proxy->prop_func(proxy, name, &value, proxy->prop_data);
}
static void update_properties(GDBusProxy *proxy, DBusMessageIter *iter)
@@ -655,6 +663,18 @@ gboolean g_dbus_proxy_method_call(GDBusProxy *proxy, const char *method,
return TRUE;
}
+gboolean g_dbus_proxy_set_property_watch(GDBusProxy *proxy,
+ GDBusPropertyFunction function, void *user_data)
+{
+ if (proxy == NULL)
+ return FALSE;
+
+ proxy->prop_func = function;
+ proxy->prop_data = user_data;
+
+ return TRUE;
+}
+
static void properties_changed(GDBusClient *client, const char *path,
DBusMessage *msg)
{
@@ -702,6 +722,9 @@ static void properties_changed(GDBusClient *client, const char *path,
g_hash_table_remove(proxy->prop_list, name);
+ if (proxy->prop_func)
+ proxy->prop_func(proxy, name, NULL, proxy->prop_data);
+
if (client->property_changed)
client->property_changed(proxy, name, NULL,
client->user_data);
diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index 4caa31d..b0de6d5 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -304,6 +304,13 @@ gboolean g_dbus_proxy_method_call(GDBusProxy *proxy, const char *method,
GDBusReturnFunction function, void *user_data,
GDBusDestroyFunction destroy);
+typedef void (* GDBusProxyFunction) (GDBusProxy *proxy, void *user_data);
+typedef void (* GDBusPropertyFunction) (GDBusProxy *proxy, const char *name,
+ DBusMessageIter *iter, void *user_data);
+
+gboolean g_dbus_proxy_set_property_watch(GDBusProxy *proxy,
+ GDBusPropertyFunction function, void *user_data);
+
GDBusClient *g_dbus_client_new(DBusConnection *connection,
const char *service, const char *path);
@@ -317,10 +324,6 @@ gboolean g_dbus_client_set_disconnect_watch(GDBusClient *client,
gboolean g_dbus_client_set_signal_watch(GDBusClient *client,
GDBusMessageFunction function, void *user_data);
-typedef void (* GDBusProxyFunction) (GDBusProxy *proxy, void *user_data);
-typedef void (* GDBusPropertyFunction) (GDBusProxy *proxy, const char *name,
- DBusMessageIter *iter, void *user_data);
-
gboolean g_dbus_client_set_proxy_handlers(GDBusClient *client,
GDBusProxyFunction proxy_added,
GDBusProxyFunction proxy_removed,