soc.2010.detachablepurple: 38f0e9cc: Added the PurpleConstructor gobject. It'...

gillux at soc.pidgin.im gillux at soc.pidgin.im
Tue Jul 6 17:01:08 EDT 2010


----------------------------------------------------------------------
Revision: 38f0e9cc124e845107df921f74d8748be7be5079
Parent:   1a5715819f7455c3d2ec02797337bd45dc686ff4
Author:   gillux at soc.pidgin.im
Date:     07/06/10 14:01:21
Branch:   im.pidgin.soc.2010.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/38f0e9cc124e845107df921f74d8748be7be5079

Changelog: 

Added the PurpleConstructor gobject. It's used to remotely create a gobject
over DBus. Because the only things you can call on dbus (using the glib mapping
we use) are gobject methods, we need some object to create other objects.
Currently we would only create PurpleAccounts.
In the design pattern world, I think it's called a singleton.

Changes against parent 1a5715819f7455c3d2ec02797337bd45dc686ff4

  added    libpurple/dbus-constructor.c
  added    libpurple/dbus-constructor.h

-------------- next part --------------
============================================================
--- /dev/null	
+++ libpurple/dbus-constructor.c	09aa1f02691374dcb4b31fabc39de2fef2ee1c02
@@ -0,0 +1,88 @@
+/* purple
+ *
+ * Purple is the legal property of its developers, whose names are too numerous
+ * to list here.  Please refer to the COPYRIGHT file distributed with this
+ * source distribution.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+#include <dbus/dbus-glib-bindings.h>
+
+#include "dbus-constructor.h"
+#include "dbus-constructor-server.h"
+
+#include "account.h"
+
+/**
+ * PurpleConstructor, a dummy class to remotely create gobjects over DBus.
+ *
+ * The DBus glib bindings allows to publish your gobjects on DBus. You can then
+ * call their methods and get/set their properties. But this only works for
+ * instantiated gobjects. So when you want to instantiate an object remotely,
+ * using an RPC, you also need to do this on some instantiated object.
+ *
+ * This is what this PurpleConstructor class is intended to do. It allows
+ * you to remotely create gobjects over dbus. Therefore, there is only one
+ * PurpleConstructor created for the whole program - the one held by
+ * purple_constructor_get_instance(). Over dbus this object is named
+ * /im/pidgin/purple/constructor.
+ *
+ * When you create an object with it, it returns you the DBus path of the
+ * created object (a thing like /im/pidgin/purple/stuff), and you can later
+ * use this path to do your stuff on your object.
+ *
+ * The available methods of this class should also be written in
+ * dbus-prototypes/constructor.xml.
+ */
+
+G_DEFINE_TYPE(PurpleConstructor, purple_constructor, G_TYPE_OBJECT)
+
+static void purple_constructor_init(PurpleConstructor* obj) {
+
+}
+
+static void purple_constructor_class_init(PurpleConstructorClass *klass)
+{
+	/**
+	 * Add dbus stuff to this gobject.
+	 * dbus_glib_DBUS_purple_constructor_object_info is defined in
+	 * dbus-constructor-server.h, which is autogenerated.
+	 */
+	dbus_g_object_type_install_info(PURPLE_TYPE_CONSTRUCTOR,
+					&dbus_glib_DBUS_purple_constructor_object_info);
+}
+
+PurpleConstructor* purple_constructor_get_instance(void) {
+	static PurpleConstructor* self = NULL;
+
+	if (self == NULL) {
+		self = g_object_new(PURPLE_TYPE_CONSTRUCTOR, NULL);
+	}
+	return self;
+}
+
+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;
+	}
+}
+
============================================================
--- /dev/null	
+++ libpurple/dbus-constructor.h	e5e4e93f903676a02c5a1f29f4c9e2fd8274d197
@@ -0,0 +1,28 @@
+
+#include "pobject.h"
+
+/* GObject definitions */
+
+#define PURPLE_TYPE_CONSTRUCTOR         (purple_constructor_get_type())
+
+GType purple_constructor_get_type(void);
+
+typedef struct {
+	PurpleObjectClass parent;
+} PurpleConstructorClass;
+
+typedef struct {
+	PurpleObject parent;
+} PurpleConstructor;
+
+G_BEGIN_DECLS
+
+PurpleConstructor* purple_constructor_get_instance(void);
+
+/**
+ * What's get actually called when you call NewAccount over dbus.
+ */
+gboolean DBUS_purple_constructor_new_account(PurpleConstructor *con, gchar* username, gchar* protocol_id, gchar **account_path, GError** error);
+
+G_END_DECLS
+


More information about the Commits mailing list