cpw.gillux.detachablepurple: 1cdfd837: Moved the closure parameters preparation...
gillux at soc.pidgin.im
gillux at soc.pidgin.im
Tue Mar 27 17:25:52 EDT 2012
----------------------------------------------------------------------
Revision: 1cdfd83748e5f04659af4117aec8cb0e661d8aaf
Parent: 0af331138cba35c79cf68e7026117af89c3aaae7
Author: gillux at soc.pidgin.im
Date: 03/27/12 16:45:59
Branch: im.pidgin.cpw.gillux.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/1cdfd83748e5f04659af4117aec8cb0e661d8aaf
Changelog:
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.
Changes against parent 0af331138cba35c79cf68e7026117af89c3aaae7
patched libpurple/pobject.c
-------------- next part --------------
============================================================
--- libpurple/pobject.c 42939c71cd31f6e6931563e106a9d290c21aa3e6
+++ libpurple/pobject.c 0520469e129ff67d45635f3a7c29a2c61c0cdef7
@@ -646,35 +646,49 @@ purple_object_get_dbus_closure(PurpleObj
return g_datalist_get_data(&klass->dbus_callbacks, name);
}
-void
-purple_object_generic_dbus_method_handler(GDBusConnection *connection,
- const gchar *sender,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *method_name,
- GVariant *params,
- GDBusMethodInvocation *invoc,
- gpointer object)
+/*
+ * 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)
{
- guint num_params = g_variant_n_children(params);
- GValue *paramv = g_new0(GValue, num_params + 1);
GVariant *next;
GVariantIter iter;
+ GValue *gval;
guint i;
- GClosure *closure;
+ *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 (¶mv[0], G_TYPE_FROM_INSTANCE(object));
- g_value_set_object (¶mv[0], 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, ¶mv[i++]);
+ g_dbus_gvariant_to_gvalue(next, &gval[i++]);
g_variant_unref(next);
}
+}
- /* Get the binded function back, and execute it. */
+void
+purple_object_generic_dbus_method_handler(GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *params,
+ GDBusMethodInvocation *invoc,
+ gpointer object)
+{
+ GValue *paramv;
+ GClosure *closure;
+ guint i, num_params;
+
+ /* Get the binded function back. */
closure = purple_object_get_dbus_closure(PURPLE_OBJECT_GET_CLASS(object),
method_name);
if (!closure)
@@ -683,11 +697,15 @@ purple_object_generic_dbus_method_handle
"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, ¶mv, &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 (¶mv[i]);
g_free (paramv);
}
More information about the Commits
mailing list