/srv/mercurial-server/detachablepurple: 99cb5770d26a: Mostly ren...

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


Changeset: 99cb5770d26aa8d43b21a71366af114f639e4cac
Author:	 Gilles Bedel <gillux at cpw.pidgin.im>
Date:	 2012-03-27 15:24 +0000
Branch:	 cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/99cb5770d26a

Description:

Mostly renamed the dbus "object registration" to "dbus connection"
as we are going to use this same process for both object registration
on the daemon side and connection to remote objects on the client side.
Now, the client in remote mode should connect to the bus and use
the same per-object dbus preparing callback system upon connection to
D-Bus.

diffstat:

 libpurple/dbus-server.c |  62 +++++++++++++++++++++++++++++++++---------------
 libpurple/dbus-server.h |   2 +-
 2 files changed, 44 insertions(+), 20 deletions(-)

diffs (125 lines):

diff --git a/libpurple/dbus-server.c b/libpurple/dbus-server.c
--- a/libpurple/dbus-server.c
+++ b/libpurple/dbus-server.c
@@ -88,13 +88,13 @@
 static GHashTable *map_id_node;
 static GHashTable *map_id_type;
 
-/* The bus acquiring process is asynchronous. We first ask to get it,
+/* The connection to the bus is asynchronous. We first ask to get it,
  * then the other parts of purple are initialized, and then when we
  * reach the program main loop, the on_bus_acquired callback is called.
  * Therefore we need something to remember the objects created during
  * the initialization that we will need to register on DBus when we get
  * the bus. We temporary hold a reference to such objects in this list. */
-static GSList *dbus_obj_to_register = NULL;
+static GSList *dbus_obj_on_bus = NULL;
 
 static gchar *init_error;
 static int dbus_request_name_reply = DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER;
@@ -782,38 +782,44 @@
 }
 
 void
-purple_dbus_register_object(gpointer object)
+purple_dbus_connect_object(gpointer object)
 {
 	if (purple_gdbus_connection)
 		purple_object_register_on_dbus(object, purple_gdbus_connection);
 	else
-		dbus_obj_to_register = g_slist_append(dbus_obj_to_register,
-		                                      g_object_ref(object));
+		dbus_obj_on_bus = g_slist_append(dbus_obj_on_bus, g_object_ref(object));
+}
+
+static void
+connect_waiting_objects(GDBusConnection *connection)
+{
+	GObject *obj;
+	GSList* obj_list;
+
+	for (obj_list = dbus_obj_on_bus; obj_list; obj_list = obj_list->next) {
+		obj = G_OBJECT(obj_list->data);
+		/* If we are owning the last a reference, it means we are going
+		 * to destroy it, so don’t bother registering it on DBus. */
+		if (obj->ref_count > 1)
+			purple_object_dbus_connect(obj_list->data, connection);
+		g_object_unref(obj);
+	}
+
+	g_slist_free(dbus_obj_on_bus);
 }
 
 /* Note that this callback will not be called until we reach the event loop,
  * after everything is initialized. That’s why we need to put our objects
- * in the dbus_obj_to_register GSList, to register them later, when we have
+ * in the dbus_obj_on_bus GSList, to register them later, when we have
  * acquired the bus.
  */
+/* The following is for the daemon. */
 static void
 on_bus_acquired(GDBusConnection *connection, const gchar *name,
                 gpointer user_data)
 {
-	GObject *obj;
-	GSList* obj_list;
-
 	purple_gdbus_connection = connection;
-	for (obj_list = dbus_obj_to_register; obj_list; obj_list = obj_list->next) {
-		obj = G_OBJECT(obj_list->data);
-		/* If we are owning the last a reference, it means we are going
-		 * to destroy it, so don’t bother registering it on DBus. */
-		if (obj->ref_count > 1)
-			purple_object_register_on_dbus(obj_list->data, connection);
-		g_object_unref(obj);
-	}
-
-	g_slist_free(dbus_obj_to_register);
+	connect_waiting_objects(connection);
 }
 
 static void
@@ -823,6 +829,21 @@
 	purple_debug_error("dbus", "Name %s lost!", name);
 }
 
+/* This part is for the clients. */
+static void
+on_client_connected(GObject *obj, GAsyncResult *res, gpointer user_data)
+{
+	GError *error;
+
+	purple_gdbus_connection = g_bus_get_finish(res, &error);
+	if (purple_gdbus_connection) {
+		connect_waiting_objects(purple_gdbus_connection);
+	} else {
+		/* TODO: Handle this properly. */
+		purple_debug_error("dbus", "Lost client connection!");
+	}
+}
+
 static void
 purple_gdbus_init(void)
 {
@@ -847,6 +868,9 @@
 		                           NULL, NULL);
 		/* TODO: handle fail of owning the name. */
 	}
+	else if(purple_core_is_remote_mode()) {
+		g_bus_get(G_BUS_TYPE_SESSION, NULL, on_client_connected, NULL);
+	}
 
 	/* In remote and daemon mode, we create our singleton objects */
 
diff --git a/libpurple/dbus-server.h b/libpurple/dbus-server.h
--- a/libpurple/dbus-server.h
+++ b/libpurple/dbus-server.h
@@ -185,7 +185,7 @@
  *
  * @param obj The object to register. Must be a subclass of PurpleObject.
  */
-void purple_dbus_register_object(gpointer object);
+void purple_dbus_connect_object(gpointer object);
 
 /**
  * Starts Purple's D-BUS server.  It is responsible for handling DBUS



More information about the Commits mailing list