cpw.gillux.detachablepurple: 18431e0e: Mostly renamed the dbus "object registra...

gillux at soc.pidgin.im gillux at soc.pidgin.im
Tue Mar 27 17:25:52 EDT 2012


----------------------------------------------------------------------
Revision: 18431e0e6bf8c84777773b936f68e6e4d453945b
Parent:   b5cd4d96e89d8b29bbbf29186651f77f6df59489
Author:   gillux at soc.pidgin.im
Date:     03/27/12 11:24:52
Branch:   im.pidgin.cpw.gillux.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/18431e0e6bf8c84777773b936f68e6e4d453945b

Changelog: 

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.

Changes against parent b5cd4d96e89d8b29bbbf29186651f77f6df59489

  patched  libpurple/dbus-server.c
  patched  libpurple/dbus-server.h

-------------- next part --------------
============================================================
--- libpurple/dbus-server.c	e0bf81855f0987841f234719a7474ba1f17a32bb
+++ libpurple/dbus-server.c	bceecf5ae9c3991deba539afe6253a90e669998d
@@ -88,13 +88,13 @@ static GHashTable *map_id_type;
 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,48 +782,69 @@ void
 }
 
 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));
 }
 
-/* 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
- * acquired the bus.
- */
 static void
-on_bus_acquired(GDBusConnection *connection, const gchar *name,
-                gpointer user_data)
+connect_waiting_objects(GDBusConnection *connection)
 {
 	GObject *obj;
 	GSList* obj_list;
 
-	purple_gdbus_connection = connection;
-	for (obj_list = dbus_obj_to_register; obj_list; obj_list = obj_list->next) {
+	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_register_on_dbus(obj_list->data, connection);
+			purple_object_dbus_connect(obj_list->data, connection);
 		g_object_unref(obj);
 	}
 
-	g_slist_free(dbus_obj_to_register);
+	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_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)
+{
+	purple_gdbus_connection = connection;
+	connect_waiting_objects(connection);
+}
+
+static void
 on_name_lost(GDBusConnection *connection, const gchar *name, gpointer user_data)
 {
 	/* TODO: Handle this properly. */
 	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)
 {
 	guint owner_id;
@@ -847,6 +868,9 @@ purple_gdbus_init(void)
 		                           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 */
 
============================================================
--- libpurple/dbus-server.h	fdc85e47a83c0d3688979bee43480d04f33c2e9b
+++ libpurple/dbus-server.h	957b21679ed90000c1e6840d6bf9d1f11879b5ec
@@ -185,7 +185,7 @@ gboolean purple_dbus_is_owner(void);
  *
  * @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