cpw.gillux.detachablepurple: d4f8bcdb: Added yet another virtual function in Pu...

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


----------------------------------------------------------------------
Revision: d4f8bcdb2b33fde33439f951b4a8ca16d0b1e49a
Parent:   7b5d8e574517497dff30a49d7db6a72f4d70a0fd
Author:   gillux at soc.pidgin.im
Date:     05/14/12 20:38:52
Branch:   im.pidgin.cpw.gillux.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/d4f8bcdb2b33fde33439f951b4a8ca16d0b1e49a

Changelog: 

Added yet another virtual function in PurpleObjectClass to handle
the D-Bus initialization of PurpleObjects in a more generic way.
This will allow generic construction of PurpleObjects by the
PurpleConstructor, which is handy for client side proxy objects.

Also updated PurpleAccount to take advantage of this.

Changes against parent 7b5d8e574517497dff30a49d7db6a72f4d70a0fd

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

-------------- next part --------------
============================================================
--- libpurple/account.c	f9e8a6fe865fb3f26a410a11219fc9e957a91ba3
+++ libpurple/account.c	e81935e59beaeb3d60ccca82cb490e9b1d72f5cf
@@ -817,7 +817,6 @@ purple_account_new(const char *username,
 	priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
 
 	PURPLE_DBUS_REGISTER_POINTER(account, PurpleAccount);
-	purple_account_dbus_init(account);
 
 	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
 	if (prpl_info != NULL && prpl_info->status_types != NULL)
@@ -838,6 +837,9 @@ purple_account_new(const char *username,
 
 	g_signal_emit_by_name(G_OBJECT(account), "new");
 
+	/* D-Bus-related initialization. */
+	purple_object_dbus_init(account);
+
 	return account;
 }
 
============================================================
--- libpurple/pobject.c	16b3cd7c9195aa3663bf96f016b3068d4fec757b
+++ libpurple/pobject.c	8d6b246f8d84441d057ad38ec4f474ce2baf7433
@@ -904,6 +904,16 @@ purple_object_dbus_connect(gpointer obje
 	}
 }
 
+void
+purple_object_dbus_init(gpointer object)
+{
+	PurpleObjectClass *pclass = PURPLE_OBJECT_GET_CLASS(object);
+
+	if (pclass->dbus_init) {
+		pclass->dbus_init(object);
+	}
+}
+
 /* 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	db2fc77c9104e0024011a7242c64ebe97d26b21e
+++ libpurple/pobject.h	a8aadb380ed9069aa0f06104774525e6b4829015
@@ -64,8 +64,13 @@ struct _PurpleObjectClass
 	   be set in daemon mode, or possibly in client mode for well-known
 	   names. */
 	char* (*build_dbus_path)(PurpleObject *object);
+	/* A function used for D-Bus initialization of a newly-created object.
+	 * Use purple_object_dbus_init() to call it. This allows generic
+	 * creation of PurpleObject proxy objects on the client side by the
+	 * PurpleConstructor. */
+	void (*dbus_init)(gpointer object);
 #else
-	void (*_purple_reserved[4])(void);
+	void (*_purple_reserved[5])(void);
 #endif
 };
 
@@ -393,6 +398,13 @@ void purple_object_set_prop_on_dbus(Purp
 void purple_object_set_prop_on_dbus(PurpleObject *pobj, gchar *prop_name, ...);
 
 /**
+ * Calls the dbus_init function pointer on a child of PurpleObject.
+ *
+ * @param object A child of PurpleObject.
+ */
+void purple_object_dbus_init(gpointer object);
+
+/**
  * 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
============================================================
--- libpurple/dbus/account.c	4396fba10b79ffbacbdcac11afcd85b9dbec3f62
+++ libpurple/dbus/account.c	00036b22a68b26e91005d5929a2cb31cfce9901f
@@ -163,12 +163,33 @@ purple_account_build_dbus_path(PurpleObj
         return id;
 }
 
+/* D-Bus initialization part of a newly-created PurpleAccount object. */
+static void
+purple_account_dbus_init(gpointer object)
+{
+	PurpleAccount *account = PURPLE_ACCOUNT(object);
+	PurpleObject *pobject = PURPLE_OBJECT(account);
+
+	/* Publish/listen for the object on the bus. */
+	purple_dbus_connect_object(account);
+	/* Keep the properties synchronized between client and daemon. */
+	purple_object_dbus_bind_notify(pobject);
+
+	if (purple_core_is_daemon_mode()) {
+	} else if (purple_core_is_remote_mode()) {
+		/* This will add our new account
+		 * in the account list of accountlist.c. */
+		g_signal_emit_by_name(G_OBJECT(account), "new");
+	}
+}
+
 void
 purple_account_class_dbus_init(PurpleAccountClass *klass)
 {
 	PurpleObjectClass *pobjclass = PURPLE_OBJECT_CLASS(klass);
 
 	pobjclass->dbus_ifaceinfo = &purple_account_interface_info;
+	pobjclass->dbus_init = purple_account_dbus_init;
 	if (purple_core_is_daemon_mode()) {
 		pobjclass->build_dbus_path = purple_account_build_dbus_path;
 		purple_object_bind_dbus_callback(pobjclass, "Connect",
@@ -222,41 +243,6 @@ purple_account_class_dbus_init(PurpleAcc
 	}
 }
 
-void
-purple_account_dbus_init(PurpleAccount *account)
-{
-        DBusGProxy* proxy;
-
-	purple_dbus_connect_object(account);
-
-	purple_object_dbus_bind_notify(PURPLE_OBJECT(account));
-
-	if (purple_core_is_remote_mode() || purple_core_is_mirror_mode()) {
-		/* For clients connect our wrapper sighandlers */
-		proxy = purple_object_get_dbus_obj_proxy(PURPLE_OBJECT(account));
-		dbus_g_proxy_add_signal(proxy, "NotifyAdded", G_TYPE_STRING,
-		                        G_TYPE_STRING, G_TYPE_STRING,
-		                        G_TYPE_STRING, G_TYPE_INVALID);
-		dbus_g_proxy_connect_signal(proxy, "NotifyAdded",
-		                            G_CALLBACK(notify_added_cb),
-		                            account, NULL);
-		dbus_g_proxy_add_signal(proxy, "RequestAdd", G_TYPE_STRING,
-		                        G_TYPE_STRING, G_TYPE_STRING,
-		                        G_TYPE_STRING, G_TYPE_INVALID);
-		dbus_g_proxy_connect_signal(proxy, "RequestAdd",
-		                            G_CALLBACK(request_add_cb),
-		                            account, NULL);
-		dbus_g_proxy_add_signal(proxy, "RequestAuthorize",
-		                        G_TYPE_STRING,  G_TYPE_STRING,
-		                        G_TYPE_STRING,  G_TYPE_STRING,
-		                        G_TYPE_BOOLEAN, G_TYPE_UINT,
-		                        G_TYPE_INVALID);
-		dbus_g_proxy_connect_signal(proxy, "RequestAuthorize",
-		                            G_CALLBACK(request_authorize_cb),
-		                            account, NULL);
-	}
-}
-
 PurpleAccount*
 purple_account_new_RPC(const char *username, const char *protocol_id)
 {
============================================================
--- libpurple/dbus/account.h	db96e733979cb0343efb36a28f098e34f60ea3d5
+++ libpurple/dbus/account.h	5a55f43bd5650379beae6daccb394185218a88ca
@@ -31,11 +31,6 @@ void purple_account_class_dbus_init(Purp
 void purple_account_class_dbus_init(PurpleAccountClass *klass);
 
 /**
- * Initialize the dbus data of a new account.
- */
-void purple_account_dbus_init(PurpleAccount *account);
-
-/**
  * Used in remote mode context, to remotely call purple_account_new().
  */
 PurpleAccount* purple_account_new_RPC(const char *username, const char *protocol_id);


More information about the Commits mailing list