/srv/mercurial-server/detachablepurple: 62eaba3fee48: Going mult...

Gilles Bedel gillux at cpw.pidgin.im
Fri Jun 15 22:01:39 EDT 2012


Changeset: 62eaba3fee48898e24767f7241ab720220f19c5d
Author:	 Gilles Bedel <gillux at cpw.pidgin.im>
Date:	 2012-05-20 13:21 +0000
Branch:	 cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/62eaba3fee48

Description:

Going multi-interface. Adapted the signal registration part,
so that we register every interface of the given object.

diffstat:

 libpurple/pobject.c |  48 ++++++++++++++++++++++++++++++++----------------
 libpurple/pobject.h |   9 ++++-----
 2 files changed, 36 insertions(+), 21 deletions(-)

diffs (101 lines):

diff --git a/libpurple/pobject.c b/libpurple/pobject.c
--- a/libpurple/pobject.c
+++ b/libpurple/pobject.c
@@ -902,26 +902,44 @@
 	g_free (paramv);
 }
 
-guint
+void
 purple_object_generic_dbus_signal_subscribe(gpointer object, GDBusConnection *dbus_conn)
 {
 	PurpleObject *pobj = PURPLE_OBJECT(object);
+	PurpleObjectClass *pobjclass = PURPLE_OBJECT_GET_CLASS(pobj);
+	GDBusInterfaceInfo *ifaceinfo;
+	GType type, child;
 	guint reg_id;
 
-	reg_id = g_dbus_connection_signal_subscribe
-	          (dbus_conn, NULL, /* TODO: is NULL for 'sender' what we want? */
-	           PURPLE_OBJECT_GET_CLASS(pobj)->dbus_ifaceinfo->name,
-	           NULL, /* any signal name */
-	           purple_object_get_dbus_path(pobj),
-	           NULL, /* any first arg */
-	           G_DBUS_SIGNAL_FLAGS_NONE,
-	           purple_object_generic_dbus_sighandler, object, NULL);
+	/* Step from the most derived type to PurpleObject
+	 * type and retreive each associated D-Bus interface info. */
+	type = G_OBJECT_TYPE(pobj);
+	do {
+		ifaceinfo = g_datalist_id_get_data(&pobjclass->dbus_ifaceinfos,
+		                                   g_type_qname(type));
+		if (ifaceinfo) {
+			reg_id = g_dbus_connection_signal_subscribe
+			          (dbus_conn, NULL, /* TODO: is NULL for 'sender' what we want? */
+			           ifaceinfo->name,
+			           NULL, /* any signal name */
+			           purple_object_get_dbus_path(pobj),
+			           NULL, /* any first arg */
+			           G_DBUS_SIGNAL_FLAGS_NONE,
+			           purple_object_generic_dbus_sighandler,
+			           object, NULL);
 	
-	if (reg_id == 0) {
-		purple_debug_error("dbus", "Failed to subscribe %s to D-Bus signals\n",
-                                   G_OBJECT_TYPE_NAME(object));
+			if (reg_id == 0) {
+				purple_debug_error("dbus",
+				  "Failed to subscribe a %s with interface %s to D-Bus signals\n",
+				  G_OBJECT_TYPE_NAME(object), ifaceinfo->name);
+			} else {
+				purple_object_add_dbus_reg_id(pobj, reg_id);
+			}
+		}
+		child = type;
+		type = g_type_parent(type);
 	}
-	return reg_id;
+	while (child != PURPLE_TYPE_OBJECT && child != 0);
 }
 
 void
@@ -936,11 +954,9 @@
 purple_object_dbus_connect(gpointer object, GDBusConnection *dbus_conn)
 {
 	PurpleObjectClass *pclass = PURPLE_OBJECT_GET_CLASS(object);
-	guint reg_id;
 
 	if (pclass->on_dbus_connected) {
-		reg_id = pclass->on_dbus_connected(object, dbus_conn);
-		purple_object_set_dbus_reg_id(PURPLE_OBJECT(object), reg_id);
+		pclass->on_dbus_connected(object, dbus_conn);
 	}
 }
 
diff --git a/libpurple/pobject.h b/libpurple/pobject.h
--- a/libpurple/pobject.h
+++ b/libpurple/pobject.h
@@ -51,9 +51,8 @@
 #ifdef HAVE_DBUS
 	/* A function called when the DBus connection is acquiered. Usually,
            in deamon context the object should register itself on the bus,
-           whereas on client context it should put DBus signals handlers.
-	   Returns the registration or subscription id provided by GDbus/ */
-	guint (*on_dbus_connected)(gpointer object, GDBusConnection *connection);
+           whereas on client context it should put DBus signals handlers. */
+	void (*on_dbus_connected)(gpointer object, GDBusConnection *connection);
 	/* A data set of DBus methods (in daemon context) or signals (in client
 	   context) names as keys and GClosures as values. */
 	GData *dbus_callbacks;
@@ -385,9 +384,9 @@
  *
  * @param object An object derived from PurpleObject.
  * @param dbus_conn The GDBus handle.
- * @return The registration id returned by g_dbus_connection_signal_subscribe().
  */
-guint purple_object_generic_dbus_signal_subscribe(gpointer object, GDBusConnection *dbus_conn);
+void purple_object_generic_dbus_signal_subscribe(gpointer object, GDBusConnection *dbus_conn);
+
 /**
  * Adds an D-Bus interface definition to the pool of handled interfaces
  * by the object class of the given type. This function should be ran by



More information about the Commits mailing list