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

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


Changeset: bb97888d5f037fe64b015cd0dfc433c5a44da934
Author:	 Gilles Bedel <gillux at cpw.pidgin.im>
Date:	 2012-05-15 03:18 +0000
Branch:	 cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/bb97888d5f03

Description:

Rewritten the NewAccount D-Bus method according to the new gbus-based API.
And added some forgotten #includes.

diffstat:

 libpurple/account.c            |   1 +
 libpurple/dbus/account.c       |  32 +-----------------------
 libpurple/dbus/account.h       |   6 ----
 libpurple/dbus/constructor.c   |  55 ++++++++++++++++++++++++-----------------
 libpurple/dbus/constructor.h   |   6 ++++
 libpurple/dbus/constructor.xml |   7 +++--
 6 files changed, 44 insertions(+), 63 deletions(-)

diffs (224 lines):

diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -30,6 +30,7 @@
 #include "core.h"
 #include "dbus-maybe.h"
 #include "dbus/callback.h"
+#include "dbus/constructor.h"
 #include "debug.h"
 #include "marshallers.h"
 #include "network.h"
diff --git a/libpurple/dbus/account.c b/libpurple/dbus/account.c
--- a/libpurple/dbus/account.c
+++ b/libpurple/dbus/account.c
@@ -25,6 +25,7 @@
 #include "dbus/account-client.h"
 #include "dbus/account-server.h"
 #include "dbus/callback.h"
+#include "dbus/constructor.h"
 #include "dbus/constructor-client.h"
 #include "dbus-maybe.h"
 #include "marshallers.h"
@@ -245,37 +246,6 @@
 	}
 }
 
-PurpleAccount*
-purple_account_new_RPC(const char *username, const char *protocol_id)
-{
-	PurpleAccount* account;
-	char* dbus_path;
-	DBusGProxy* dbus_proxy;
-	GError *error = NULL;
-	PurpleRunningMode mode;
-
-	/* First, remotely create a new account */
-	dbus_proxy = dbus_g_proxy_new_for_name(purple_gdbus_get_connection(),
-	                                       DBUS_PURPLE_SERVICE,
-	                                       DBUS_CONSTRUCTOR_PATH,
-	                                       DBUS_CONSTRUCTOR_INTERFACE);
-	if (!im_pidgin_purple_constructor_new_account(dbus_proxy, username,
-	                                              protocol_id, &dbus_path,
-	                                              &error)) {
-		PURPLE_RPC_FAILED(purple_account_new, error);
-		return NULL;
-	}
-
-	/* Then, locally create a mirror account that will hold a proxy */
-	/* Act in normal mode so that the account is created locally */
-	mode = purple_core_get_running_mode();
-	purple_core_set_running_mode(PURPLE_RUN_MIRROR_MODE);
-	account = purple_account_new(username, protocol_id);
-	purple_core_set_running_mode(mode);
-
-	return account;
-}
-
 void
 purple_account_connect_RPC(PurpleAccount* account)
 {
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);
 
 /**
- * Used in remote mode context, to remotely call purple_account_new().
- */
-PurpleAccount* purple_account_new_RPC(const char *username, const char *protocol_id);
-
-/**
  * Client side purple_account_connect() wrapper.
  */
 void purple_account_connect_RPC(PurpleAccount* account);
@@ -91,7 +86,6 @@
 
 #define purple_account_class_dbus_init()              ((void)0)
 #define purple_account_dbus_init(acc)                 ((void)0)
-#define purple_account_new_RPC(username, protocol_id) (NULL)
 #define purple_account_connect_RPC(account)           ((void)0)
 #define purple_account_disconnect_RPC(account)        ((void)0)
 #define purple_account_register_RPC(account)          ((void)0)
diff --git a/libpurple/dbus/constructor.c b/libpurple/dbus/constructor.c
--- a/libpurple/dbus/constructor.c
+++ b/libpurple/dbus/constructor.c
@@ -31,6 +31,7 @@
 #include "dbus/constructor.h"
 #include "dbus/constructor.xml.h"
 #include "dbus-maybe.h"
+#include "dbus-server.h"
 #include "debug.h"
 #include "marshallers.h"
 
@@ -63,6 +64,7 @@
 
 static GVariant* purple_constructor_get_all_accounts(void);
 static void purple_constructor_pobj_created(PurpleObject *constructor, const char *type, const char *dbus_path, GVariant *props);
+static GVariant* purple_constructor_new_account(PurpleObject *constructor, const char *username, const char *protocol_id);
 
 static char*
 purple_constructor_build_dbus_path(PurpleObject *object)
@@ -82,8 +84,11 @@
 	/* Both client and daemon can build this well-known name. */
 	pobjclass->build_dbus_path = purple_constructor_build_dbus_path;
 	if (purple_core_is_daemon_mode()) {
+		/* D-Bus method handlers. */
 		purple_object_bind_dbus_callback(pobjclass, "GetAllAccounts",
 		                                 (GCallback)purple_constructor_get_all_accounts);
+		purple_object_bind_dbus_callback(pobjclass, "NewAccount",
+		                                 (GCallback)purple_constructor_new_account);
 	}
 	else if (purple_core_is_remote_mode()) {
 		/* D-Bus signal handlers. */
@@ -111,7 +116,6 @@
 PurpleConstructor*
 purple_constructor_get_instance(void)
 {
-	DBusGProxy* proxy;
 	PurpleConstructorClass *klass;
 	PurpleConstructor *self;
 
@@ -122,32 +126,10 @@
 		klass->instance = self;
 
 		purple_dbus_connect_object(self);
-		if (purple_core_is_remote_mode() || purple_core_is_mirror_mode()) {
-			/* Connect our sighandlers */
-			proxy = purple_object_get_dbus_obj_proxy(PURPLE_OBJECT(self));
-			dbus_g_proxy_add_signal(proxy, "PurpleConnectionCreated",
-									G_TYPE_STRING, G_TYPE_BOOLEAN,
-									G_TYPE_STRING, G_TYPE_INVALID);
-			dbus_g_proxy_connect_signal(proxy, "PurpleConnectionCreated",
-									G_CALLBACK(purple_connection_created_cb),
-									self, NULL);
-		}
 	}
 	return klass->instance;
 }
 
-gboolean
-DBUS_purple_constructor_new_account(PurpleConstructor *con, gchar* username, gchar* protocol_id, gchar **account_path, GError** error)
-{
-	PurpleAccount* account = purple_account_new(username, protocol_id);
-	if(account) {
-		*account_path = purple_object_get_dbus_path(PURPLE_OBJECT(account));
-		return TRUE;
-	} else {
-		return FALSE;
-	}
-}
-
 /* Creates a new proxy gobject of type_name, initializing its properties with
  * what's in props.
  */
@@ -357,3 +339,30 @@
 	purple_object_dbus_init(obj);
 	purple_object_set_synchronized(PURPLE_OBJECT(obj), TRUE);
 }
+
+/* "NewAccount" method handler. */
+static GVariant*
+purple_constructor_new_account(PurpleObject *constructor,
+                               const char *username, const char *protocol_id)
+{
+	PurpleAccount *account;
+	account = purple_account_new(username, protocol_id);
+	return pack_pobject(account);
+}
+
+PurpleAccount *
+purple_account_new_RPC(const char *username, const char *protocol_id)
+{
+	PurpleConstructor* con = purple_constructor_get_instance();
+	PurpleAccount *account = NULL;
+	GVariant *ret;
+
+	/* Remotely create this account. */
+	ret = purple_object_dbus_call(PURPLE_OBJECT(con), "NewAccount",
+	                              username, protocol_id);
+	if (ret) {
+		account = PURPLE_ACCOUNT(load_pobject(ret, "PurpleAccount"));
+		purple_object_set_synchronized(PURPLE_OBJECT(account), TRUE);
+	}
+	return account;
+}
diff --git a/libpurple/dbus/constructor.h b/libpurple/dbus/constructor.h
--- a/libpurple/dbus/constructor.h
+++ b/libpurple/dbus/constructor.h
@@ -81,11 +81,17 @@
  */
 void purple_accounts_get_all_RPC(void);
 
+/**
+ * RPC version of purple_account_new(), used by clients.
+ */
+PurpleAccount *purple_account_new_RPC(const char *username, const char *protocol_id);
+
 G_END_DECLS
 
 #else /* !HAVE_DBUS */
 
 #define purple_accounts_get_all_RPC() ((void)0)
+#define purple_account_new_RPC(username, protocol_id) ((void)0)
 
 #endif /* HAVE_DBUS */
 #endif /* _PURPLE_DBUS_CONSTRUCTOR_H_ */
diff --git a/libpurple/dbus/constructor.xml b/libpurple/dbus/constructor.xml
--- a/libpurple/dbus/constructor.xml
+++ b/libpurple/dbus/constructor.xml
@@ -3,9 +3,10 @@
 <node name="/im/pidgin/purple/constructor">
 	<interface name="im.pidgin.purple.constructor">
 		<method name="NewAccount">
-			<arg type="o" name="account"     direction="out" />
-			<arg type="s" name="username"    direction="in" />
-			<arg type="s" name="protocol_id" direction="in" />
+			<arg type="s"      name="username"    direction="in" />
+			<arg type="s"      name="protocol_id" direction="in" />
+			<arg type="o"      name="account_path"       direction="out" />
+			<arg type="a(sv)"  name="account_properties" direction="out" />
 		</method>
 		<method name="GetAllAccounts">
 			<arg type="a(oa(sv))" name="accounts" direction="out" />



More information about the Commits mailing list