cpw.gillux.detachablepurple: 7ebc4714: Added a convenience function to emit a D...

gillux at soc.pidgin.im gillux at soc.pidgin.im
Mon May 14 23:27:00 EDT 2012


----------------------------------------------------------------------
Revision: 7ebc4714593d06dd2d26e0a46cf9c9612ae207ca
Parent:   aeb59e75314b7110227e6e500da9c4b76f0a691c
Author:   gillux at soc.pidgin.im
Date:     05/14/12 21:03:54
Branch:   im.pidgin.cpw.gillux.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/7ebc4714593d06dd2d26e0a46cf9c9612ae207ca

Changelog: 

Added a convenience function to emit a D-Bus signal
from a given PurpleObject.

Changes against parent aeb59e75314b7110227e6e500da9c4b76f0a691c

  patched  libpurple/pobject.c
  patched  libpurple/pobject.h

-------------- next part --------------
============================================================
--- libpurple/pobject.c	527cb7d4d2f8133da5b15f0ab3b79302118bd900
+++ libpurple/pobject.c	d9cfd086ea1b927f2aaae9d71719bc41fb33a027
@@ -569,9 +569,6 @@ purple_object_forward_notify_cb(GObject 
 	gchar *prop_name;
 	GVariant *prop;
 	GVariant *signal_params;
-	char *object_path;
-	GDBusInterfaceInfo *ifaceinfo;
-	GDBusConnection *connection;
 
 	/* 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
@@ -579,14 +576,6 @@ purple_object_forward_notify_cb(GObject 
 	 * avoid it.
 	 */
 
-	/* Check if we are on DBus. Not having a connection can happen
-	   during purple initialization, when object properties are
-	   modified whereas the bus name is not acquired yet.
-	   Not a problem at all. */
-	connection = purple_gdbus_get_connection();
-	if (!connection)
-		return;
-
 	prop_name = g_param_spec_get_name(pspec);
 	prop = purple_object_get_dbus_property(PURPLE_OBJECT(gobj), prop_name);
 	if (!prop)
@@ -597,10 +586,7 @@ purple_object_forward_notify_cb(GObject 
 	                  prop_name, G_OBJECT_TYPE_NAME(gobj));
 
 	signal_params = g_variant_new("(sv)", prop_name, prop);
-	object_path = purple_object_get_dbus_path(PURPLE_OBJECT(gobj));
-	ifaceinfo = PURPLE_OBJECT_GET_CLASS(PURPLE_OBJECT(gobj))->dbus_ifaceinfo;
-	g_dbus_connection_emit_signal(connection, NULL,
-	                              object_path, ifaceinfo->name,
+	purple_object_emit_dbus_signal(PURPLE_OBJECT(gobj),
 	                              "PropertyChanged", signal_params, NULL);
 	g_variant_unref(prop);
 	g_variant_unref(signal_params);
@@ -930,6 +916,31 @@ purple_object_dbus_init(gpointer object)
 	}
 }
 
+gboolean
+purple_object_emit_dbus_signal(PurpleObject *pobj, const gchar *signal_name,
+                               GVariant *signal_params, GError **error)
+{
+	GDBusInterfaceInfo *interface_info;
+	GDBusConnection *connection;
+	char *object_path;
+
+	object_path = purple_object_get_dbus_path(pobj);
+	g_return_val_if_fail(object_path != NULL, FALSE);
+
+	interface_info = PURPLE_OBJECT_GET_CLASS(pobj)->dbus_ifaceinfo;
+	g_return_val_if_fail(interface_info != 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_info->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 *
============================================================
--- libpurple/pobject.h	2c00a2fb407cd68b4cc90ce22cff33d2af4fd0a2
+++ libpurple/pobject.h	8b3f64ea8b4dd1c9d3dcebe1a5b34b9c2bd640db
@@ -419,6 +419,21 @@ void purple_object_dbus_init(gpointer ob
 void purple_object_dbus_init(gpointer object);
 
 /**
+ * A convenience function that emits signal_name D-Bus signal on pobj
+ * with signal_params parameters. Emits on the dbus_ifaceinfo interface
+ * through our D-Bus connection. Only the daemon may emit D-Bus signals.
+ *
+ * @param pobj The PurpleObject from which the signal must be emitted.
+ * @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.
+ */
+gboolean purple_object_emit_dbus_signal(PurpleObject *pobj, const gchar *signal_name, GVariant *signal_params, GError **error);
+
+/**
  * Remotely calls method_name on pobj over D-Bus. Actually, it's not called
  * on this pojb object but on the remote associated one. The input parameters
  * are all the variable parameters, and must follow the method input parameters


More information about the Commits mailing list