/srv/mercurial-server/detachablepurple: 94f464e8561a: Moved the ...

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


Changeset: 94f464e8561abdc762efaaca742490917abaeaf2
Author:	 Gilles Bedel <gillux at cpw.pidgin.im>
Date:	 2012-05-25 17:59 +0000
Branch:	 cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/94f464e8561a

Description:

Moved the purple_gvariant_to_gvalue_closure_args() function to util.c,
so that it will be available for the D-Bus user-provided callbacks part.

diffstat:

 libpurple/pobject.c |  34 ++++------------------------------
 libpurple/util.c    |  27 +++++++++++++++++++++++++++
 libpurple/util.h    |  18 ++++++++++++++++++
 3 files changed, 49 insertions(+), 30 deletions(-)

diffs (127 lines):

diff --git a/libpurple/pobject.c b/libpurple/pobject.c
--- a/libpurple/pobject.c
+++ b/libpurple/pobject.c
@@ -751,34 +751,6 @@
 	return ret;
 }
 
-/*
- * 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,
@@ -804,7 +776,9 @@
 		         method_name, interface_name);
 
 	/* Prepare the closure parameters. */
-	gvariant_to_gvalue_closure_args(object, params, &paramv, &num_params);
+	purple_gvariant_to_gvalue_closure_args(object, params,
+	                                       &paramv, &num_params);
+
 /* We don't want to force such a recent version, so keep a shitty workaround. */
 #if GLIB_CHECK_VERSION(2, 32, 1)
 	g_value_init(&ret_val, G_TYPE_VARIANT);
@@ -931,7 +905,7 @@
 	}
 
 	/* Prepare the closure parameters. */
-	gvariant_to_gvalue_closure_args(object, params, &paramv, &num_params);
+	purple_gvariant_to_gvalue_closure_args(object, params, &paramv, &num_params);
 
 	/* Execute the sighandler. */
 	g_closure_invoke(closure, NULL, num_params, paramv, NULL);
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -36,6 +36,8 @@
 #include "prefs.h"
 #include "util.h"
 
+#include "glib-2.30.h"
+
 struct _PurpleUtilFetchUrlData
 {
 	PurpleUtilFetchUrlCallback callback;
@@ -5264,3 +5266,28 @@
 			b,
 			(tmp >> 16) & 0xFFFF, g_random_int());
 }
+
+void
+purple_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);
+	}
+}
+
diff --git a/libpurple/util.h b/libpurple/util.h
--- a/libpurple/util.h
+++ b/libpurple/util.h
@@ -1526,6 +1526,24 @@
 		const gchar *nonce_count, const gchar *client_nonce,
 		const gchar *session_key);
 
+/*
+ * Converts a set of GVariant parameters into a GValue array with the
+ * object prepended. Useful to prepare parameters for a g_closure_invoke().
+ *
+ * @param object The object instance prepended to the parameters.
+ * @param params The parameters in a GVariant array.
+ * @param paramv A pointer to an array of GValues that will be created. It
+ *               must be freed with something like:
+ *               for (i = 0; i < num_params; i++)
+ *                 g_value_unset (&paramv[i]);
+ *               g_free (paramv);
+ * @param num_params A pointer to a value filled with the size of the
+ *                   newly-created paramv array.
+ *
+ */
+void
+purple_gvariant_to_gvalue_closure_args(gpointer object, GVariant *params,
+                                       GValue **paramv, guint *num_params);
 
 /** @name Slice-allocated GValue helpers */
 /** @{ */



More information about the Commits mailing list