cpw.gillux.detachablepurple: 675c21b5: Rewritten PurpleDBusCallback's signals a...

gillux at soc.pidgin.im gillux at soc.pidgin.im
Fri May 25 15:47:04 EDT 2012


----------------------------------------------------------------------
Revision: 675c21b5c52aa592fd4a13c00ad8cbbeb7e2c3a7
Parent:   4dcffaff1c53b9897b12840ad523b266a5f4a099
Author:   gillux at soc.pidgin.im
Date:     05/25/12 14:48:12
Branch:   im.pidgin.cpw.gillux.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/675c21b5c52aa592fd4a13c00ad8cbbeb7e2c3a7

Changelog: 

Rewritten PurpleDBusCallback's signals and methods implementations,
using the new gdbus-based API.

Changes against parent 4dcffaff1c53b9897b12840ad523b266a5f4a099

  patched  libpurple/dbus/callback.c

-------------- next part --------------
============================================================
--- libpurple/dbus/callback.c	974bf3bc878090da6acaa6aeeca666945a65d415
+++ libpurple/dbus/callback.c	ae5d7c6e00062f77a1ac25a3e8066d0ba2a2f302
@@ -25,8 +25,6 @@
 #include "core.h"
 #include "dbus/callback.h"
 #include "dbus/callback.xml.h"
-#include "dbus/callback-server.h"
-#include "dbus/callback-client.h"
 #include "dbus-maybe.h"
 #include "dbus-purple.h"
 #include "dbus-server.h"
@@ -65,8 +63,10 @@ G_DEFINE_TYPE(PurpleDBusCallback, purple
 
 #define PURPLE_TYPE_CALLBACK                   (purple_dbus_callback_get_type())
 
-static void run_callback_cb(DBusGProxy *proxy, const guint64 callback_id, GPtrArray *params, gpointer data);
-static void request_closed_cb(DBusGProxy *proxy, const guint request_id, gpointer data);
+/* D-Bus signals and methods handlers. */
+static void run_callback_cb(PurpleDBusCallback* handler, const guint64 callback_id, GVariant *params);
+static void request_closed_cb(PurpleDBusCallback* handler, const guint request_id);
+static void run_request_cb(PurpleDBusCallback *handler, guint request_id, guint choice);
 
 void
 purple_dbus_callback_do_init(void)
@@ -138,9 +138,19 @@ purple_dbus_callback_class_init(PurpleDB
 	pobjclass->build_dbus_path = purple_callback_build_dbus_path;
 
 	if (purple_core_is_daemon_mode()) {
+		/* D-Bus method handlers. */
+               	purple_object_bind_dbus_callback
+		  (pobjclass, purple_callback_interface_info.name,
+		  "RunRequest", (GCallback)run_request_cb);
+	} else if (purple_core_is_remote_mode()) {
+		/* D-Bus signal handlers. */
+		purple_object_bind_dbus_callback
+		  (pobjclass, purple_callback_interface_info.name,
+		   "RunCallback", (GCallback)run_callback_cb);
+		purple_object_bind_dbus_callback
+		  (pobjclass, purple_callback_interface_info.name,
+		   "RequestClosed", (GCallback)request_closed_cb);
 	}
-	else if (purple_core_is_remote_mode()) {
-	}
 }
 
 static void
@@ -179,48 +189,37 @@ purple_dbus_callback_new_id(void)
 }
 
 /**
- * Builds a n_args sized array of GValues, giving a alternate GType,typed arg
- * list. E.g. build_args_list(2, G_TYPE_BOOLEAN, TRUE, G_TYPE_STRING, "foobar")
+ * Builds an n_args sized array of GVariants, giving an alternate
+ * "GVariant signature, typed arg" list. E.g.:
+ * build_args_list(2, "b", TRUE, "s", "foobar")
  */
-static GPtrArray*
+static GVariant*
 build_args_list(unsigned int n_args, ...)
 {
-	GPtrArray *values;
-	GValue *val;
+	GVariantBuilder builder;
+	GVariant *val;
+	const gchar *type;
 	va_list ap;
-	gchar *err;
-	int i;
 
-	values = g_ptr_array_sized_new(n_args);
+	g_variant_builder_init(&builder, G_VARIANT_TYPE("av"));
 	va_start(ap, n_args);
-	for (i = 0; i < n_args; i++) {
-		val = g_new0(GValue, 1);
-#if GLIB_CHECK_VERSION(2, 24, 0)
-		/* A more optimized way */
-		G_VALUE_COLLECT_INIT(val, va_arg(ap, GType), ap, 0, &err);
-#else
-		g_value_init(val, va_arg(ap, GType));
-		G_VALUE_COLLECT(val, ap, 0, &err);
-#endif
-		if (err) {
-			g_warning("%s\n", err);
-			g_free(err);
-		}
-		g_ptr_array_add(values, val);
+	while (n_args--) {
+		type = va_arg(ap, const gchar*);
+		val = g_variant_new_va(type, NULL, &ap);
+		g_variant_builder_add_value(&builder, g_variant_new("v", val));
 	}
 	va_end(ap);
-
-	return values;
+	return g_variant_builder_end(&builder);
 }
 
 void
 purple_dbus_callback__b(void *obj, gboolean arg1, guint64 *id)
 {
 	PurpleDBusCallback* handler = purple_dbus_callback_get_instance();
-	GPtrArray* params = build_args_list(1, G_TYPE_BOOLEAN, arg1);
-	g_signal_emit(handler, signals[SIG_DBUS_RUN_CALLBACK], 0, *id, params);
-	g_ptr_array_foreach(params, (GFunc)g_value_unset, NULL);
-	g_ptr_array_free(params, TRUE);
+	GVariant* params = build_args_list(1, "b", arg1);
+	purple_object_emit_dbus_signal(PURPLE_OBJECT(handler),
+	                               purple_callback_interface_info.name,
+	                               "RunCallback", *id, params);
 	g_free(id);
 }
 
@@ -228,13 +227,12 @@ static void
  * Callback, called when we receive a dbus "RunCallback" signal.
  */
 static void
-run_callback_cb(DBusGProxy *proxy, const guint64 callback_id, GPtrArray *params, gpointer data)
+run_callback_cb(PurpleDBusCallback* handler,
+                const guint64 callback_id, GVariant *params)
 {
-	PurpleDBusCallback* handler = purple_dbus_callback_get_instance();
 	GClosure *closure;
-	GObject *obj;
 	GValue *values;
-	int i;
+	guint i, num_params;
 
 	g_return_if_fail(handler != NULL);
 	g_return_if_fail(handler->callbacks != NULL);
@@ -245,21 +243,14 @@ run_callback_cb(DBusGProxy *proxy, const
 	if (!closure)
 		return;
 
-	obj = purple_dbus_get_gobject_by_path(dbus_g_proxy_get_path(proxy));
-	g_return_if_fail(obj != NULL);
-
 	purple_debug_info("dbus", "Running callback %llu\n", callback_id);
 
-	/* Build the GValue array for the closure */
-	values = g_new0(GValue, params->len+1);
-	/* First parameter is the object */
-	g_value_init(&values[0], G_TYPE_OBJECT);
-	g_value_set_object(&values[0], obj);
-	/* Then the received parameters */
-	for (i = 0; i < params->len; i++)
-		memcpy(&values[i+1], params->pdata[i], sizeof(GValue));
-	g_closure_invoke(closure, NULL, params->len+1, values, NULL);
+	purple_gvariant_to_gvalue_closure_args(handler, params,
+	                                       &values, &num_params);
+	g_closure_invoke(closure, NULL, num_params, values, NULL);
 
+	for (i = 0; i < num_params; i++)
+		g_value_unset (&values[i]);
 	g_free(values);
 	/* The following frees the closure and the id */
 	g_hash_table_remove(handler->callbacks, &callback_id);
@@ -269,7 +260,7 @@ static void
  * Callback, called when we receive a dbus "RequestClosed" signal.
  */
 static void
-request_closed_cb(DBusGProxy *proxy, const guint request_id, gpointer data)
+request_closed_cb(PurpleDBusCallback* handler, const guint request_id)
 {
 	/* Forget about this pending request, execute the closing callback */
 	purple_callback_close_client_req(request_id);
@@ -353,19 +344,15 @@ purple_callback_run_request_RPC(guint re
 purple_callback_run_request_RPC(guint request_id, guint choice)
 {
 	PurpleDBusCallback* handler = purple_dbus_callback_get_instance();
-	DBusGProxy* proxy;
-	GError *error = NULL;
 
-	proxy = purple_object_get_dbus_obj_proxy(PURPLE_OBJECT(handler));
-	if (!im_pidgin_purple_callback_run_request(proxy, request_id, choice,
-	                                           &error))
-		PURPLE_RPC_FAILED(purple_account_run_request, error);
+	purple_object_dbus_call(PURPLE_OBJECT(handler),
+	                        purple_callback_interface_info.name,
+	                        "RunRequest", request_id, choice);
 }
 
-gboolean
-purple_callback_run_request(guint request_id, guint choice)
+static void
+run_request_cb(PurpleDBusCallback *handler, guint request_id, guint choice)
 {
-	PurpleDBusCallback* handler = purple_dbus_callback_get_instance();
 	GPtrArray *closures;
 	GClosure *closure;
 	void *key = GINT_TO_POINTER(request_id);
@@ -376,8 +363,8 @@ purple_callback_run_request(guint reques
 	 * client already ran a RunRequest faster than the one who presently
 	 * sent us this RunRequest. */
 	if (!closures)
-		return TRUE;
-	g_return_val_if_fail(choice < closures->len, FALSE);
+		return;
+	g_return_if_fail(choice < closures->len);
 	closure = closures->pdata[choice];
 
 	/* Run it! */
@@ -396,7 +383,6 @@ purple_callback_run_request(guint reques
 
 	/* Forget about this pending request, it has been handled */
 	g_hash_table_remove(handler->requests, key);
-	return TRUE;
 }
 
 void


More information about the Commits mailing list