/srv/mercurial-server/detachablepurple: a2d25cdbc52c: Added a Pu...

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


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

Description:

Added a PurpleObjectCreated D-Bus signal to inform all the clients
about the creation of any PurpleObject on the daemon. This replaces
the old PurpleConnectionCreated D-Bus signal in a more generic way.
Also updated PurpleAccount to make it annouce any new PurpleAccount.

diffstat:

 libpurple/dbus/account.c       |   2 +
 libpurple/dbus/constructor.c   |  70 +++++++++++++++++++++++------------------
 libpurple/dbus/constructor.h   |   9 +++++
 libpurple/dbus/constructor.xml |   8 ++--
 4 files changed, 54 insertions(+), 35 deletions(-)

diffs (149 lines):

diff --git a/libpurple/dbus/account.c b/libpurple/dbus/account.c
--- a/libpurple/dbus/account.c
+++ b/libpurple/dbus/account.c
@@ -176,6 +176,8 @@
 	purple_object_dbus_bind_notify(pobject);
 
 	if (purple_core_is_daemon_mode()) {
+		/* Tell the clients about this new account. */
+		purple_constructor_announce_pobject_creation(pobject);
 	} else if (purple_core_is_remote_mode()) {
 		/* This will add our new account
 		 * in the account list of accountlist.c. */
diff --git a/libpurple/dbus/constructor.c b/libpurple/dbus/constructor.c
--- a/libpurple/dbus/constructor.c
+++ b/libpurple/dbus/constructor.c
@@ -62,6 +62,7 @@
 G_DEFINE_TYPE(PurpleConstructor, purple_constructor, PURPLE_TYPE_OBJECT)
 
 static GVariant* purple_constructor_get_all_accounts(void);
+static void purple_constructor_pobj_created(PurpleObject *constructor, const char *type, const char *dbus_path, GVariant *props);
 
 static char*
 purple_constructor_build_dbus_path(PurpleObject *object)
@@ -69,24 +70,6 @@
 	return g_strdup(DBUS_CONSTRUCTOR_PATH);
 }
 
-/**
- * Callback called when we receive a dbus "PurpleConnectionCreated" signal.
- */
-static void
-purple_connection_created_cb(DBusGProxy *proxy, const char* account, gboolean regist, const char *password, gpointer data)
-{
-	GObject *account_obj;
-	PurpleRunningMode mode;
-
-	account_obj = purple_dbus_get_gobject_by_path(account);
-	g_return_if_fail(account_obj != NULL);
-
-	mode = purple_core_get_running_mode();
-	purple_core_set_running_mode(PURPLE_RUN_MIRROR_MODE);
-	purple_connection_new(PURPLE_ACCOUNT(account_obj), regist, password);
-	purple_core_set_running_mode(mode);
-}
-
 static void purple_constructor_init(PurpleConstructor* obj) {
 
 }
@@ -101,21 +84,11 @@
 	if (purple_core_is_daemon_mode()) {
 		purple_object_bind_dbus_callback(pobjclass, "GetAllAccounts",
 		                                 (GCallback)purple_constructor_get_all_accounts);
-		/**
-		 * Add dbus stuff to this gobject.
-		 */
-		g_signal_new("purple_connection_created", PURPLE_TYPE_CONSTRUCTOR,
-					G_SIGNAL_RUN_LAST, 0, NULL, NULL,
-					purple_smarshal_VOID__STRING_BOOLEAN_STRING,
-					G_TYPE_NONE, 3,
-					G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING);
 	}
 	else if (purple_core_is_remote_mode()) {
-		/* Marshaller for the PurpleConnectionCreated dbus signals */
-		dbus_g_object_register_marshaller(
-			purple_smarshal_VOID__STRING_BOOLEAN_STRING,
-			G_TYPE_NONE, G_TYPE_STRING, G_TYPE_BOOLEAN,
-			G_TYPE_STRING, G_TYPE_INVALID);
+		/* D-Bus signal handlers. */
+		purple_object_bind_dbus_callback(pobjclass, "PurpleObjectCreated",
+		                                 (GCallback)purple_constructor_pobj_created);
 	}
 }
 
@@ -349,3 +322,38 @@
 {
 	purple_constructor_load_all_pobj("GetAllAccounts", "PurpleAccount");
 }
+
+void
+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),
+	                       pack_pobject_properties(pobj));
+	purple_object_emit_dbus_signal(PURPLE_OBJECT(con), "PurpleObjectCreated",
+	                               params, NULL);
+}
+
+/* "PurpleObjectCreated" signal handler. */
+static void
+purple_constructor_pobj_created(PurpleObject *constructor, const gchar *type,
+                                const gchar *dbus_path, GVariant *props)
+{
+	gpointer *obj;
+
+	/* If we are the one who created this object, we already have it. */
+	if (purple_dbus_get_gobject_by_path(dbus_path))
+		return;
+
+	obj = purple_constructor_new_proxy_object(type, props);
+	g_variant_unref(props);
+
+	purple_object_set_dbus_path(PURPLE_OBJECT(obj), dbus_path);
+	g_free((gchar*)dbus_path);
+
+	purple_object_dbus_init(obj);
+	purple_object_set_synchronized(PURPLE_OBJECT(obj), TRUE);
+}
diff --git a/libpurple/dbus/constructor.h b/libpurple/dbus/constructor.h
--- a/libpurple/dbus/constructor.h
+++ b/libpurple/dbus/constructor.h
@@ -58,6 +58,15 @@
 PurpleConstructor* purple_constructor_get_instance(void);
 
 /**
+ * Sends a "PurpleObjectCreated" D-Bus signal that announce the creation
+ * of the object pobj. The object must be properly initialized, with a
+ * dbus path name set.
+ *
+ * @param pobj The PurpleObject you want to tell the clients about.
+ */
+void purple_constructor_announce_pobject_creation(PurpleObject *pobj);
+
+/**
  * What's get actually called when you call NewAccount over dbus.
  */
 gboolean DBUS_purple_constructor_new_account(PurpleConstructor *con, gchar* username, gchar* protocol_id, gchar **account_path, GError** error);
diff --git a/libpurple/dbus/constructor.xml b/libpurple/dbus/constructor.xml
--- a/libpurple/dbus/constructor.xml
+++ b/libpurple/dbus/constructor.xml
@@ -11,10 +11,10 @@
 			<arg type="a(oa(sv))" name="accounts" direction="out" />
 		</method>
 
-		<signal name="PurpleConnectionCreated">
-			<arg type="o" name="account" />
-			<arg type="b" name="regist" />
-			<arg type="s" name="password" />
+		<signal name="PurpleObjectCreated">
+			<arg type="s"     name="type" />
+			<arg type="o"     name="path" />
+			<arg type="a(sv)" name="properties" />
 		</signal>
 	</interface>
 </node>



More information about the Commits mailing list