/srv/mercurial-server/detachablepurple: 69a907706a7c: Moved the ...

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


Changeset: 69a907706a7cb6a05c0583372859a9d730c06a09
Author:	 Gilles Bedel <gillux at cpw.pidgin.im>
Date:	 2012-03-27 20:45 +0000
Branch:	 cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/69a907706a7c

Description:

Moved the closure parameters preparation to a dedicated function,
as this will be very useful for D-Bus sighandlers too. Also made
purple_object_generic_dbus_method_handler() to use it.

diffstat:

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

diffs (85 lines):

diff --git a/libpurple/pobject.c b/libpurple/pobject.c
--- a/libpurple/pobject.c
+++ b/libpurple/pobject.c
@@ -646,6 +646,34 @@
 	return g_datalist_get_data(&klass->dbus_callbacks, name);
 }
 
+/*
+ * Converts a GVariant tuple params into a GValue array with object prepended.
+ * Returns a newly allocated array in paramv, and its size in num_params.
+ */
+static void
+gvariant_to_gvalue_closure_args(gpointer object, GVariant *params,
+                                GValue **paramv, guint *num_params)
+{
+	GVariant *next;
+	GVariantIter iter;
+	GValue *gval;
+	guint i;
+
+	*num_params = g_variant_n_children(params) + 1;
+	*paramv = gval = g_new0(GValue, *num_params);
+
+	/* Put the right parameters in paramv. First, the object. */
+	g_value_init (&gval[0], G_TYPE_FROM_INSTANCE(object));
+	g_value_set_object (&gval[0], object);
+	/* Then the others, if any. */
+	i = 1;
+	g_variant_iter_init (&iter, params);
+	while ((next = g_variant_iter_next_value(&iter)) != NULL) {
+		g_dbus_gvariant_to_gvalue(next, &gval[i++]);
+		g_variant_unref(next);
+	}
+}
+
 void
 purple_object_generic_dbus_method_handler(GDBusConnection       *connection,
                                           const gchar           *sender,
@@ -656,25 +684,11 @@
                                           GDBusMethodInvocation *invoc,
                                           gpointer               object)
 {
-	guint num_params = g_variant_n_children(params);
-	GValue *paramv = g_new0(GValue, num_params + 1);
-	GVariant *next;
-	GVariantIter iter;
-	guint i;
+	GValue *paramv;
 	GClosure *closure;
+	guint i, num_params;
 
-	/* Put the right parameters in paramv. First, the object. */
-	g_value_init (&paramv[0], G_TYPE_FROM_INSTANCE(object));
-	g_value_set_object (&paramv[0], object);
-	/* Then the others, if any. */
-	i = 1;
-	g_variant_iter_init (&iter, params);
-	while ((next = g_variant_iter_next_value(&iter)) != NULL) {
-		g_dbus_gvariant_to_gvalue(next, &paramv[i++]);
-		g_variant_unref(next);
-	}
-
-	/* Get the binded function back, and execute it. */
+	/* Get the binded function back. */
 	closure = purple_object_get_dbus_closure(PURPLE_OBJECT_GET_CLASS(object),
 	                                         method_name);
 	if (!closure)
@@ -683,11 +697,15 @@
 		         "Method %s is not yet implemented on interface %s.",
 		         method_name, interface_name);
 
-	g_closure_invoke(closure, NULL, num_params + 1, paramv, NULL);
+	/* Prepare the closure parameters. */
+	gvariant_to_gvalue_closure_args(object, params, &paramv, &num_params);
+
+	/* Execute the callback. */
+	g_closure_invoke(closure, NULL, num_params, paramv, NULL);
 	/* TODO: handle output parameters. */
 	g_dbus_method_invocation_return_value(invoc, NULL);
 
-	for (i = 0; i < num_params + 1; i++)
+	for (i = 0; i < num_params; i++)
 		g_value_unset (&paramv[i]);
 	g_free (paramv);
 }



More information about the Commits mailing list