cpw.gillux.detachablepurple: f1177849: Client side object connection will use t...

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


----------------------------------------------------------------------
Revision: f117784967ff2fe2570a336f37396b12dfd6711f
Parent:   18431e0e6bf8c84777773b936f68e6e4d453945b
Author:   gillux at soc.pidgin.im
Date:     03/27/12 16:16:30
Branch:   im.pidgin.cpw.gillux.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/f117784967ff2fe2570a336f37396b12dfd6711f

Changelog: 

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.

Changes against parent 18431e0e6bf8c84777773b936f68e6e4d453945b

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

-------------- next part --------------
============================================================
--- libpurple/dbus-server.c	bceecf5ae9c3991deba539afe6253a90e669998d
+++ libpurple/dbus-server.c	0168f367b22b5bff105889e0a983839bad2dc9b2
@@ -785,7 +785,7 @@ purple_dbus_connect_object(gpointer obje
 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));
 }
============================================================
--- libpurple/dbus-server.h	957b21679ed90000c1e6840d6bf9d1f11879b5ec
+++ libpurple/dbus-server.h	bc04e475a95646522146433c370fa647a231b343
@@ -180,7 +180,7 @@ gboolean purple_dbus_is_owner(void);
 
 /**
  * "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.
============================================================
--- libpurple/pobject.c	f60b53eaef7fba2435bd1a45b7380ca229fa6854
+++ libpurple/pobject.c	5954781190a6a7dfc2d3fb18a4fa39b02a2ea12e
@@ -39,7 +39,8 @@ struct _PurpleObjectPrivate
 {
 	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 @@ purple_object_class_init(PurpleObjectCla
 
 #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
 }
 
 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
 }
 
 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_register(gpoi
 	  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
 }
 
 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);
 	}
 }
============================================================
--- libpurple/pobject.h	71f1962d0d117982b283bf7385b563ed7b567c6b
+++ libpurple/pobject.h	b0abc4b5af366f9308635b689022ae1679f54b82
@@ -49,10 +49,14 @@ struct _PurpleObjectClass
 {
 	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(PurpleO
 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 @@ void purple_object_dbus_bind_notify(Purp
 
 /**
  * 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 @@ GClosure *purple_object_get_dbus_closure
  * 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 @@ void purple_object_generic_dbus_method_h
  * 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 @@ GVariant *purple_object_generic_dbus_get
  * 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 @@ gboolean purple_object_generic_dbus_set_
  * 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 @@ gboolean purple_object_generic_dbus_set_
  * @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);
+void purple_object_dbus_connect(gpointer object, GDBusConnection *dbus_conn);
 
 
 #endif /* HAVE_DBUS */
============================================================
--- libpurple/dbus/account.c	4ab02c910d51b65df459e5a688b5c013c6360ac7
+++ libpurple/dbus/account.c	0be4ad0224369872ba2209f06fdf16142336f63b
@@ -163,12 +163,12 @@ purple_account_class_dbus_init(PurpleAcc
 	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 @@ purple_account_dbus_init(PurpleAccount *
 	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()) {


More information about the Commits mailing list