/srv/mercurial-server/detachablepurple: 5265e5a0ea4c: Added yet ...
Gilles Bedel
gillux at cpw.pidgin.im
Fri Jun 15 22:01:35 EDT 2012
Changeset: 5265e5a0ea4c3e9d1af4c1d6af33f312656bb004
Author: Gilles Bedel <gillux at cpw.pidgin.im>
Date: 2012-05-15 00:38 +0000
Branch: cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/5265e5a0ea4c
Description:
Added yet another virtual function in PurpleObjectClass to handle
the D-Bus initialization of PurpleObjects in a more generic way.
This will allow generic construction of PurpleObjects by the
PurpleConstructor, which is handy for client side proxy objects.
Also updated PurpleAccount to take advantage of this.
diffstat:
libpurple/account.c | 4 ++-
libpurple/dbus/account.c | 56 ++++++++++++++++++------------------------------
libpurple/dbus/account.h | 5 ----
libpurple/pobject.c | 10 ++++++++
libpurple/pobject.h | 14 +++++++++++-
5 files changed, 47 insertions(+), 42 deletions(-)
diffs (167 lines):
diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -817,7 +817,6 @@
priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
PURPLE_DBUS_REGISTER_POINTER(account, PurpleAccount);
- purple_account_dbus_init(account);
prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
if (prpl_info != NULL && prpl_info->status_types != NULL)
@@ -838,6 +837,9 @@
g_signal_emit_by_name(G_OBJECT(account), "new");
+ /* D-Bus-related initialization. */
+ purple_object_dbus_init(account);
+
return account;
}
diff --git a/libpurple/dbus/account.c b/libpurple/dbus/account.c
--- a/libpurple/dbus/account.c
+++ b/libpurple/dbus/account.c
@@ -163,12 +163,33 @@
return id;
}
+/* D-Bus initialization part of a newly-created PurpleAccount object. */
+static void
+purple_account_dbus_init(gpointer object)
+{
+ PurpleAccount *account = PURPLE_ACCOUNT(object);
+ PurpleObject *pobject = PURPLE_OBJECT(account);
+
+ /* Publish/listen for the object on the bus. */
+ purple_dbus_connect_object(account);
+ /* Keep the properties synchronized between client and daemon. */
+ purple_object_dbus_bind_notify(pobject);
+
+ if (purple_core_is_daemon_mode()) {
+ } else if (purple_core_is_remote_mode()) {
+ /* This will add our new account
+ * in the account list of accountlist.c. */
+ g_signal_emit_by_name(G_OBJECT(account), "new");
+ }
+}
+
void
purple_account_class_dbus_init(PurpleAccountClass *klass)
{
PurpleObjectClass *pobjclass = PURPLE_OBJECT_CLASS(klass);
pobjclass->dbus_ifaceinfo = &purple_account_interface_info;
+ pobjclass->dbus_init = purple_account_dbus_init;
if (purple_core_is_daemon_mode()) {
pobjclass->build_dbus_path = purple_account_build_dbus_path;
purple_object_bind_dbus_callback(pobjclass, "Connect",
@@ -222,41 +243,6 @@
}
}
-void
-purple_account_dbus_init(PurpleAccount *account)
-{
- DBusGProxy* proxy;
-
- purple_dbus_connect_object(account);
-
- purple_object_dbus_bind_notify(PURPLE_OBJECT(account));
-
- if (purple_core_is_remote_mode() || purple_core_is_mirror_mode()) {
- /* For clients connect our wrapper sighandlers */
- proxy = purple_object_get_dbus_obj_proxy(PURPLE_OBJECT(account));
- dbus_g_proxy_add_signal(proxy, "NotifyAdded", G_TYPE_STRING,
- G_TYPE_STRING, G_TYPE_STRING,
- G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(proxy, "NotifyAdded",
- G_CALLBACK(notify_added_cb),
- account, NULL);
- dbus_g_proxy_add_signal(proxy, "RequestAdd", G_TYPE_STRING,
- G_TYPE_STRING, G_TYPE_STRING,
- G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(proxy, "RequestAdd",
- G_CALLBACK(request_add_cb),
- account, NULL);
- dbus_g_proxy_add_signal(proxy, "RequestAuthorize",
- G_TYPE_STRING, G_TYPE_STRING,
- G_TYPE_STRING, G_TYPE_STRING,
- G_TYPE_BOOLEAN, G_TYPE_UINT,
- G_TYPE_INVALID);
- dbus_g_proxy_connect_signal(proxy, "RequestAuthorize",
- G_CALLBACK(request_authorize_cb),
- account, NULL);
- }
-}
-
PurpleAccount*
purple_account_new_RPC(const char *username, const char *protocol_id)
{
diff --git a/libpurple/dbus/account.h b/libpurple/dbus/account.h
--- a/libpurple/dbus/account.h
+++ b/libpurple/dbus/account.h
@@ -31,11 +31,6 @@
void purple_account_class_dbus_init(PurpleAccountClass *klass);
/**
- * Initialize the dbus data of a new account.
- */
-void purple_account_dbus_init(PurpleAccount *account);
-
-/**
* Used in remote mode context, to remotely call purple_account_new().
*/
PurpleAccount* purple_account_new_RPC(const char *username, const char *protocol_id);
diff --git a/libpurple/pobject.c b/libpurple/pobject.c
--- a/libpurple/pobject.c
+++ b/libpurple/pobject.c
@@ -904,6 +904,16 @@
}
}
+void
+purple_object_dbus_init(gpointer object)
+{
+ PurpleObjectClass *pclass = PURPLE_OBJECT_GET_CLASS(object);
+
+ if (pclass->dbus_init) {
+ pclass->dbus_init(object);
+ }
+}
+
/* Merges all the args signatures in a tuple and create a GVariantType from
* that. Code shamely copied from glib's gdbusprivate.c. */
static GVariantType *
diff --git a/libpurple/pobject.h b/libpurple/pobject.h
--- a/libpurple/pobject.h
+++ b/libpurple/pobject.h
@@ -64,8 +64,13 @@
be set in daemon mode, or possibly in client mode for well-known
names. */
char* (*build_dbus_path)(PurpleObject *object);
+ /* A function used for D-Bus initialization of a newly-created object.
+ * Use purple_object_dbus_init() to call it. This allows generic
+ * creation of PurpleObject proxy objects on the client side by the
+ * PurpleConstructor. */
+ void (*dbus_init)(gpointer object);
#else
- void (*_purple_reserved[4])(void);
+ void (*_purple_reserved[5])(void);
#endif
};
@@ -393,6 +398,13 @@
void purple_object_set_prop_on_dbus(PurpleObject *pobj, gchar *prop_name, ...);
/**
+ * Calls the dbus_init function pointer on a child of PurpleObject.
+ *
+ * @param object A child of PurpleObject.
+ */
+void purple_object_dbus_init(gpointer object);
+
+/**
* Remotely calls method_name on pobj over D-Bus. Actually, it's not called
* on this pojb object but on the remote associated one. The input parameters
* are all the variable parameters, and must follow the method input parameters
More information about the Commits
mailing list