cpw.gillux.detachablepurple: 8a1a8492: The D-Bus sending signal function now ta...

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


----------------------------------------------------------------------
Revision: 8a1a8492fb4a53c9ee4f0379289ca9cc33bfc1fa
Parent:   3afce50b2cca69538ee5ece57dfc33b4c538e36c
Author:   gillux at soc.pidgin.im
Date:     05/25/12 14:12:51
Branch:   im.pidgin.cpw.gillux.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/8a1a8492fb4a53c9ee4f0379289ca9cc33bfc1fa

Changelog: 

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

Changes against parent 3afce50b2cca69538ee5ece57dfc33b4c538e36c

  patched  libpurple/dbus/constructor.c
  patched  libpurple/pobject.c
  patched  libpurple/pobject.h

-------------- next part --------------
============================================================
--- libpurple/pobject.c	7da1132f15d4ccee75c7b011d38898859b54205a
+++ libpurple/pobject.c	a5d73b962339760940a4c3f846ea270b4997e1a9
@@ -616,7 +616,6 @@ purple_object_forward_notify_cb(GObject 
 {
 	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_object_forward_notify_cb(GObject 
 	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 @@ purple_object_dbus_init(gpointer object,
 	}
 }
 
-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 @@ purple_object_tuplize_signatures(GDBusAr
 	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, ...)
============================================================
--- libpurple/pobject.h	68eb0bab3da932bb270118bc2458eb0090937330
+++ libpurple/pobject.h	6d9662eac30d696f9058925e13f7d3c4381e7f9f
@@ -428,19 +428,16 @@ void purple_object_dbus_init(gpointer ob
                              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
============================================================
--- libpurple/dbus/constructor.c	cc724c41d602cddceb2a3cd1e347e8c623912b37
+++ libpurple/dbus/constructor.c	25027943ec5e29fb50e0ed9eeb0190a18134f728
@@ -416,15 +416,12 @@ purple_constructor_announce_pobject_crea
 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. */


More information about the Commits mailing list