/srv/mercurial-server/detachablepurple: ca18aafa3b5c: The D-Bus ...

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


Changeset: ca18aafa3b5cc947a033b35a1fde1b7c4db58fcf
Author:	 Gilles Bedel <gillux at cpw.pidgin.im>
Date:	 2012-05-25 18:12 +0000
Branch:	 cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/ca18aafa3b5c

Description:

The D-Bus sending signal function now takes variable parameters,
just like the D-Bus method calling one.

diffstat:

 libpurple/dbus/constructor.c |  11 ++----
 libpurple/pobject.c          |  74 ++++++++++++++++++++++++++++---------------
 libpurple/pobject.h          |  13 ++----
 3 files changed, 57 insertions(+), 41 deletions(-)

diffs (159 lines):

diff --git a/libpurple/dbus/constructor.c b/libpurple/dbus/constructor.c
--- a/libpurple/dbus/constructor.c
+++ b/libpurple/dbus/constructor.c
@@ -416,15 +416,12 @@
 purple_constructor_announce_pobject_creation(PurpleObject *pobj)
 {
 	PurpleConstructor *con = purple_constructor_get_instance();
-	GVariant *params;
-
-	params = g_variant_new("(so at a(sv))",
-	                       G_OBJECT_TYPE_NAME(pobj),
-	                       purple_object_get_dbus_path(pobj),
-	                       purple_constructor_pack_pobject_props(pobj));
 	purple_object_emit_dbus_signal(PURPLE_OBJECT(con),
 	                               purple_constructor_interface_info.name,
-	                               "PurpleObjectCreated", params, NULL);
+	                               "PurpleObjectCreated",
+	                               G_OBJECT_TYPE_NAME(pobj),
+	                               purple_object_get_dbus_path(pobj),
+	                               purple_constructor_pack_pobject_props(pobj));
 }
 
 /* "PurpleObjectCreated" signal handler. */
diff --git a/libpurple/pobject.c b/libpurple/pobject.c
--- a/libpurple/pobject.c
+++ b/libpurple/pobject.c
@@ -616,7 +616,6 @@
 {
 	const gchar *prop_name;
 	GVariant *prop;
-	GVariant *signal_params;
 
 	/* Note that this "notify" signal may occur even if the property havn't
 	 * changed (when one sets it to its previous value). This can constitute
@@ -633,12 +632,10 @@
 	purple_debug_info("dbus", "Sending notify about property '%s' of a %s\n",
 	                  prop_name, G_OBJECT_TYPE_NAME(gobj));
 
-	signal_params = g_variant_new("(sv)", prop_name, prop);
 	purple_object_emit_dbus_signal(PURPLE_OBJECT(gobj),
 	                               purple_object_interface_info.name,
-	                              "PropertyChanged", signal_params, NULL);
+	                              "PropertyChanged", prop_name, prop);
 	g_variant_unref(prop);
-	g_variant_unref(signal_params);
 }
 
 void
@@ -1014,28 +1011,6 @@
 	}
 }
 
-gboolean
-purple_object_emit_dbus_signal(PurpleObject *pobj, const gchar *interface_name,
-                               const gchar *signal_name,
-                               GVariant *signal_params, GError **error)
-{
-	GDBusConnection *connection;
-	char *object_path;
-
-	object_path = purple_object_get_dbus_path(pobj);
-	g_return_val_if_fail(object_path != NULL, FALSE);
-
-	/* Not having a connection yet can happen during an asynchronous
-	 * purple initialization. */
-	connection = purple_gdbus_get_connection();
-	if (!connection)
-		return FALSE;
-
-	return g_dbus_connection_emit_signal(connection, NULL,
-	                                     object_path, interface_name,
-	                                     signal_name, signal_params, error);
-}
-
 /* Merges all the args signatures in a tuple and create a GVariantType from
  * that. Code shamely copied from glib's gdbusprivate.c. */
 static GVariantType *
@@ -1060,6 +1035,53 @@
 	return g_variant_type_new_tuple (arg_types, n);
 }
 
+void
+purple_object_emit_dbus_signal(PurpleObject *pobj, const gchar *interface_name,
+                               const gchar *signal_name, ...)
+{
+	va_list ap;
+	GDBusInterfaceInfo *iface;
+	GDBusSignalInfo *signal_info;
+	GDBusConnection *connection;
+	GVariantType *type;
+	GVariant *signal_params;
+	GError *error = NULL;
+	char *object_path, *sig;
+	gboolean ok;
+
+	/* Not having a connection yet can happen during an asynchronous
+	 * purple initialization. */
+	connection = purple_gdbus_get_connection();
+	if (!connection)
+		return;
+
+	object_path = purple_object_get_dbus_path(pobj);
+	g_return_if_fail(object_path != NULL);
+
+	iface = find_interface_info_by_name(pobj, interface_name);
+	g_return_if_fail(iface != NULL);
+	signal_info = g_dbus_interface_info_lookup_signal(iface, signal_name);
+	g_return_if_fail(signal_info != NULL);
+
+	type = purple_object_tuplize_signatures(signal_info->args);
+	sig = g_variant_type_dup_string(type);
+	va_start(ap, signal_name);
+	signal_params = g_variant_new_va(sig, NULL, &ap);
+	va_end(ap);
+	g_free(sig);
+	g_free(type);
+
+	ok = g_dbus_connection_emit_signal(connection, NULL,
+	                                   object_path, interface_name,
+	                                   signal_name, signal_params, &error);
+
+	if (!ok) {
+		purple_debug_error("dbus", "Error while sending signal %s.%s: %s\n",
+		                   iface->name, signal_name, error->message);
+		g_error_free(error);
+	}
+}
+
 GVariant *
 purple_object_dbus_call(PurpleObject *pobj, const char *interface_name,
                         const char *method_name, ...)
diff --git a/libpurple/pobject.h b/libpurple/pobject.h
--- a/libpurple/pobject.h
+++ b/libpurple/pobject.h
@@ -428,19 +428,16 @@
                              gboolean propagate_props_changes);
 
 /**
- * A convenience function that emits signal_name D-Bus signal on pobj
- * with signal_params parameters. Only the daemon may emit D-Bus signals.
+ * Emits signal_name D-Bus signal on interface interface_name with variable
+ * parameters. Only the daemon may emit D-Bus signals. The parameters must
+ * match the signature of the signal defined in the XML file.
  *
  * @param pobj The PurpleObject from which the signal must be emitted.
  * @param interface_name The name of the interface.
  * @param signal_name The name of the signal.
- * @param signal_params The parameters of the signal (may be NULL).
- *        Multiple parameters must be packed in a GVarianttuple, in the
- *        order they are presented in the D-Bus introspection XML files.
- * @param error A GError directly passed to g_dbus_connection_emit_signal().
- * @return TRUE If the signal has been sent, FALSE otherwise.
+ * @param ... The parameters of the signal, if any.
  */
-gboolean purple_object_emit_dbus_signal(PurpleObject *pobj, const gchar *interface_name, const gchar *signal_name, GVariant *signal_params, GError **error);
+void purple_object_emit_dbus_signal(PurpleObject *pobj, const gchar *interface_name, const gchar *signal_name, ...);
 
 /**
  * Remotely calls method_name on pobj over D-Bus. Actually, it's not called



More information about the Commits mailing list