soc.2010.detachablepurple: b5d57c23: Added a "dbus path name -> gobject" hash...
gillux at soc.pidgin.im
gillux at soc.pidgin.im
Sat Jul 17 10:38:13 EDT 2010
----------------------------------------------------------------------
Revision: b5d57c238c9e8ba5c9ef084e6e9e251bb6539177
Parent: 9b9bbe0ae57a480103e675ad27752ef6e137592a
Author: gillux at soc.pidgin.im
Date: 07/17/10 10:10:15
Branch: im.pidgin.soc.2010.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/b5d57c238c9e8ba5c9ef084e6e9e251bb6539177
Changelog:
Added a "dbus path name -> gobject" hash table, so that on the client side we
know which dbus remote object our local objects are the mirror of. This will
be needed by the dbus signal handlers on the clients; signals only comes with
the dbus path name they originate from, and it's only up to us to have local
copies of these objects.
Changes against parent 9b9bbe0ae57a480103e675ad27752ef6e137592a
patched libpurple/dbus-server.c
patched libpurple/dbus-server.h
patched libpurple/pobject.c
patched libpurple/pobject.h
-------------- next part --------------
============================================================
--- libpurple/dbus-server.c 0040b3f2484f13cd2a816f9a84b617c9e8f9732d
+++ libpurple/dbus-server.c da2ac7dc86cbbe7156ac25f65c639c0bca278db3
@@ -71,6 +71,16 @@
* pointers (nodes) and the corresponding handles (ids).
*/
+/**
+ * A "dbus path name -> gobject" hash table. Used in remote mode context only.
+ *
+ * Each local gobject is a kind of mirror if a remote object on the daemon.
+ * These remote objects are identified by dbus path names. When we receive a
+ * dbus signal, it is associated with a dbus path, and we need to know what is
+ * the matching local object.
+ */
+static GHashTable *dbus_path_gobjects;
+
static GHashTable *map_node_id;
static GHashTable *map_id_node;
static GHashTable *map_id_type;
@@ -481,6 +491,33 @@ purple_dbus_sanitize_dbus_path(const gch
return path_valid;
}
+void
+purple_dbus_assoc_gobject(const gchar *dbus_path, GObject *gobj)
+{
+ g_return_if_fail(dbus_path_gobjects != NULL);
+ g_return_if_fail(dbus_path != NULL);
+
+ g_hash_table_insert(dbus_path_gobjects, g_strdup(dbus_path), gobj);
+}
+
+void
+purple_dbus_disassoc_gobject(const gchar *dbus_path)
+{
+ g_return_if_fail(dbus_path_gobjects != NULL);
+ g_return_if_fail(dbus_path != NULL);
+
+ g_hash_table_remove(dbus_path_gobjects, dbus_path);
+}
+
+GObject*
+purple_dbus_get_gobject_by_path(const gchar *dbus_path)
+{
+ g_return_val_if_fail(dbus_path_gobjects != NULL, NULL);
+ g_return_val_if_fail(dbus_path != NULL, NULL);
+
+ return g_hash_table_lookup(dbus_path_gobjects, dbus_path);
+}
+
/**************************************************************/
/* DBus bindings ... */
/**************************************************************/
@@ -740,11 +777,18 @@ purple_dbus_g_init(void)
GError *error = NULL;
guint request_ret;
- /* Export our objects only if we are in normal mode. */
- if (purple_core_is_remote_mode())
+ if (purple_core_is_remote_mode()) {
+ /* We also use the "dbus path name -> gobject" hash table */
+ dbus_path_gobjects = g_hash_table_new_full(g_str_hash, g_str_equal,
+ g_free, NULL);
return;
- /*
- * Create a proxy for the purple service, so we can
+ }
+
+ /* Export our objects only if we are in daemon mode. */
+ if (!purple_core_is_daemon_mode())
+ return;
+
+ /* In daemon mode create a proxy for the purple service, so we can
* publish our gobjects on DBus.
*/
dbus_proxy = dbus_g_proxy_new_for_name(purple_dbus_get_g_connection(),
@@ -959,6 +1003,12 @@ purple_dbus_init(void)
purple_dbus_g_init();
}
+static void
+purple_dbus_g_uninit(void)
+{
+ g_hash_table_destroy(dbus_path_gobjects);
+}
+
void
purple_dbus_uninit(void)
{
@@ -975,5 +1025,6 @@ purple_dbus_uninit(void)
purple_signals_disconnect_by_handle(purple_dbus_get_handle());
g_free(init_error);
init_error = NULL;
-}
+ purple_dbus_g_uninit();
+}
============================================================
--- libpurple/dbus-server.h b21f17e59e986acebee1b146d9499eda91ed9e58
+++ libpurple/dbus-server.h 0acd9de4c5ab4abeb23e019ae0d2b11de7a3fa41
@@ -215,7 +215,31 @@ gchar* purple_dbus_sanitize_dbus_path(co
gchar* purple_dbus_sanitize_dbus_path(const gchar *str);
/**
+ * Associates a local GObject with its matching remote dbus path.
+ *
+ * @param dbus_path The dbus path name.
+ * @param dbus_path The GObject.
+ */
+void purple_dbus_assoc_gobject(const gchar *dbus_path, GObject *gobj);
+/**
+ * Disassociates a local GObject with its matching remote dbus path.
+ *
+ * @param dbus_path The dbus path name.
+ * @param dbus_path The GObject.
+ */
+void purple_dbus_disassoc_gobject(const gchar *dbus_path);
+
+/**
+ * Get the local GObject associated with the given dbus path.
+ *
+ * @param dbus_path The dbus path name.
+ * @return The local GObject.
+ */
+GObject* purple_dbus_get_gobject_by_path(const gchar *dbus_path);
+
+/**
+
Macro #DBUS_EXPORT expands to nothing. It is used to indicate to the
dbus-analyze-functions.py script that the given function should be
available to other applications through DBUS. If
============================================================
--- libpurple/pobject.c 7d5c5928220e28d8a598cebd84699fcf5a7c7db2
+++ libpurple/pobject.c 739d68f1dc9151b6bfd0e63c57ff81431adeca58
@@ -75,6 +75,9 @@ purple_object_dispose(GObject *obj)
g_signal_emit(pobj, signals[SIG_DESTROYING], 0);
+ /* Forget about the associated dbus path */
+ purple_dbus_disassoc_gobject(priv->dbus_path);
+
if (priv->proto_data) {
g_warning("Purple-Object: object destroyed without unsetting the protocol data. This may lead to memory leak.\n");
}
@@ -292,6 +295,9 @@ purple_object_install_dbus_infos(PurpleO
/* Remember the purple interface */
purple_object_set_dbus_obj_interface(pobj, dbus_interface);
+
+ /* Remember what local gobject this object is a mirror of. */
+ purple_dbus_assoc_gobject(dbus_path, G_OBJECT(pobj));
}
else if (purple_core_is_daemon_mode()) {
/* Register our object as at dbus_path */
============================================================
--- libpurple/pobject.h b912158bc42b63336d4eb42cde78a4a9f3a0a3c3
+++ libpurple/pobject.h 361dcab847cecc98355bee35da0642e864367128
@@ -95,6 +95,18 @@ void purple_object_set_dbus_obj_interfac
*/
void purple_object_set_dbus_obj_interface(PurpleObject *pobj, char* interface);
+/**
+ * Checks whether we export a given property on the given dbus interface.
+ *
+ * @param pobj The PurpleObject which may hold the property.
+ * @param interface The interface the property belongs to.
+ * @param prop_name The name of the property to check.
+ *
+ * @return TRUE if we export the property on dbus, FALSE otherwise.
+ */
+gboolean purple_object_have_dbus_property(PurpleObject *pobj, const gchar *interface, const gchar *prop_name);
+
+
#ifdef HAVE_DBUS
/**
More information about the Commits
mailing list