/srv/mercurial-server/detachablepurple: d50d2ece9408: Rewritten ...
Gilles Bedel
gillux at cpw.pidgin.im
Fri Jun 15 22:01:45 EDT 2012
Changeset: d50d2ece94082f00cf47a47984182beeb5abf330
Author: Gilles Bedel <gillux at cpw.pidgin.im>
Date: 2012-05-20 16:39 +0000
Branch: cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/d50d2ece9408
Description:
Rewritten the D-Bus code of PurpleBuddyList, according to the new
gdbus-based API. Note that we don't need a dummy GObject anymore. :)
diffstat:
libpurple/blist.c | 13 ++++--
libpurple/dbus/blist.c | 87 ++++++++++---------------------------------------
libpurple/dbus/blist.h | 17 ++++-----
3 files changed, 33 insertions(+), 84 deletions(-)
diffs (207 lines):
diff --git a/libpurple/blist.c b/libpurple/blist.c
--- a/libpurple/blist.c
+++ b/libpurple/blist.c
@@ -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 @@
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_get_list();
- /* Create and expose the blist object */
- purple_blist_init_dbus();
}
void
@@ -1325,9 +1329,6 @@
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 @@
* 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
diff --git a/libpurple/dbus/blist.c b/libpurple/dbus/blist.c
--- a/libpurple/dbus/blist.c
+++ b/libpurple/dbus/blist.c
@@ -27,38 +27,10 @@
#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
@@ -106,57 +78,34 @@
/* 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);
- }
-}
-
-static PurpleBListDBus *
-purple_blist_dbus_get_instance(void)
-{
- PurpleBListDBusClass *klass;
- PurpleBListDBus *instance;
-
- 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;
+ /* Publish/listen for the object on the bus. */
+ purple_dbus_connect_object(object);
}
void
-purple_blist_init_dbus(void)
+purple_blist_class_dbus_init(PurpleObjectClass *pobjclass)
{
- purple_blist_dbus_get_instance();
-}
+ /* Register our interface. */
+ purple_object_class_register_dbus_iface
+ (pobjclass, g_type_from_name("PurpleBuddyList"),
+ &purple_blist_interface_info);
-void
-purple_blist_uninit_dbus(void)
-{
- PurpleBListDBusClass *klass;
+ pobjclass->dbus_init = purple_blist_dbus_init;
- klass = g_type_class_peek(PURPLE_TYPE_BLIST_DBUS);
- g_return_if_fail(klass->instance != NULL);
- g_object_unref(klass->instance);
+ /* Both client and daemon can build this well-known name. */
+ pobjclass->build_dbus_path = purple_blist_build_dbus_path;
+
+ if (purple_core_is_daemon_mode()) {
+ }
}
/**
diff --git a/libpurple/dbus/blist.h b/libpurple/dbus/blist.h
--- a/libpurple/dbus/blist.h
+++ b/libpurple/dbus/blist.h
@@ -28,17 +28,15 @@
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);
-
-/**
- * Destroys the PurpleBuddyList dbus equivalent singleton.
- */
-void purple_blist_uninit_dbus(void);
+void purple_blist_class_dbus_init(PurpleObjectClass *klass);
/**
* 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 @@
#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