/srv/mercurial-server/detachablepurple: 390bdd3b69bd: Added a co...

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


Changeset: 390bdd3b69bdaa75dabb55819f90c2dc49bc88ad
Author:	 Gilles Bedel <gillux at cpw.pidgin.im>
Date:	 2012-05-15 01:03 +0000
Branch:	 cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/390bdd3b69bd

Description:

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

diffstat:

 libpurple/pobject.c |  41 ++++++++++++++++++++++++++---------------
 libpurple/pobject.h |  15 +++++++++++++++
 2 files changed, 41 insertions(+), 15 deletions(-)

diffs (97 lines):

diff --git a/libpurple/pobject.c b/libpurple/pobject.c
--- a/libpurple/pobject.c
+++ b/libpurple/pobject.c
@@ -569,9 +569,6 @@
 	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 @@
 	 * 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 @@
 	                  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 @@
 	}
 }
 
+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 *
diff --git a/libpurple/pobject.h b/libpurple/pobject.h
--- a/libpurple/pobject.h
+++ b/libpurple/pobject.h
@@ -419,6 +419,21 @@
 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