/srv/mercurial-server/detachablepurple: 189380cff649: Changed a ...

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


Changeset: 189380cff64918a5dba1ec0e1a2206ba8962875d
Author:	 Gilles Bedel <gillux at cpw.pidgin.im>
Date:	 2012-05-12 19:06 +0000
Branch:	 cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/189380cff649

Description:

Changed a bit the way D-Bus path names are created.
We now use a generic builder function pointer that should only be set
if the caller will be able to garantee that the built name is unique.
That is, only either by the daemon, or if it's a well-known name,
by both dameon and clients. Also updated PurpleAccount's D-Bus code
accordingly.

diffstat:

 libpurple/dbus/account.c |  19 +++++++++++--------
 libpurple/pobject.c      |   8 ++++++++
 libpurple/pobject.h      |   6 +++++-
 3 files changed, 24 insertions(+), 9 deletions(-)

diffs (95 lines):

diff --git a/libpurple/dbus/account.c b/libpurple/dbus/account.c
--- a/libpurple/dbus/account.c
+++ b/libpurple/dbus/account.c
@@ -142,11 +142,17 @@
 }
 
 static char*
-purple_account_build_dbus_path(const char *username, const char *protocol_id)
+purple_account_build_dbus_path(PurpleObject *object)
 {
+	PurpleAccount *account;
+	const char *username, *protocol_id;
 	gchar *id;
 	gchar *id2;
 
+	account = PURPLE_ACCOUNT(object);
+	username = purple_account_get_username(account);
+	protocol_id = purple_account_get_protocol_id(account);
+
 	id = g_strjoin("/", protocol_id, username, NULL);
 	id2 = purple_dbus_sanitize_dbus_path(id);
 	g_free(id);
@@ -161,8 +167,10 @@
 purple_account_class_dbus_init(PurpleAccountClass *klass)
 {
 	PurpleObjectClass *pobjclass = PURPLE_OBJECT_CLASS(klass);
+
+	pobjclass->dbus_ifaceinfo = &purple_account_interface_info;
 	if (purple_core_is_daemon_mode()) {
-		pobjclass->dbus_ifaceinfo = &purple_account_interface_info;
+		pobjclass->build_dbus_path = purple_account_build_dbus_path;
 		purple_object_bind_dbus_callback(pobjclass, "Connect",
 		                                 (GCallback)purple_account_connect);
 		purple_object_bind_dbus_callback(pobjclass, "Disconnect",
@@ -215,15 +223,10 @@
 }
 
 void
-purple_account_dbus_init(PurpleAccount *account, const char *username, const char *protocol_id)
+purple_account_dbus_init(PurpleAccount *account)
 {
-	char* dbus_path;
         DBusGProxy* proxy;
 
-	dbus_path = purple_account_build_dbus_path(username, protocol_id);
-	purple_object_set_dbus_path(PURPLE_OBJECT(account), dbus_path);
-	g_free(dbus_path);	
-
 	purple_dbus_connect_object(account);
 
 	purple_object_dbus_bind_notify(PURPLE_OBJECT(account));
diff --git a/libpurple/pobject.c b/libpurple/pobject.c
--- a/libpurple/pobject.c
+++ b/libpurple/pobject.c
@@ -357,9 +357,15 @@
 purple_object_get_dbus_path(PurpleObject *pobj)
 {
 	PurpleObjectPrivate *priv;
+	PurpleObjectClass *pclass;
 
 	g_return_val_if_fail(pobj, NULL);
 	priv = PURPLE_OBJECT_GET_PRIVATE(pobj);
+	pclass = PURPLE_OBJECT_GET_CLASS(pobj);
+	if (!priv->dbus_path && pclass->build_dbus_path(pobj)) {
+		/* Let's try to build it. */
+		priv->dbus_path = pclass->build_dbus_path(pobj);
+	}
 	return priv->dbus_path;
 }
 
@@ -370,6 +376,8 @@
 
 	g_return_if_fail(pobj);
 	priv = PURPLE_OBJECT_GET_PRIVATE(pobj);
+	if (priv->dbus_path)
+		g_free(priv->dbus_path);
 	priv->dbus_path = g_strdup(path);
 }
 
diff --git a/libpurple/pobject.h b/libpurple/pobject.h
--- a/libpurple/pobject.h
+++ b/libpurple/pobject.h
@@ -59,7 +59,11 @@
 	GData *dbus_callbacks;
 	/* The C structure based representation of the XML DBus interface. */
 	GDBusInterfaceInfo *dbus_ifaceinfo;
-	void (*_purple_reserved[1])(void);
+	/* Build a unique dbus path name for the object. Only the deamon can
+	   garantee the uniqueness of a name, thus this function should only
+	   be set in daemon mode, or possibly in client mode for well-known
+	   names. */
+	char* (*build_dbus_path)(PurpleObject *object);
 #else
 	void (*_purple_reserved[4])(void);
 #endif



More information about the Commits mailing list