soc.2010.detachablepurple: d2258743: Code moves and cleanups, dbus related co...

gillux at soc.pidgin.im gillux at soc.pidgin.im
Wed Jul 28 19:25:46 EDT 2010


----------------------------------------------------------------------
Revision: d225874339aecd68f8cd641e6ca7dd367c644f91
Parent:   eacfa3ae69ce431ea2ee4c27cfa43b5a230938cf
Author:   gillux at soc.pidgin.im
Date:     07/28/10 18:34:44
Branch:   im.pidgin.soc.2010.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/d225874339aecd68f8cd641e6ca7dd367c644f91

Changelog: 

Code moves and cleanups, dbus related code is now placed in a separate file
or properly surrounded by #ifdef HAVE_DBUS. Purple now compiles well with or
without dbus support.

Changes against parent eacfa3ae69ce431ea2ee4c27cfa43b5a230938cf

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

-------------- next part --------------
============================================================
--- libpurple/core.c	b66d4414a72e9c27dc986b85d607000fe56f74fd
+++ libpurple/core.c	1e0f362c371ffe27a8eda35135a82011629fc55b
@@ -326,7 +326,7 @@ purple_core_set_running_mode(PurpleRunni
 void
 purple_core_set_running_mode(PurpleRunningMode mode)
 {
-#if HAVE_DBUS
+#ifdef HAVE_DBUS
 	g_return_if_fail(mode < PURPLE_RUN_MODE_LAST);
 	_running_mode = mode;
 #else
============================================================
--- libpurple/account.c	4e445cfa9c4273157049022162b6388be42c23c7
+++ libpurple/account.c	82d102699d44d3cfe53d505b6457914dcf718f1c
@@ -44,10 +44,6 @@
 #include "util.h"
 #include "xmlnode.h"
 
-#ifdef HAVE_DBUS
-#  include "dbus-account-server.h"
-#endif
-
 #define PURPLE_ACCOUNT_GET_PRIVATE(account) \
 	(G_TYPE_INSTANCE_GET_PRIVATE((account), PURPLE_TYPE_ACCOUNT, PurpleAccountPrivate))
 typedef struct _PurpleAccountPrivate		PurpleAccountPrivate;
@@ -754,11 +750,7 @@ static void purple_account_class_init(Pu
 
 #warning TODO: Setup more signals
 
-	/* Add dbus stuff */
-	if (purple_core_is_daemon_mode())
-		/* Install method introspection data */
-		purple_object_type_install_dbus_infos(PURPLE_TYPE_ACCOUNT,
-									&dbus_glib_DBUS_purple_account_object_info);
+	purple_account_class_dbus_init();
 
 	g_type_class_add_private(klass, sizeof(PurpleAccountPrivate));
 }
@@ -789,22 +781,6 @@ GType purple_account_get_gtype(void)
 	return type;
 }
 
-static char*
-build_dbus_path(const char *username, const char *protocol_id)
-{
-	gchar *id;
-	gchar *id2;
-
-	id = g_strjoin("/", protocol_id, username, NULL);
-	id2 = purple_dbus_sanitize_dbus_path(id);
-	g_free(id);
-
-	id = g_strjoin("/", DBUS_ACCOUNT_PATH, id2, NULL);
-        g_free(id2);
-
-        return id;
-}
-
 PurpleAccount *
 purple_account_new(const char *username, const char *protocol_id)
 {
@@ -813,7 +789,6 @@ purple_account_new(const char *username,
 	PurplePluginProtocolInfo *prpl_info = NULL;
 	PurpleStatusType *status_type;
 	PurpleAccountPrivate *priv;
-	char* dbus_path;
 
 	g_return_val_if_fail(username != NULL, NULL);
 	g_return_val_if_fail(protocol_id != NULL, NULL);
@@ -837,12 +812,8 @@ purple_account_new(const char *username,
 	priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
 
 	PURPLE_DBUS_REGISTER_POINTER(account, PurpleAccount);
+	purple_account_dbus_init(account, username, protocol_id);
 
-	dbus_path = build_dbus_path(username, protocol_id);
-	purple_object_install_dbus_infos(PURPLE_OBJECT(account),
-					DBUS_ACCOUNT_INTERFACE, dbus_path);
-	g_free(dbus_path);
-
 	prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
 	if (prpl_info != NULL && prpl_info->status_types != NULL)
 		purple_account_set_status_types(account, prpl_info->status_types(account));
============================================================
--- libpurple/pobject.c	8a219f45bf7c4c7c4c6bb633d614056136dfce78
+++ libpurple/pobject.c	311eb298d1c5ee2d15aed035dede13216b47c180
@@ -77,8 +77,10 @@ purple_object_dispose(GObject *obj)
 
 	g_signal_emit(pobj, signals[SIG_DESTROYING], 0);
 
+#ifdef HAVE_DBUS
 	/* Forget about the associated dbus path */
 	purple_dbus_disassoc_gobject(priv->dbus_path);
+#endif
 
 	if (priv->proto_data) {
 		g_warning("Purple-Object: object destroyed without unsetting the protocol data. This may lead to memory leak.\n");
@@ -221,6 +223,7 @@ gpointer purple_object_get_ui_data(Purpl
 	return priv->ui_data;
 }
 
+#ifdef HAVE_DBUS
 char*
 purple_object_get_dbus_obj_interface(PurpleObject *pobj)
 {
@@ -357,14 +360,13 @@ purple_object_install_dbus_infos(PurpleO
 void
 purple_object_install_dbus_infos(PurpleObject *pobj, char *dbus_interface, char *dbus_path)
 {
-#ifdef HAVE_DBUS
 	DBusGProxy* dbus_proxy;
 	PurpleObjectPrivate *priv;
 
 	g_return_if_fail(pobj);
 	priv = PURPLE_OBJECT_GET_PRIVATE(pobj);
 
-	if (purple_core_is_remote_mode()) {
+	if (purple_core_is_remote_mode() || purple_core_is_mirror_mode()) {
 		/* One for the org.freedesktop.DBus.Properties interface */
 		dbus_proxy = dbus_g_proxy_new_for_name(
 					purple_dbus_get_g_connection(),
@@ -411,7 +413,6 @@ purple_object_install_dbus_infos(PurpleO
 		                 G_CALLBACK(purple_object_forward_notify_cb),
 		                 NULL);
 	}
-#endif	
 }
 
 static GQuark
@@ -430,7 +431,6 @@ purple_object_type_dbus_metadata_quark(v
  * @param object_type GType for the object
  * @param infos A DBusGObjectInfo pointer, this data is generated by dbus-binding-tool.
  */
-#ifdef HAVE_DBUS
 void
 purple_object_type_install_dbus_infos(GType object_type, const DBusGObjectInfo *infos)
 {
@@ -441,9 +441,7 @@ purple_object_type_install_dbus_infos(GT
 
 	g_type_set_qdata(object_type, quark, (gpointer)infos);
 }
-#endif
 
-#ifdef HAVE_DBUS
 GPtrArray*
 purple_object_get_dbus_props(GType object_type, char *interface)
 {
============================================================
--- libpurple/pobject.h	361dcab847cecc98355bee35da0642e864367128
+++ libpurple/pobject.h	2d604aada43b7dce4d8537d044e215118476cc13
@@ -63,6 +63,7 @@ gpointer purple_object_get_ui_data(Purpl
 
 gpointer purple_object_get_ui_data(PurpleObject *pobj);
 
+#ifdef HAVE_DBUS
 /**
  * Gets the dbus proxy. This is used in detachable sessions context only.
  * When a client is in remote mode, the gobjects it creates are kind of mirrors
@@ -106,9 +107,6 @@ gboolean purple_object_have_dbus_propert
  */
 gboolean purple_object_have_dbus_property(PurpleObject *pobj, const gchar *interface, const gchar *prop_name);
 
-
-#ifdef HAVE_DBUS
-
 /**
  * Convenience function to install the dbus proxies, the dbus path and the
  * interface name in a PurpleObject. Depending on the running state of purple
@@ -142,20 +140,6 @@ GPtrArray* purple_object_get_dbus_props(
  */
 GPtrArray* purple_object_get_dbus_props(GType object_type, char *interface);
 
-#else /* !HAVE_DBUS */
-
-/* Giving this macro, on a system without dbus, a code such as :
- * purple_object_install_dbus_infos(obj, get_interface(), build_path());
- * wouldn't even run the get_interface() or build_path() functions.
- */
-#define purple_object_install_dbus_infos(pobj, interface, path) ((void)0)
-
-#define purple_object_type_install_dbus_infos(object_type, infos) ((void)0)
-
-#define purple_object_get_dbus_props(object_type, interface) (NULL)
-
-#endif
-
 /**
  * Gets the dbus path associated with this PurpleObject.
  * Each gobjects that are published on DBus have a path name (something like
@@ -174,6 +158,7 @@ void purple_object_set_dbus_path(PurpleO
  * @param path The path name.
  */
 void purple_object_set_dbus_path(PurpleObject *pobj, char* path);
+#endif /* HAVE_DBUS */
 
 int purple_object_get_int(PurpleObject *pobj, const char *prop);
 
============================================================
--- libpurple/account-dbus.c	0e3f10364345a859490dd0d47bfed04a31f7ac5b
+++ libpurple/account-dbus.c	7a38d6c8e83004ae19e5803da4ee9f2155e1bea9
@@ -6,10 +6,48 @@
 #include "account.h"
 #include "account-dbus.h"
 #include "dbus-account-client.h"
+#include "dbus-account-server.h"
 #include "dbus-callback.h"
 #include "dbus-constructor-client.h"
 #include "dbus-maybe.h"
 
+static char*
+build_dbus_path(const char *username, const char *protocol_id)
+{
+	gchar *id;
+	gchar *id2;
+
+	id = g_strjoin("/", protocol_id, username, NULL);
+	id2 = purple_dbus_sanitize_dbus_path(id);
+	g_free(id);
+
+	id = g_strjoin("/", DBUS_ACCOUNT_PATH, id2, NULL);
+        g_free(id2);
+
+        return id;
+}
+
+void
+purple_account_class_dbus_init(void)
+{
+	if (purple_core_is_daemon_mode()) {
+		/* Install method introspection data */
+		purple_object_type_install_dbus_infos(PURPLE_TYPE_ACCOUNT,
+				&dbus_glib_DBUS_purple_account_object_info);
+	}
+}
+
+void
+purple_account_dbus_init(PurpleAccount *account, const char *username, const char *protocol_id)
+{
+	char* dbus_path;
+
+	dbus_path = build_dbus_path(username, protocol_id);
+	purple_object_install_dbus_infos(PURPLE_OBJECT(account),
+					DBUS_ACCOUNT_INTERFACE, dbus_path);
+	g_free(dbus_path);	
+}
+
 PurpleAccount*
 purple_account_new_RPC(const char *username, const char *protocol_id)
 {
============================================================
--- libpurple/account-dbus.h	d37cde3ed930ebe696ec57e2724374f59bf7592c
+++ libpurple/account-dbus.h	d208aa60879efceed44adcad9ef0f7cdd5d5d4d2
@@ -2,6 +2,16 @@
 #ifdef HAVE_DBUS
 
 /**
+ * Initialize the dbus data of the account class.
+ */
+void purple_account_class_dbus_init(void);
+
+/**
+ * Initialize the dbus data of a new account.
+ */
+void purple_account_dbus_init(PurpleAccount *account, const char *username, const char *protocol_id);
+
+/**
  * Used in remote mode context, to remotely call purple_account_new().
  */
 PurpleAccount* purple_account_new_RPC(const char *username, const char *protocol_id);
@@ -48,10 +58,12 @@ gboolean DBUS_purple_account_unregister(
 
 #else /* !HAVE_DBUS */
 
+#define purple_account_class_dbus_init()              ((void)0)
+#define purple_account_dbus_init(acc, user, proto)    ((void)0)
 #define purple_account_new_RPC(username, protocol_id) (NULL)
 #define purple_account_connect_RPC(account)           ((void)0)
 #define purple_account_register_RPC(account)          ((void)0)
 #define purple_account_set_status_list_RPC(acc, status, active, attr) ((void)0)
-#define purple_account_unregister(account, cb, user_data) ((void)0)
+#define purple_account_unregister_RPC(account, cb, user_data) ((void)0)
 
 #endif /* HAVE_DBUS */


More information about the Commits mailing list