/srv/mercurial-server/detachablepurple: b85aa5ff19fd: Rewritten ...

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


Changeset: b85aa5ff19fdc63847227f0604fb448cead8a98f
Author:	 Gilles Bedel <gillux at cpw.pidgin.im>
Date:	 2012-05-20 16:45 +0000
Branch:	 cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/b85aa5ff19fd

Description:

Rewritten the "GetBuddyList" D-Bus method for the new gdbus-based API.
Much more simpler and cleaner. :)

diffstat:

 libpurple/blist.c            |    3 +-
 libpurple/dbus/blist.c       |  589 +++++-------------------------------------
 libpurple/dbus/blist.h       |    4 +-
 libpurple/dbus/blist.xml     |   26 +-
 libpurple/dbus/constructor.c |   11 +-
 5 files changed, 104 insertions(+), 529 deletions(-)

diffs (truncated from 747 to 300 lines):

diff --git a/libpurple/blist.c b/libpurple/blist.c
--- a/libpurple/blist.c
+++ b/libpurple/blist.c
@@ -25,6 +25,7 @@
 
 #include "internal.h"
 #include "accountlist.h"
+#include "blist.h"
 #include "dbus-maybe.h"
 #include "dbus/blist.h"
 #include "debug.h"
@@ -398,7 +399,7 @@
 
 	/* In remote mode, get the buddy list from the daemon instead. */
 	if (purple_core_is_remote_mode())
-		return purple_blist_load_RPC();
+		return purple_blist_load_RPC(PURPLE_OBJECT(PURPLE_BLIST));
 
 	purple = purple_util_read_xml_from_file("blist.xml", _("buddy list"));
 
diff --git a/libpurple/dbus/blist.c b/libpurple/dbus/blist.c
--- a/libpurple/dbus/blist.c
+++ b/libpurple/dbus/blist.c
@@ -26,54 +26,17 @@
 #include "blist-node.h"
 #include "core.h"
 #include "dbus/blist.h"
-#include "dbus/blist-client.h"
 #include "dbus/blist.xml.h"
+#include "dbus/constructor.h"
 #include "dbus-maybe.h"
 #include "dbus-purple.h"
 
+/* The type PurpleBuddyList is only defined in libpurple/blist.c. While we
+ * don't strictly need it, we use it here and there for the sake of
+ * consistency. Hence this dummy type definition: */
+typedef void PurpleBlist;
 
-/* Server side dbus methods.
- * Theses functions needs PurpleBListDBus declared, and must go before the
- * inclusion of blist-server.h, in which they are defined. */
-gboolean DBUS_purple_blist_get_buddy_list(PurpleBListDBus *blist, GPtrArray **groups, GPtrArray **contacts, GPtrArray **buddies, GPtrArray **chats, GError** error);
-#include "dbus/blist-server.h"
-
-/* DBus transfered data formats */
-#define DBUS_PURPLE_BLIST_SETTING \
-( \
-	dbus_g_type_get_struct("GValueArray", \
-		G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID) \
-)
-#define DBUS_PURPLE_BLIST_SETTINGS \
-( \
-	dbus_g_type_get_collection("GPtrArray", \
-		DBUS_PURPLE_BLIST_SETTING) \
-)
-#define DBUS_PURPLE_GROUP_PACK \
-( \
-	dbus_g_type_get_struct("GValueArray", \
-		G_TYPE_STRING, G_TYPE_STRING, DBUS_PURPLE_BLIST_SETTINGS, \
-		G_TYPE_INVALID) \
-)
-#define DBUS_PURPLE_CONTACT_PACK \
-( \
-	dbus_g_type_get_struct("GValueArray", \
-		G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, \
-		DBUS_PURPLE_BLIST_SETTINGS, G_TYPE_INVALID) \
-)
-#define DBUS_PURPLE_BUDDY_PACK \
-( \
-	dbus_g_type_get_struct("GValueArray", \
-		G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, \
-		G_TYPE_STRING, DBUS_PURPLE_BLIST_SETTINGS, G_TYPE_INVALID) \
-)
-#define DBUS_PURPLE_CHAT_PACK \
-( \
-	dbus_g_type_get_struct("GValueArray", \
-		G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, \
-		DBUS_TYPE_G_STRING_STRING_HASHTABLE, G_TYPE_STRING, \
-		DBUS_PURPLE_BLIST_SETTINGS, G_TYPE_INVALID) \
-)
+static GVariant * purple_blist_get_buddy_list(PurpleBlist *blist);
 
 /* A convenience macro. */
 #define parent_node_dbus_path(node) purple_object_get_dbus_path(PURPLE_OBJECT(purple_blist_node_parent(node)))
@@ -105,222 +68,37 @@
 	pobjclass->build_dbus_path = purple_blist_build_dbus_path;
 
 	if (purple_core_is_daemon_mode()) {
+		/* D-Bus method handlers. */
+		purple_object_bind_dbus_callback
+		  (pobjclass, purple_blist_interface_info.name,
+		   "GetBuddyList", (GCallback)purple_blist_get_buddy_list);
 	}
 }
 
 /**
- * Callback used by settings_to_ptr_array().
- * Builds a DBUS_PURPLE_BLIST_SETTING struct, to export a setting on dbus.
+ * Recursive function. Goes through the buddy list and fills the
+ * GVariantBuilders from what it encounters.
  */
 static void
-blist_setting_to_array(const char *name, GValue *value, GPtrArray *settings)
-{
-	GValue setting = {0, };
-	gboolean ok;
-
-	g_value_init(&setting, DBUS_PURPLE_BLIST_SETTING);
-	g_value_take_boxed(&setting,
-	         dbus_g_type_specialized_construct(DBUS_PURPLE_BLIST_SETTING));
-	ok = dbus_g_type_struct_set(&setting, 0, name, 1, value, G_MAXUINT);
-
-	g_return_if_fail(ok == TRUE);
-	g_ptr_array_add(settings, g_value_get_boxed(&setting));
-}
-
-/**
- * Converts the settings of the provided PurpleBlistNode into a
- * DBUS_PURPLE_BLIST_SETTINGS GPtrArray (array of GValues), to export them on
- * dbus. Caller is responsible for freeing the array and the GValues in it.
- * Used to pack data in DBUS_purple_blist_get_buddy_list().
- */
-static GPtrArray *
-settings_to_ptr_array(PurpleBlistNode *node)
-{
-	GPtrArray *array;
-	GHashTable *settings_hash;
-
-	array = g_ptr_array_new();
-	settings_hash = purple_blist_node_get_settings(PURPLE_BLIST_NODE(node));
-	g_hash_table_foreach(settings_hash,
-	                     (GHFunc)blist_setting_to_array, array);
-	return array;
-}
-
-/**
- * Packs a PurpleGroup in a DBUS_PURPLE_GROUP_PACK struct,
- * to export it on dbus, and append it in the provided groups array.
- * Used to pack data in DBUS_purple_blist_get_buddy_list().
- */
-static void
-pack_group(GPtrArray *groups, PurpleGroup *group)
-{
-	GValue group_pack = {0, };
-	gboolean ok;
-	char *group_path;
-	const char *group_name;
-	GPtrArray *settings_pack;
-
-	g_value_init(&group_pack, DBUS_PURPLE_GROUP_PACK);
-	g_value_set_boxed(&group_pack,
-	            dbus_g_type_specialized_construct(DBUS_PURPLE_GROUP_PACK));
-
-	group_path = purple_object_get_dbus_path(PURPLE_OBJECT(group));
-	group_name = purple_group_get_name(group);
-	settings_pack = settings_to_ptr_array(PURPLE_BLIST_NODE(group));
-	ok = dbus_g_type_struct_set(&group_pack,
-	                            0, group_path,
-	                            1, group_name,
-	                            2, settings_pack, G_MAXUINT);
-
-	g_ptr_array_foreach(settings_pack, (GFunc)g_value_array_free, NULL);
-	g_ptr_array_free(settings_pack, TRUE);
-
-	g_return_if_fail(ok == TRUE);
-	g_ptr_array_add(groups, g_value_get_boxed(&group_pack));
-}
-
-/**
- * Packs a PurpleContact in a DBUS_PURPLE_CONTACT_PACK struct,
- * to export it on dbus, and append it in the provided contacts array.
- * Used to pack data in DBUS_purple_blist_get_buddy_list().
- */
-static void
-pack_contact(GPtrArray *contacts, PurpleContact *contact)
-{
-	GValue contact_pack = {0, };
-	gboolean ok;
-	char* contact_path;
-	const char *alias;
-	char *parent_path;
-	GPtrArray *settings_pack;
-
-	g_value_init(&contact_pack, DBUS_PURPLE_CONTACT_PACK);
-	g_value_set_boxed(&contact_pack,
-	          dbus_g_type_specialized_construct(DBUS_PURPLE_CONTACT_PACK));
-
-	contact_path = purple_object_get_dbus_path(PURPLE_OBJECT(contact));
-	alias = purple_contact_get_alias(contact);
-	parent_path = parent_node_dbus_path(PURPLE_BLIST_NODE(contact));
-	settings_pack = settings_to_ptr_array(PURPLE_BLIST_NODE(contact));
-	ok = dbus_g_type_struct_set(&contact_pack,
-	                            0, contact_path,
-	                            1, alias,
-	                            2, parent_path,
-	                            3, settings_pack, G_MAXUINT);
-
-	g_ptr_array_foreach(settings_pack, (GFunc)g_value_array_free, NULL);
-	g_ptr_array_free(settings_pack, TRUE);
-
-	g_return_if_fail(ok == TRUE);
-	g_ptr_array_add(contacts, g_value_get_boxed(&contact_pack));
-}
-
-/**
- * Packs a PurpleBuddy in a DBUS_PURPLE_BUDDY_PACK struct,
- * to export it on dbus, and append it in the provided buddies array.
- * Used to pack data in DBUS_purple_blist_get_buddy_list().
- */
-static void
-pack_buddy(GPtrArray *buddies, PurpleBuddy *buddy)
-{
-	GValue buddy_pack = {0, };
-	gboolean ok;
-	char *buddy_path;
-	char *account_path;
-	const char *name;
-	const char *alias;
-	char *parent_path;
-	GPtrArray *settings_pack;
-
-	g_value_init(&buddy_pack, DBUS_PURPLE_BUDDY_PACK);
-	g_value_set_boxed(&buddy_pack,
-	          dbus_g_type_specialized_construct(DBUS_PURPLE_BUDDY_PACK));
-
-	buddy_path   = purple_object_get_dbus_path(PURPLE_OBJECT(buddy));
-	account_path = purple_object_get_dbus_path(
-	                      PURPLE_OBJECT(purple_buddy_get_account(buddy)));
-	name  = purple_buddy_get_name(buddy);
-	alias = purple_buddy_get_alias_only(buddy);
-	parent_path = parent_node_dbus_path(PURPLE_BLIST_NODE(buddy));
-	settings_pack = settings_to_ptr_array(PURPLE_BLIST_NODE(buddy));
-	ok = dbus_g_type_struct_set(&buddy_pack,
-	                            0, buddy_path,
-	                            1, account_path,
-	                            2, name,
-	                            3, alias,
-	                            4, parent_path,
-	                            5, settings_pack, G_MAXUINT);
-
-	g_ptr_array_foreach(settings_pack, (GFunc)g_value_array_free, NULL);
-	g_ptr_array_free(settings_pack, TRUE);
-
-	g_return_if_fail(ok == TRUE);
-	g_ptr_array_add(buddies, g_value_get_boxed(&buddy_pack));
-}
-
-/**
- * Packs a PurpleChat in a DBUS_PURPLE_CHAT_PACK struct,
- * to export it on dbus, and append it in the provided chats array.
- * Used to pack data in DBUS_purple_blist_get_buddy_list().
- */
-static void
-pack_chat(GPtrArray *chats, PurpleChat *chat)
-{
-	GValue chat_pack = {0, };
-	gboolean ok;
-	char *chat_path;
-	char *account_path;
-	const char *alias;
-	GHashTable *components;
-	char *parent_path;
-	GPtrArray *settings_pack;
-
-	g_value_init(&chat_pack, DBUS_PURPLE_CHAT_PACK);
-	g_value_set_boxed(&chat_pack,
-	          dbus_g_type_specialized_construct(DBUS_PURPLE_CHAT_PACK));
-
-	chat_path    = purple_object_get_dbus_path(PURPLE_OBJECT(chat));
-	account_path = purple_object_get_dbus_path(
-	                        PURPLE_OBJECT(purple_chat_get_account(chat)));
-	alias        = purple_chat_get_alias(chat);
-	components   = purple_chat_get_components(chat);
-	parent_path  = parent_node_dbus_path(PURPLE_BLIST_NODE(chat));
-	settings_pack = settings_to_ptr_array(PURPLE_BLIST_NODE(chat));
-	ok = dbus_g_type_struct_set(&chat_pack,
-	                            0, chat_path,
-	                            1, account_path,
-	                            2, alias,
-	                            3, components,
-	                            4, parent_path,
-	                            5, settings_pack, G_MAXUINT);
-
-	g_ptr_array_foreach(settings_pack, (GFunc)g_value_array_free, NULL);
-	g_ptr_array_free(settings_pack, TRUE);
-
-	g_return_if_fail(ok == TRUE);
-	g_ptr_array_add(chats, g_value_get_boxed(&chat_pack));
-}
-
-/**
- * Recursive function. Goes through the buddy list and fills the GPtrArrays
- * from what it encounter.
- * Used to pack data in purple_blist_get_buddy_list_RPC().
- */
-static void
-pack_node(PurpleBlistNode *node, GPtrArray *groups, GPtrArray *contacts,
-          GPtrArray *buddies, GPtrArray *chats)
+pack_node(PurpleBlistNode *node,
+          GVariantBuilder *groups,  GVariantBuilder *contacts,



More information about the Commits mailing list