/srv/mercurial-server/detachablepurple: 1c4660af5934: Finally ad...

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


Changeset: 1c4660af5934738bfb0b0a32bbe6774f10b903e6
Author:	 Gilles Bedel <gillux at cpw.pidgin.im>
Date:	 2012-03-27 21:07 +0000
Branch:	 cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/1c4660af5934

Description:

Finally added the D-Bus sighandlers code. Hopefully, clients will
be able to simply bind their sighandlers upon connection to D-Bus,
using the same mechanisms as the daemon with its methods handlers.
Clients shall first bind every sighandler with
purple_object_bind_dbus_callback() on their class initialization
function, and then call purple_dbus_connect_object() on their
object initialization function.

diffstat:

 libpurple/pobject.c |  64 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 56 insertions(+), 8 deletions(-)

diffs (81 lines):

diff --git a/libpurple/pobject.c b/libpurple/pobject.c
--- a/libpurple/pobject.c
+++ b/libpurple/pobject.c
@@ -208,14 +208,8 @@
 #ifdef HAVE_DBUS
 	if (purple_core_is_daemon_mode())
 		klass->on_dbus_connected = purple_object_generic_dbus_register_object;
-	/* In remote mode we need to register the marshallers
-	 * we will use to receive the signals sent by the daemon */
-	if (purple_core_is_remote_mode()) {
-		/* Marshaller for the DBusNotify dbus signal */
-		dbus_g_object_register_marshaller(
-			purple_smarshal_VOID__STRING_BOXED,
-			G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
-	}
+	else if (purple_core_is_remote_mode())
+		klass->on_dbus_connected = purple_object_generic_dbus_signal_subscribe;
 #endif
 }
 
@@ -775,6 +769,60 @@
 	return reg_id;
 }
 
+static void
+purple_object_generic_dbus_sighandler(GDBusConnection *connection,
+                                      const gchar *sender_name,
+                                      const gchar *object_path,
+                                      const gchar *interface_name,
+                                      const gchar *signal_name,
+                                      GVariant *params,
+                                      gpointer object)
+{
+	GClosure *closure;
+	GValue *paramv;
+	guint i, num_params;
+
+	/* Get the sighandler back. */
+	closure = purple_object_get_dbus_closure(PURPLE_OBJECT_GET_CLASS(object),
+	                                         signal_name);
+	if (!closure) {
+		purple_debug_warning("dbus", "Signal %s received on interface %s lacks a sighandler.", signal_name, interface_name);
+		return;
+	}
+
+	/* Prepare the closure parameters. */
+	gvariant_to_gvalue_closure_args(object, params, &paramv, &num_params);
+
+	/* Execute the sighandler. */
+	g_closure_invoke(closure, NULL, num_params, paramv, NULL);
+
+	for (i = 0; i < num_params; i++)
+		g_value_unset (&paramv[i]);
+	g_free (paramv);
+}
+
+guint
+purple_object_generic_dbus_signal_subscribe(gpointer object, GDBusConnection *dbus_conn)
+{
+	PurpleObject *pobj = PURPLE_OBJECT(object);
+	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);
+	
+	if (reg_id == 0) {
+		purple_debug_error("dbus", "Failed to subscribe %s to D-Bus signals\n",
+                                   G_OBJECT_TYPE_NAME(object));
+	}
+	return reg_id;
+}
+
 void
 purple_object_dbus_connect(gpointer object, GDBusConnection *dbus_conn)
 {



More information about the Commits mailing list