cpw.gillux.detachablepurple: 2a84ab02: Rewritten the NewAccount D-Bus method ac...

gillux at soc.pidgin.im gillux at soc.pidgin.im
Mon May 14 23:26:53 EDT 2012


----------------------------------------------------------------------
Revision: 2a84ab02517d2f281b127a2d5eca272e52cbd1b9
Parent:   1851d02a08ac063e0dd1b117d0eab5d6936a712f
Author:   gillux at soc.pidgin.im
Date:     05/14/12 23:18:50
Branch:   im.pidgin.cpw.gillux.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/2a84ab02517d2f281b127a2d5eca272e52cbd1b9

Changelog: 

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

Changes against parent 1851d02a08ac063e0dd1b117d0eab5d6936a712f

  patched  libpurple/account.c
  patched  libpurple/dbus/account.c
  patched  libpurple/dbus/account.h
  patched  libpurple/dbus/constructor.c
  patched  libpurple/dbus/constructor.h
  patched  libpurple/dbus/constructor.xml

-------------- next part --------------
============================================================
--- libpurple/account.c	e81935e59beaeb3d60ccca82cb490e9b1d72f5cf
+++ libpurple/account.c	912da524a4ad903f4ae512d4784a037226150270
@@ -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"
============================================================
--- libpurple/dbus/account.c	0b31e38876073e802e06958d587bf878b393351f
+++ libpurple/dbus/account.c	f794c468c37520e33d1ead6af0e06cf476af6401
@@ -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 @@ purple_account_class_dbus_init(PurpleAcc
 	}
 }
 
-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)
 {
============================================================
--- libpurple/dbus/account.h	5a55f43bd5650379beae6daccb394185218a88ca
+++ libpurple/dbus/account.h	ddadf3c21eea7364a4d670425662f8f967aa6f4b
@@ -31,11 +31,6 @@ void purple_account_class_dbus_init(Purp
 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 @@ G_END_DECLS
 
 #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)
============================================================
--- libpurple/dbus/constructor.c	eec81733d8ed8b9df073045b6c63a41694b1968a
+++ libpurple/dbus/constructor.c	e872531096da84204d33958e7b8cd47a7cf09000
@@ -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 void purple_constructor_pobj_crea
 
 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 @@ static void purple_constructor_class_ini
 	/* 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 @@ purple_constructor_get_instance(void)
 PurpleConstructor*
 purple_constructor_get_instance(void)
 {
-	DBusGProxy* proxy;
 	PurpleConstructorClass *klass;
 	PurpleConstructor *self;
 
@@ -122,32 +126,10 @@ purple_constructor_get_instance(void)
 		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_constructor_pobj_created(PurpleOb
 	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;
+}
============================================================
--- libpurple/dbus/constructor.h	ca7b46db648855449c7eb77db758ca0ee202b1e1
+++ libpurple/dbus/constructor.h	e76cd179321714bfebd81ba8f477b18e723717fe
@@ -81,11 +81,17 @@ void purple_accounts_get_all_RPC(void);
  */
 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_ */
============================================================
--- libpurple/dbus/constructor.xml	a11c53991c0d5f02557d6867e866e5b93f6b55cb
+++ libpurple/dbus/constructor.xml	c01c7d7215dfa0a678274afadca95ab249c316c3
@@ -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