soc.2010.detachablepurple: b940d485: Added a new dbus PurpleConnectionCreated...

gillux at soc.pidgin.im gillux at soc.pidgin.im
Thu Aug 5 00:04:06 EDT 2010


----------------------------------------------------------------------
Revision: b940d485f0443cb8551e535476805acc622b70f7
Parent:   2de5609ea4502b780a975ed3a7d2bf9ceddfcef0
Author:   gillux at soc.pidgin.im
Date:     08/04/10 23:51:36
Branch:   im.pidgin.soc.2010.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/b940d485f0443cb8551e535476805acc622b70f7

Changelog: 

Added a new dbus PurpleConnectionCreated signal, which allows the daemon to
inform the clients when a new PurpleConnection is created, so that they can
locally create a mirror of it. Next on the daemon, when a PurpleConnection
is destroyed by a purple_account_set_connection(account, NULL), it is destroyed
on the clients aswell thanks to the propagation of the PurpleAccount
"connection" property.

Changes against parent 2de5609ea4502b780a975ed3a7d2bf9ceddfcef0

  patched  libpurple/connection-dbus.c
  patched  libpurple/connection-dbus.h
  patched  libpurple/connection.c
  patched  libpurple/dbus-constructor.c
  patched  libpurple/dbus-prototypes/constructor.xml
  patched  libpurple/marshallers.list

-------------- next part --------------
============================================================
--- libpurple/connection.c	ce68e922bd43e16b9a991b492e6fba109d7cf153
+++ libpurple/connection.c	d64954a3519d0a7ddfd93c05dbc6a97737a0109d
@@ -226,7 +226,7 @@ _purple_connection_new(PurpleAccount *ac
 
 	gc = g_object_new(PURPLE_TYPE_CONNECTION, "account", account, NULL);
 	PURPLE_DBUS_REGISTER_POINTER(gc, PurpleConnection);
-	purple_connection_dbus_init(gc, account);
+	purple_connection_dbus_init(gc, account, regist, password);
 
 	priv = PURPLE_CONNECTION_GET_PRIVATE(gc);
 
============================================================
--- libpurple/marshallers.list	b9acaa6e0fa6b897e7da8bf33ac343f89f3e199a
+++ libpurple/marshallers.list	c2e39429ac51b6cd04f33420a7a54cfddcf7053d
@@ -16,6 +16,8 @@ VOID:UINT64,BOXED
 VOID:STRING,BOXED
 # Marshaller for the RunCallback dbus signal
 VOID:UINT64,BOXED
+# Marshaller for the PurpleConnectionCreated dbus signal
+VOID:STRING,BOOLEAN,STRING
 # Marshaller for the NotifyAdded and RequestAdd dbus signal
 VOID:STRING,STRING,STRING,STRING
 # Marshaller for the RequestAuthorize dbus signal
============================================================
--- libpurple/dbus-constructor.c	517e9b8a885f8d22773f40435a685d87ba4acd03
+++ libpurple/dbus-constructor.c	847e1cc1755342e8102f910166b3b0dfb2b6f6de
@@ -21,14 +21,19 @@
 
 #include <dbus/dbus-glib-bindings.h>
 
+/* Hack to allow purple_connection_new() in connection.h */
+#define _PURPLE_CONNECTION_C_
+
 #include "internal.h"
 #include "account.h"
 #include "accountlist.h"
+#include "connection.h"
 #include "dbus-constructor.h"
 #include "dbus-constructor-client.h"
 #include "dbus-constructor-server.h"
 #include "dbus-maybe.h"
 #include "debug.h"
+#include "marshallers.h"
 
 /**
  * PurpleConstructor, a dummy class to remotely create and load gobjects over DBus.
@@ -55,23 +60,57 @@ G_DEFINE_TYPE(PurpleConstructor, purple_
 
 G_DEFINE_TYPE(PurpleConstructor, purple_constructor, PURPLE_TYPE_OBJECT)
 
+/**
+ * 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) {
 
 }
 
 static void purple_constructor_class_init(PurpleConstructorClass *klass)
 {
-	/**
-	 * Add dbus stuff to this gobject.
-	 * dbus_glib_DBUS_purple_constructor_object_info is defined in
-	 * dbus-constructor-server.h, which is autogenerated.
-	 */
-	purple_object_type_install_dbus_infos(PURPLE_TYPE_CONSTRUCTOR,
-					&dbus_glib_DBUS_purple_constructor_object_info);
+	if (purple_core_is_daemon_mode()) {
+		/**
+		 * Add dbus stuff to this gobject.
+		 * dbus_glib_DBUS_purple_constructor_object_info is defined in
+		 * dbus-constructor-server.h, which is autogenerated.
+		 */
+		purple_object_type_install_dbus_infos(PURPLE_TYPE_CONSTRUCTOR,
+						&dbus_glib_DBUS_purple_constructor_object_info);
+
+		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);
+	}
 }
 
 PurpleConstructor* purple_constructor_get_instance(void) {
 	static PurpleConstructor* self = NULL;
+	DBusGProxy* proxy;
 
 	if (self == NULL) {
 		self = g_object_new(PURPLE_TYPE_CONSTRUCTOR, NULL);
@@ -79,6 +118,16 @@ PurpleConstructor* purple_constructor_ge
 					PURPLE_OBJECT(self),
 					DBUS_CONSTRUCTOR_INTERFACE,
 					DBUS_CONSTRUCTOR_PATH);
+		if (purple_core_is_remote_mode() || purple_core_is_mirror_mode()) {
+			/* Connect our sighandlers */
+			proxy = purple_object_get_dbus_obj_proxy(PURPLE_OBJECT(self));
+			dbus_g_proxy_add_signal(proxy, "PurpleConnectionCreated",
+									G_TYPE_STRING, G_TYPE_BOOLEAN,
+									G_TYPE_STRING, G_TYPE_INVALID);
+			dbus_g_proxy_connect_signal(proxy, "PurpleConnectionCreated",
+									G_CALLBACK(purple_connection_created_cb),
+									self, NULL);
+		}
 	}
 	return self;
 }
============================================================
--- libpurple/dbus-prototypes/constructor.xml	5f283dd83a16b683279061f7f0f1a605d0ab0886
+++ libpurple/dbus-prototypes/constructor.xml	b6b15368478836425c43e628b0241f992e6022cd
@@ -10,5 +10,11 @@
 		<method name="GetAllAccounts">
 			<arg type="a(osa(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>
 	</interface>
 </node>
============================================================
--- libpurple/connection-dbus.c	294b739f0d9968a4df8f2ee665667f2877965f77
+++ libpurple/connection-dbus.c	2122ae75074adf1cda35c9b404cbf869d85cfdaa
@@ -24,6 +24,7 @@
 #include "core.h"
 #include "dbus-connection-client.h"
 #include "dbus-connection-server.h"
+#include "dbus-constructor.h"
 #include "dbus-server.h"
 #include "dbus-purple.h"
 #include "pobject.h"
@@ -56,7 +57,7 @@ void
 }
 
 void
-purple_connection_dbus_init(PurpleConnection *gc, PurpleAccount *account)
+purple_connection_dbus_init(PurpleConnection *gc, PurpleAccount *account, gboolean regist, const char *password)
 {
 	char* dbus_path;
 
@@ -64,4 +65,13 @@ purple_connection_dbus_init(PurpleConnec
 	purple_object_install_dbus_infos(PURPLE_OBJECT(gc),
 	                                 DBUS_CONNECTION_INTERFACE, dbus_path);
 	g_free(dbus_path);
+
+	if (purple_core_is_daemon_mode()) {
+		/* Inform the clients we have a new PurpleConnection. */
+		g_signal_emit_by_name(
+		           G_OBJECT(purple_constructor_get_instance()),
+	                   "purple_connection_created",
+	                   purple_object_get_dbus_path(PURPLE_OBJECT(account)),
+	                   regist, password);
+	}
 }
============================================================
--- libpurple/connection-dbus.h	52db8c215c0c2e93f6e08f9d24e16bb754346f82
+++ libpurple/connection-dbus.h	4299cc3a9223bfdbc79b19d355f700d4e0fcbf8b
@@ -29,7 +29,7 @@ void purple_connection_class_dbus_init(v
 /**
  * Initialize the dbus data of a new connection.
  */
-void purple_connection_dbus_init(PurpleConnection *gc, PurpleAccount *account);
+void purple_connection_dbus_init(PurpleConnection *gc, PurpleAccount *account, gboolean regist, const char *password);
 
 #else /* !HAVE_DBUS */
 


More information about the Commits mailing list