[gconf/gdbus] Fix listening to the org.gnome.GConf.Defaults service



commit 94bbf1812eb6a1b1843f9b199c92900db66041e9
Author: Christian Persch <chpe gnome org>
Date:   Thu May 13 15:18:22 2010 +0200

    Fix listening to the org.gnome.GConf.Defaults service

 gconf/gconfd.c |   82 +++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 61 insertions(+), 21 deletions(-)
---
diff --git a/gconf/gconfd.c b/gconf/gconfd.c
index bf68592..83e5c2a 100644
--- a/gconf/gconfd.c
+++ b/gconf/gconfd.c
@@ -604,6 +604,11 @@ own_org_gnome_GConf (void)
 #ifdef ENABLE_DEFAULTS_SERVICE
 /* listen on system bus for defaults changes */
 
+typedef struct {
+  guint watch_id;
+  guint subscription_id;
+} DefaultsData;
+
 static void
 system_set_cb (GDBusConnection *connection,
                const gchar *sender_name,
@@ -613,7 +618,7 @@ system_set_cb (GDBusConnection *connection,
                GVariant *parameters,
                gpointer user_data)
 {
-  if (g_strcmp0 (sender_name, "org.gnome.GConf.Defaults") == 0 &&
+  if (g_strcmp0 (interface_name, "org.gnome.GConf.Defaults") == 0 &&
       g_strcmp0 (signal_name, "SystemSet") == 0)
     {
       if (g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(as)")))
@@ -646,28 +651,56 @@ system_set_cb (GDBusConnection *connection,
     }
 }
 
-static guint
+static void
+defaults_appeared_cb (GDBusConnection *connection,
+                      const gchar     *name,
+                      const gchar     *name_owner,
+                      gpointer         user_data)
+{
+  DefaultsData *data = (DefaultsData *) user_data;
+
+  gconf_log (GCL_DEBUG, "Defaults service appeared with name '%s'", name_owner);
+
+  g_assert (data->subscription_id == 0);
+  data->subscription_id = g_dbus_connection_signal_subscribe (connection,
+                                                              name_owner,
+                                                              "org.gnome.GConf.Defaults",
+                                                              "SystemSet",
+                                                              "/" /* really? */,
+                                                              NULL,
+                                                              system_set_cb,
+                                                              user_data, NULL);
+}
+
+static void
+defaults_vanished_cb (GDBusConnection *connection,
+                      const gchar     *name,
+                      gpointer         user_data)
+{
+  DefaultsData *data = (DefaultsData *) user_data;
+
+  gconf_log (GCL_DEBUG, "Defaults service disappeared");
+
+  if (data->subscription_id != 0) {
+    g_dbus_connection_signal_unsubscribe (connection , data->subscription_id);
+    data->subscription_id = 0;
+  }
+}
+
+static DefaultsData *
 get_on_system_bus (void)
 {
-  GDBusConnection *connection;
-  GError *error = NULL;
+  DefaultsData *data = g_new (DefaultsData, 1);
 
-  connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
-  if (connection == NULL)
-    {
-      gconf_log (GCL_ERR, _("Could not connect to system bus: %s"), error->message);
-      g_error_free (error);
-      return 0;
-    }
-    
-  return g_dbus_connection_signal_subscribe (connection,
-                                             NULL /* FIXME? */,
-                                             "org.gnome.GConf.Defaults",
-                                             "SystemSet",
-                                             "/" /* really? */,
-                                             NULL,
-                                             system_set_cb,
-                                             NULL, NULL);
+  data->subscription_id = 0;
+  data->watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
+                                     "org.gnome.GConf.Defaults",
+                                     G_BUS_NAME_WATCHER_FLAGS_NONE,
+                                     defaults_appeared_cb,
+                                     defaults_vanished_cb,
+                                     data, NULL);
+
+  return data;
 }
 #endif  /* ENABLE_DEFAULTS_SERVICE */
 
@@ -700,6 +733,7 @@ main(int argc, char** argv)
   int dev_null_fd;
   int write_byte_fd;
   GDBusConnection *connection;
+  DefaultsData *defaults_data;
 
   _gconf_init_i18n ();
   setlocale (LC_ALL, "");
@@ -873,7 +907,7 @@ main(int argc, char** argv)
   logfile_read ();
  
 #ifdef ENABLE_DEFAULTS_SERVICE 
-  get_on_system_bus ();
+  defaults_data = get_on_system_bus ();
 #endif
 
   gconf_main ();
@@ -881,6 +915,12 @@ main(int argc, char** argv)
   g_object_unref (connection);
   connection = NULL;
 
+  if (defaults_data->subscription_id != 0) {
+    g_dbus_connection_signal_unsubscribe (connection , defaults_data->subscription_id);
+  }
+  g_bus_unwatch_name (defaults_data->watch_id);
+  g_free (defaults_data);
+
   if (in_shutdown)
     exit_code = 1; /* means someone already called enter_shutdown() */
   



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