gdbus: Add g_dbus_add_properties_watch function
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Tue, 27 Nov 2012 12:51:20 +0000 (14:51 +0200)
committerMarcel Holtmann <marcel@holtmann.org>
Fri, 30 Nov 2012 09:01:06 +0000 (10:01 +0100)
Convenient function to create watches for D-Bus properties.

gdbus/gdbus.h
gdbus/watch.c

index 6aafc61..dd21f86 100644 (file)
@@ -243,6 +243,11 @@ guint g_dbus_add_signal_watch(DBusConnection *connection,
                                const char *interface, const char *member,
                                GDBusSignalFunction function, void *user_data,
                                GDBusDestroyFunction destroy);
+guint g_dbus_add_properties_watch(DBusConnection *connection,
+                               const char *sender, const char *path,
+                               const char *interface,
+                               GDBusSignalFunction function, void *user_data,
+                               GDBusDestroyFunction destroy);
 gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
 void g_dbus_remove_all_watches(DBusConnection *connection);
 
index 1cd1211..9e4f994 100644 (file)
@@ -752,6 +752,34 @@ guint g_dbus_add_signal_watch(DBusConnection *connection,
        return cb->id;
 }
 
+guint g_dbus_add_properties_watch(DBusConnection *connection,
+                               const char *sender, const char *path,
+                               const char *interface,
+                               GDBusSignalFunction function, void *user_data,
+                               GDBusDestroyFunction destroy)
+{
+       struct filter_data *data;
+       struct filter_callback *cb;
+
+       data = filter_data_get(connection, signal_filter, sender, path,
+                               DBUS_INTERFACE_PROPERTIES, "PropertiesChanged",
+                               interface);
+       if (data == NULL)
+               return 0;
+
+       cb = filter_data_add_callback(data, NULL, NULL, function, destroy,
+                                       user_data);
+       if (cb == NULL)
+               return 0;
+
+       if (data->name != NULL && data->name_watch == 0)
+               data->name_watch = g_dbus_add_service_watch(connection,
+                                                       data->name, NULL,
+                                                       NULL, NULL, NULL);
+
+       return cb->id;
+}
+
 gboolean g_dbus_remove_watch(DBusConnection *connection, guint id)
 {
        struct filter_data *data;