cpw.gillux.detachablepurple: 1cceaeb7: Rewritten the D-Bus code of PurpleBuddyL...

gillux at soc.pidgin.im gillux at soc.pidgin.im
Sun May 20 13:21:08 EDT 2012


----------------------------------------------------------------------
Revision: 1cceaeb7d3d76f2a6a6a424a65cef49fe8fb2cf9
Parent:   2e99e138d0e61e211c03698969f8f5941f1c6b3c
Author:   gillux at soc.pidgin.im
Date:     05/20/12 12:39:14
Branch:   im.pidgin.cpw.gillux.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/1cceaeb7d3d76f2a6a6a424a65cef49fe8fb2cf9

Changelog: 

Rewritten the D-Bus code of PurpleBuddyList, according to the new
gdbus-based API. Note that we don't need a dummy GObject anymore. :)

Changes against parent 2e99e138d0e61e211c03698969f8f5941f1c6b3c

  patched  libpurple/blist.c
  patched  libpurple/dbus/blist.c
  patched  libpurple/dbus/blist.h

-------------- next part --------------
============================================================
--- libpurple/blist.c	29d936c36a7f278e16ba8f2ffb7b27fbc9b58796
+++ libpurple/blist.c	5c60239af51f3caae935f756237bc680520cae71
@@ -29,6 +29,7 @@
 #include "dbus/blist.h"
 #include "debug.h"
 #include "gsignal.h"
+#include "pobject.h"
 #include "server.h"
 #include "signals.h"
 #include "xmlnode.h"
@@ -116,6 +117,11 @@ purple_blist_get_list()
 		list = g_object_new(PURPLE_TYPE_BUDDY_LIST, NULL);
 
 		purple_blist_load();
+
+		/* Publish the buddy list on D-Bus and propagate
+		 * any property change. */
+		purple_object_dbus_init(list, TRUE);
+
 		for (account = purple_accounts_all(); account != NULL; account = account->next)	{
 			purple_blist_buddies_cache_add_account(account->data);
 		}
@@ -1315,8 +1321,6 @@ purple_blist_init(void)
 purple_blist_init(void)
 {
 	purple_blist_get_list();
-	/* Create and expose the blist object */
-	purple_blist_init_dbus();
 }
 
 void
@@ -1325,9 +1329,6 @@ purple_blist_uninit(void)
 	PurpleBlistNode *node, *next_node;
 	PurpleBuddyList *list = PURPLE_BLIST;
 
-	/* Destroy the blist exposed object */
-	purple_blist_uninit_dbus();
-
 	if (list->save_timer != 0) {
 		purple_timeout_remove(list->save_timer);
 		list->save_timer = 0;
@@ -1581,6 +1582,8 @@ purple_blist_class_init(PurpleBuddyListC
 	 * hashtables. We also update the hashtables when the buddy gets removed, moved
 	 * or renamed. (TODO) */
 	purple_g_signal_connect(PURPLE_TYPE_BUDDY, "new", G_CALLBACK(new_buddy_added), NULL);
+
+	purple_blist_class_dbus_init(PURPLE_OBJECT_CLASS(klass));
 }
 
 static void
============================================================
--- libpurple/dbus/blist.c	db185f5825734e45ed1cea5fddbcc1cb310f5093
+++ libpurple/dbus/blist.c	59804fdab8fca26208b4df3adf127547847e4921
@@ -27,39 +27,11 @@
 #include "core.h"
 #include "dbus/blist.h"
 #include "dbus/blist-client.h"
+#include "dbus/blist.xml.h"
 #include "dbus-maybe.h"
 #include "dbus-purple.h"
 
-/**
- * GObject definition of PurpleBListDBus.
- *
- * This object is used to provide the PurpleBuddyList related functions
- * and uiops (the ones in libpurple/blist.h) over dbus. The PurpleBuddyList
- * object itself doesn't need dbus-exposing, but it would take less memory if
- * we could use it to do that. Sadly its gobject definition is not reachable
- * from outside libpurple/blist.c.
- */
 
-#define PURPLE_TYPE_BLIST_DBUS                  (purple_blist_dbus_get_type ())
-#define PURPLE_BLIST_DBUS(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), PURPLE_TYPE_BLIST_DBUS, PurpleBListDBus))
-#define PURPLE_IS_BLIST_DBUS(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PURPLE_TYPE_BLIST_DBUS))
-#define PURPLE_BLIST_DBUS_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), PURPLE_TYPE_BLIST_DBUS, PurpleBListDBusClass))
-#define PURPLE_IS_BLIST_DBUS_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), PURPLE_TYPE_BLIST_DBUS))
-#define PURPLE_GET_BLIST_DBUS_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), PURPLE_TYPE_BLIST_DBUS, PurpleBListDBusClass))
-
-GType purple_blist_dbus_get_type(void);
-
-typedef struct {
-	PurpleObject parent;	
-} PurpleBListDBus;
-
-typedef struct {
-	PurpleObjectClass parent;
-	PurpleBListDBus* instance;
-} PurpleBListDBusClass;
-
-G_DEFINE_TYPE(PurpleBListDBus, purple_blist_dbus, PURPLE_TYPE_OBJECT)
-
 /* Server side dbus methods.
  * Theses functions needs PurpleBListDBus declared, and must go before the
  * inclusion of blist-server.h, in which they are defined. */
@@ -106,57 +78,34 @@ gboolean DBUS_purple_blist_get_buddy_lis
 /* A convenience macro. */
 #define parent_node_dbus_path(node) purple_object_get_dbus_path(PURPLE_OBJECT(purple_blist_node_parent(node)))
 
-static void
-purple_blist_dbus_init(PurpleBListDBus *self)
+static char*
+purple_blist_build_dbus_path(PurpleObject *object)
 {
+	return g_strdup(DBUS_BLIST_PATH);
 }
 
 static void
-purple_blist_dbus_class_init(PurpleBListDBusClass *klass)
+purple_blist_dbus_init(gpointer object)
 {
-	klass->instance = NULL;
-
-	if (purple_core_is_daemon_mode()) {
-		/* Install method introspection data */
-		purple_object_type_install_dbus_infos(PURPLE_TYPE_BLIST_DBUS,
-		                     &dbus_glib_DBUS_purple_blist_object_info);
-	}
+	/* Publish/listen for the object on the bus. */
+	purple_dbus_connect_object(object);
 }
 
-static PurpleBListDBus *
-purple_blist_dbus_get_instance(void)
+void
+purple_blist_class_dbus_init(PurpleObjectClass *pobjclass)
 {
-	PurpleBListDBusClass *klass;
-	PurpleBListDBus *instance;
+	/* Register our interface. */
+	purple_object_class_register_dbus_iface
+	  (pobjclass, g_type_from_name("PurpleBuddyList"),
+	   &purple_blist_interface_info);
 
-	klass = g_type_class_peek(PURPLE_TYPE_BLIST_DBUS);
-	if (!klass) {
-		instance = g_object_new(PURPLE_TYPE_BLIST_DBUS, NULL);
-		klass = g_type_class_peek(PURPLE_TYPE_BLIST_DBUS);
-		klass->instance = instance;
-		
-		/* Register this object on DBus */
-		purple_object_install_dbus_infos(PURPLE_OBJECT(klass->instance),
-		                                 DBUS_BLIST_INTERFACE,
-		                                 DBUS_BLIST_PATH);
-	}
-	return klass->instance;
-}
+	pobjclass->dbus_init = purple_blist_dbus_init;
 
-void
-purple_blist_init_dbus(void)
-{
-	purple_blist_dbus_get_instance();
-}
+	/* Both client and daemon can build this well-known name. */
+	pobjclass->build_dbus_path = purple_blist_build_dbus_path;
 
-void
-purple_blist_uninit_dbus(void)
-{
-	PurpleBListDBusClass *klass;
-
-	klass = g_type_class_peek(PURPLE_TYPE_BLIST_DBUS);
-	g_return_if_fail(klass->instance != NULL);
-	g_object_unref(klass->instance);
+	if (purple_core_is_daemon_mode()) {
+	}
 }
 
 /**
============================================================
--- libpurple/dbus/blist.h	341b8277abd4ff41470037227b18f329be48a67b
+++ libpurple/dbus/blist.h	deaab5b09e0ca6fa5bf600c25df96ad036e2e4af
@@ -28,17 +28,15 @@ G_BEGIN_DECLS
 G_BEGIN_DECLS
 
 /**
- * Creates and exports the PurpleBuddyList dbus equivalent singleton.
+ * Initialize the dbus data of the blist class.
  */
-void purple_blist_init_dbus(void);
+void purple_blist_class_dbus_init(PurpleObjectClass *klass);
 
 /**
- * Destroys the PurpleBuddyList dbus equivalent singleton.
- */
-void purple_blist_uninit_dbus(void);
-
-/**
  * Calls the GetBuddyList dbus method and loads the received buddy list.
+ * Note that we should preferably pass the buddylist as a PurpleBuddyList,
+ * but since this type is only defined in libpurple/blist.c, we use the
+ * upper-class instead.
  */
 void purple_blist_load_RPC(void);
 
@@ -46,9 +44,8 @@ G_END_DECLS
 
 #else /* !HAVE_DBUS */
 
-#define purple_blist_init_dbus()                                 ((void)0)
-#define purple_blist_uninit_dbus()                               ((void)0)
-#define purple_blist_get_buddy_list_RPC()                        ((void)0)
+#define purple_blist_class_dbus_init(klass)                      ((void)0)
+#define purple_blist_load_RPC()                                  ((void)0)
 
 #endif /* HAVE_DBUS */
 #endif /* _PURPLE_DBUS_BLIST_H */


More information about the Commits mailing list