/srv/mercurial-server/detachablepurple: f162d35b129a: Client sid...

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


Changeset: f162d35b129a78eadbb514f9146571455c437ebc
Author:	 Gilles Bedel <gillux at cpw.pidgin.im>
Date:	 2012-03-27 20:16 +0000
Branch:	 cpw.gillux.detachablepurple
URL: http://hg.pidgin.im/srv/mercurial-server/detachablepurple/rev/f162d35b129a

Description:

Client side object connection will use the same callback function
pointer as on the daemon side, thus renamed to "on_dbus_connected"
instead of "dbus_register". D-Bus signal handlers will also use the
same callbacks pool as the methods on the daemon side (a GData with
callback names as key), thus renamed to "dbus_callbacks" instead of
"dbus_methods". A few functions were also renamed to match these
conceptual changes.

diffstat:

 libpurple/dbus-server.c  |   2 +-
 libpurple/dbus-server.h  |   2 +-
 libpurple/dbus/account.c |  17 +++++------
 libpurple/pobject.c      |  38 ++++++++++++++-------------
 libpurple/pobject.h      |  65 +++++++++++++++++++++++++----------------------
 5 files changed, 64 insertions(+), 60 deletions(-)

diffs (truncated from 304 to 300 lines):

diff --git a/libpurple/dbus-server.c b/libpurple/dbus-server.c
--- a/libpurple/dbus-server.c
+++ b/libpurple/dbus-server.c
@@ -785,7 +785,7 @@
 purple_dbus_connect_object(gpointer object)
 {
 	if (purple_gdbus_connection)
-		purple_object_register_on_dbus(object, purple_gdbus_connection);
+		purple_object_dbus_connect(object, purple_gdbus_connection);
 	else
 		dbus_obj_on_bus = g_slist_append(dbus_obj_on_bus, g_object_ref(object));
 }
diff --git a/libpurple/dbus-server.h b/libpurple/dbus-server.h
--- a/libpurple/dbus-server.h
+++ b/libpurple/dbus-server.h
@@ -180,7 +180,7 @@
 
 /**
  * "Busless" function to register a PurpleObject on DBus.
- * If the bus is acquired, it calls the ->dbus_register() operation.
+ * If the bus is acquired, it calls the ->on_dbus_connected() operation.
  * Otherwise, it will do it when the bus is acquired.
  *
  * @param obj The object to register. Must be a subclass of PurpleObject.
diff --git a/libpurple/dbus/account.c b/libpurple/dbus/account.c
--- a/libpurple/dbus/account.c
+++ b/libpurple/dbus/account.c
@@ -163,12 +163,12 @@
 	PurpleObjectClass *pobjclass = PURPLE_OBJECT_CLASS(klass);
 	if (purple_core_is_daemon_mode()) {
 		pobjclass->dbus_ifaceinfo = &purple_account_interface_info;
-		purple_object_bind_dbus_method(pobjclass, "Connect",
-		                               (GCallback)purple_account_connect);
-		purple_object_bind_dbus_method(pobjclass, "Disconnect",
-		                               (GCallback)purple_account_disconnect);
-		purple_object_bind_dbus_method(pobjclass, "Register",
-		                               (GCallback)purple_account_register);
+		purple_object_bind_dbus_callback(pobjclass, "Connect",
+		                                 (GCallback)purple_account_connect);
+		purple_object_bind_dbus_callback(pobjclass, "Disconnect",
+		                                 (GCallback)purple_account_disconnect);
+		purple_object_bind_dbus_callback(pobjclass, "Register",
+		                                 (GCallback)purple_account_register);
 /* Those are more complicated, we will handle them later.
 		purple_object_bind_dbus_method(PURPLE_OBJECT_CLASS(klass),
 		                               "Unregister",
@@ -220,13 +220,12 @@
 	char* dbus_path;
         DBusGProxy* proxy;
 
-	if (purple_core_is_daemon_mode())
-		purple_dbus_register_object(account);
-
 	dbus_path = purple_account_build_dbus_path(username, protocol_id);
 	purple_object_set_dbus_path(PURPLE_OBJECT(account), dbus_path);
 	g_free(dbus_path);	
 
+	purple_dbus_connect_object(account);
+
 	purple_object_dbus_bind_notify(PURPLE_OBJECT(account));
 
 	if (purple_core_is_remote_mode() || purple_core_is_mirror_mode()) {
diff --git a/libpurple/pobject.c b/libpurple/pobject.c
--- a/libpurple/pobject.c
+++ b/libpurple/pobject.c
@@ -39,7 +39,8 @@
 {
 	gpointer proto_data;
 	gpointer ui_data;
-	/* The gdbus id used to unregister registered objects. */
+	/* The gdbus id(s) used to unregister the registered object (in daemon
+	   context) or the registered sighandler (in client context). */
 	guint dbus_reg_id;
 	/* The dbus interface we use for purple related methods and signals,
 	 * e.g. im.pidgin.purple.account.
@@ -206,7 +207,7 @@
 
 #ifdef HAVE_DBUS
 	if (purple_core_is_daemon_mode())
-		klass->dbus_register = purple_object_generic_dbus_register;
+		klass->on_dbus_connected = purple_object_generic_dbus_register_object;
 	/* In remote mode we need to register the marshallers
 	 * we will use to receive the signals sent by the daemon */
 	if (purple_core_is_remote_mode()) {
@@ -596,22 +597,23 @@
 }
 
 void
-purple_object_bind_dbus_method(PurpleObjectClass *klass,
-                               const char *method_name,
-                               GCallback func)
+purple_object_bind_dbus_callback(PurpleObjectClass *klass,
+                                 const char *name,
+                                 GCallback func)
 {
 	GClosure* closure;
 
 	closure = g_cclosure_new(G_CALLBACK(func), NULL, NULL);
 	g_closure_set_marshal(closure, g_cclosure_marshal_generic);
-	g_datalist_set_data(&klass->dbus_methods, method_name, closure);
+	g_datalist_set_data(&klass->dbus_callbacks, name, closure);
+
 }
 
 GClosure *
 purple_object_get_dbus_closure(PurpleObjectClass *klass,
-                               const char *method_name)
+                               const char *name)
 {
-	return g_datalist_get_data(&klass->dbus_methods, method_name);
+	return g_datalist_get_data(&klass->dbus_callbacks, name);
 }
 
 void
@@ -744,7 +746,7 @@
 }
 
 guint
-purple_object_generic_dbus_register(gpointer object, GDBusConnection *dbus_conn)
+purple_object_generic_dbus_register_object(gpointer object, GDBusConnection *dbus_conn)
 {
 	PurpleObject *pobj = PURPLE_OBJECT(object);
 	GError *error = NULL;
@@ -755,12 +757,12 @@
 	  purple_object_generic_dbus_set_property };
 
 	reg_id = g_dbus_connection_register_object
-	           (dbus_conn,
-	            purple_object_get_dbus_path(pobj),
-	            PURPLE_OBJECT_GET_CLASS(pobj)->dbus_ifaceinfo,
-	            &interface_vtable,
-	            object, NULL, &error);
-	if (error) {
+	          (dbus_conn,
+	           purple_object_get_dbus_path(pobj),
+	           PURPLE_OBJECT_GET_CLASS(pobj)->dbus_ifaceinfo,
+	           &interface_vtable,
+	           object, NULL, &error);
+	if (reg_id == 0) {
 		purple_debug_error("dbus", "Failed to register a %s: %s\n",
                            G_OBJECT_TYPE_NAME(object), error->message);
 		g_error_free(error);
@@ -769,13 +771,13 @@
 }
 
 void
-purple_object_register_on_dbus(gpointer object, GDBusConnection *dbus_conn)
+purple_object_dbus_connect(gpointer object, GDBusConnection *dbus_conn)
 {
 	PurpleObjectClass *pclass = PURPLE_OBJECT_GET_CLASS(object);
 	guint reg_id;
 
-	if (pclass->dbus_register) {
-		reg_id = pclass->dbus_register(object, dbus_conn);
+	if (pclass->on_dbus_connected) {
+		reg_id = pclass->on_dbus_connected(object, dbus_conn);
 		purple_object_set_dbus_reg_id(PURPLE_OBJECT(object), reg_id);
 	}
 }
diff --git a/libpurple/pobject.h b/libpurple/pobject.h
--- a/libpurple/pobject.h
+++ b/libpurple/pobject.h
@@ -49,10 +49,14 @@
 {
 	GObjectClass gparent;
 #ifdef HAVE_DBUS
-	/* A function that should register the object on DBus. */
-	guint (*dbus_register)(gpointer object, GDBusConnection *connection);
-	/* A data set of DBus methods name as keys and GClosures as values. */
-	GData *dbus_methods;
+	/* A function called when the DBus connection is acquiered. Usually,
+           in deamon context the object should register itself on the bus,
+           whereas on client context it should put DBus signals handlers.
+	   Returns the registration or subscription id provided by GDbus/ */
+	guint (*on_dbus_connected)(gpointer object, GDBusConnection *connection);
+	/* A data set of DBus methods (in daemon context) or signals (in client
+	   context) names as keys and GClosures as values. */
+	GData *dbus_callbacks;
 	/* The C structure based representation of the XML DBus interface. */
 	GDBusInterfaceInfo *dbus_ifaceinfo;
 	void (*_purple_reserved[1])(void);
@@ -184,24 +188,23 @@
 void purple_object_set_dbus_path(PurpleObject *pobj, char* path);
 
 /**
- * Associates the function func with the DBus method named method_name.
- * If the default generic dbus handlers are in place, a call to the method
- * named method_name will result in the call of the function func, with the
- * parameters as described in the dbus_ifaceinfo field of the class (which is
+ * Binds the function func with the D-Bus method (in daemon context) or
+ * D-Bus signal (in client context) named name. The parameters of the method
+ * or sighandler will be as in the dbus_ifaceinfo field of the class (which is
  * a C structure based representation of the DBus XML interface). The given
  * PurpleObjectClass klass must be the super-class the class intended to
- * provide the method, e.g. the super-class of PurpleAccountClass.
+ * provide the method or signal, e.g. the super-class of PurpleAccountClass.
  * This function internally stores func in a GClosure and adds it to the
- * dbus_methods data set, in klass.
+ * dbus_callbacks data set, in klass.
  *
- * @param klass The super-class of the class providing method_name.
- * @param method_name The name of the method on DBus.
- * @param func The function called when one calls method_name on DBus.
+ * @param klass The super-class of the class providing the method or signal.
+ * @param name The name of the method or signal on DBus.
+ * @param func The function called when one calls the method or receive the signal on D-Bus.
  *
  */
-void purple_object_bind_dbus_method(PurpleObjectClass *klass,
-                                    const char        *method_name,
-                                    GCallback          func);
+void purple_object_bind_dbus_callback(PurpleObjectClass *klass,
+                                      const char        *name,
+                                      GCallback          func);
 
 /**
  * Makes the relevant object properties changes to be transmitted over DBus.
@@ -216,14 +219,14 @@
 
 /**
  * Gets the GClosure created to handle the call of the DBus method
- * named method_name.
+ * (in dameon context) or signal handler (in client context) named name.
  *
- * @param klass The super-class of the class providing method_name.
- * @param method_name The name of the method on DBus.
- * @see purple_object_bind_dbus_method
+ * @param klass The super-class of the class handling name.
+ * @param name The name of the method or signal on DBus.
+ * @see purple_object_bind_dbus_callback
  */
 GClosure *purple_object_get_dbus_closure(PurpleObjectClass *klass,
-                                         const char        *method_name);
+                                         const char        *name);
 
 /**
  * A GDBusInterfaceMethodCallFunc compilant DBus method handler.
@@ -233,7 +236,7 @@
  * It may be used e.g. along with non-default properties handlers
  * in an interface virtual table, for very special DBus methods.
  * 
- * @see purple_object_generic_dbus_register
+ * @see purple_object_generic_dbus_register_object
  * @see purple_object_generic_dbus_get_property
  * @see purple_object_generic_dbus_set_property
  */
@@ -250,11 +253,11 @@
  * A GDBusInterfaceMethodCallFunc compilant DBus property getter.
  * This property getter aims to be set in a GDBusInterfaceVTable.
  * In fact, it is the default property getter, set by the default
- * DBus object register purple_object_generic_dbus_register().
+ * DBus object register purple_object_generic_dbus_register_object().
  * It may be used e.g. along with a non-default method handler
  * in an interface virtual table, for very special DBus properties.
  * 
- * @see purple_object_generic_dbus_register
+ * @see purple_object_generic_dbus_register_object
  * @see purple_object_generic_dbus_method_handler
  * @see purple_object_generic_dbus_set_property
  */
@@ -270,11 +273,11 @@
  * A GDBusInterfaceMethodCallFunc compilant DBus property setter.
  * This property setter aims to be set in a GDBusInterfaceVTable.
  * In fact, it is the default property setter, set by the default
- * DBus object register purple_object_generic_dbus_register().
+ * DBus object register purple_object_generic_dbus_register_object().
  * It may be used e.g. along with a non-default method handler
  * in an interface virtual table, for very special DBus properties.
  * 
- * @see purple_object_generic_dbus_register
+ * @see purple_object_generic_dbus_register_object
  * @see purple_object_generic_dbus_method_handler
  * @see purple_object_generic_dbus_get_property
  */
@@ -291,7 +294,7 @@
  * Registers an object on DBus, with the default method and properties
  * handlers, using the dbus_ifaceinfo class field as interface informations,
  * and using the dbus_path object field as DBus object name. This function aims
- * to be set as the dbus_register field of a class. Actually, it is already set
+ * to be set as the on_dbus_connected field of a class. Actually, it is already set
  * so by default in PurpleObjectClass. So unless you have to perform specific
  * stuff on the registration, like using your own interface virtual table, you
  * shouldn’t care about it.
@@ -300,16 +303,16 @@
  * @param dbus_conn The GDBus handle.
  * @return The registration id returned by g_dbus_connection_register_object().
  */
-guint purple_object_generic_dbus_register(gpointer object, GDBusConnection *dbus_conn);
+guint purple_object_generic_dbus_register_object(gpointer object, GDBusConnection *dbus_conn);
 
 /**
- * Calls the dbus_register function pointer on the class of object, and keeps
- * the registration id.
+ * Calls the on_dbus_connected function pointer on the class of object,
+ * and keeps the registration id.
  *
  * @param object An object derived from PurpleObject.
  * @param dbus_conn The GDBus handle.
  */
-void purple_object_register_on_dbus(gpointer object, GDBusConnection *dbus_conn);



More information about the Commits mailing list