[gconf] gconf-dbus: Emit a Bye dbus signal when dropping a database



commit dc7e44d0a7a9f34d491ce4629c89cb4b37b7bcca
Author: Vincent Untz <vuntz gnome org>
Date:   Mon Oct 17 20:02:16 2011 +0200

    gconf-dbus: Emit a Bye dbus signal when dropping a database
    
    This enables clients to know the database got dropped, and to stop
    referencing the object path of this database. The clients will
    eventually cause the re-creation of this database when they'll need it.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=659835

 gconf/gconf-database-dbus.c |    1 +
 gconf/gconf-dbus-utils.h    |    1 +
 gconf/gconf-dbus.c          |   42 ++++++++++++++++++++++++++++++++++++++++++
 gconf/gconfd-dbus.c         |   16 ++++++++++++++++
 gconf/gconfd-dbus.h         |    2 ++
 5 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/gconf/gconf-database-dbus.c b/gconf/gconf-database-dbus.c
index ea3b553..1ba705b 100644
--- a/gconf/gconf-database-dbus.c
+++ b/gconf/gconf-database-dbus.c
@@ -873,6 +873,7 @@ gconf_database_dbus_teardown (GConfDatabase *db)
 
   conn = gconfd_dbus_get_connection ();
 
+  gconfd_emit_db_gone (db->object_path);
   dbus_connection_unregister_object_path (conn, db->object_path);
   
   dbus_connection_remove_filter (conn,
diff --git a/gconf/gconf-dbus-utils.h b/gconf/gconf-dbus-utils.h
index deeab87..8d16a51 100644
--- a/gconf/gconf-dbus-utils.h
+++ b/gconf/gconf-dbus-utils.h
@@ -35,6 +35,7 @@
 #define GCONF_DBUS_SERVER_GET_DEFAULT_DB    "GetDefaultDatabase"
 #define GCONF_DBUS_SERVER_GET_DB            "GetDatabase"
 #define GCONF_DBUS_SERVER_SHUTDOWN          "Shutdown"
+#define GCONF_DBUS_SERVER_BYE_SIGNAL        "Bye"
 
 #define GCONF_DBUS_DATABASE_LOOKUP          "Lookup"
 #define GCONF_DBUS_DATABASE_LOOKUP_EXTENDED "LookupExtended" 
diff --git a/gconf/gconf-dbus.c b/gconf/gconf-dbus.c
index 335bc22..8845ed9 100644
--- a/gconf/gconf-dbus.c
+++ b/gconf/gconf-dbus.c
@@ -46,6 +46,8 @@
     "type='method_call',interface='org.gnome.GConf.Database',member='Notify'"
 #define DAEMON_DISCONNECTED_RULE \
     "type='signal',member='Disconnected'"
+#define BYE_RULE \
+    "type='signal',interface='org.gnome.GConf.Server',member='Bye'"
 
 struct _GConfEngine {
   guint refcount;
@@ -416,6 +418,7 @@ ensure_dbus_connection (void)
 
   dbus_bus_add_match (global_conn, DAEMON_NAME_OWNER_CHANGED_RULE, NULL);
   dbus_bus_add_match (global_conn, NOTIFY_RULE, NULL);
+  dbus_bus_add_match (global_conn, BYE_RULE, NULL);
   dbus_bus_add_match (global_conn, DAEMON_DISCONNECTED_RULE, NULL);
 
   dbus_connection_add_filter (global_conn, gconf_dbus_message_filter,
@@ -2314,6 +2317,45 @@ gconf_dbus_message_filter (DBusConnection    *dbus_conn,
       
       return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;      
     }
+  else if (dbus_message_is_signal (message,
+				   GCONF_DBUS_SERVER_INTERFACE,
+				   "Bye"))
+    {
+      char *db;
+      GConfEngine *conf;
+
+      dbus_message_get_args (message,
+			     NULL,
+			     DBUS_TYPE_OBJECT_PATH, &db,
+			     DBUS_TYPE_INVALID);
+
+      conf = lookup_engine_by_database (db);
+      if (conf != NULL)
+        {
+	  g_hash_table_remove (engines_by_db, db);
+
+	  if (g_hash_table_size (conf->notify_ids) > 0)
+	    {
+	      GList *cnxns, *l;
+
+	      cnxns = NULL;
+	      g_hash_table_foreach (conf->notify_ids,
+				    cnxn_get_all_func,
+				    &cnxns);
+
+	      for (l = cnxns; l; l = l->next)
+		{
+		  GConfCnxn *cnxn = l->data;
+
+		  send_notify_add (conf, cnxn, NULL);
+		}
+
+	      g_list_free (cnxns);
+	    }
+        }
+
+      return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+    }
 
   return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 } 
diff --git a/gconf/gconfd-dbus.c b/gconf/gconfd-dbus.c
index 6f42ef5..ed2f3ca 100644
--- a/gconf/gconfd-dbus.c
+++ b/gconf/gconfd-dbus.c
@@ -390,3 +390,19 @@ gconfd_dbus_get_connection (void)
   return bus_conn;
 }
 
+void
+gconfd_emit_db_gone (const char *object_path)
+{
+  DBusMessage *signal;
+
+  signal = dbus_message_new_signal (server_path,
+				    GCONF_DBUS_SERVER_INTERFACE,
+				    GCONF_DBUS_SERVER_BYE_SIGNAL);
+
+  dbus_message_append_args (signal,
+			    DBUS_TYPE_OBJECT_PATH, &object_path,
+			    DBUS_TYPE_INVALID);
+
+  dbus_connection_send (bus_conn, signal, NULL);
+  dbus_message_unref (signal);
+}
diff --git a/gconf/gconfd-dbus.h b/gconf/gconfd-dbus.h
index 40695ab..f2e266d 100644
--- a/gconf/gconfd-dbus.h
+++ b/gconf/gconfd-dbus.h
@@ -39,4 +39,6 @@ gboolean gconfd_dbus_check_in_shutdown        (DBusConnection *connection,
 					       DBusMessage    *message);
 DBusConnection *gconfd_dbus_get_connection    (void);
 
+void gconfd_emit_db_gone (const char *object_path);
+
 #endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]