[telepathy-mission-control/master] McdClientRegistry: take responsibility for ListNames etc., from McdDispatcher

Simon McVittie simon.mcvittie at collabora.co.uk
Mon Oct 19 07:01:13 PDT 2009


---
 src/client-registry.c |   97 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/mcd-dispatcher.c  |   95 ------------------------------------------------
 2 files changed, 97 insertions(+), 95 deletions(-)

diff --git a/src/client-registry.c b/src/client-registry.c
index 7dcbc37..338e457 100644
--- a/src/client-registry.c
+++ b/src/client-registry.c
@@ -241,6 +241,96 @@ _mcd_client_registry_init (McdClientRegistry *self)
 }
 
 static void
+mcd_client_registry_list_activatable_names_cb (TpDBusDaemon *proxy,
+    const gchar **names,
+    const GError *error,
+    gpointer user_data,
+    GObject *weak_object)
+{
+  McdClientRegistry *self = MCD_CLIENT_REGISTRY (weak_object);
+
+  if (error != NULL)
+    {
+      DEBUG ("ListActivatableNames returned error, assuming none: %s %d: %s",
+          g_quark_to_string (error->domain), error->code, error->message);
+    }
+  else if (names != NULL)
+    {
+      const gchar **iter = names;
+
+      DEBUG ("ListActivatableNames returned");
+
+      while (*iter != NULL)
+        {
+          _mcd_client_registry_found_name (self, *iter, NULL, TRUE);
+          iter++;
+        }
+    }
+
+  /* paired with the lock taken when the McdClientRegistry was constructed */
+  _mcd_client_registry_dec_startup_lock (self);
+}
+
+static void
+mcd_client_registry_reload_config_cb (TpDBusDaemon *proxy,
+    const GError *error,
+    gpointer user_data,
+    GObject *weak_object)
+{
+  if (error != NULL)
+    {
+      DEBUG ("ReloadConfig returned error. Recent .service files may not "
+          "be found: %s %d: %s",
+          g_quark_to_string (error->domain), error->code, error->message);
+    }
+
+  tp_cli_dbus_daemon_call_list_activatable_names (proxy, -1,
+      mcd_client_registry_list_activatable_names_cb,
+      NULL, NULL, weak_object);
+  /* deliberately not calling _mcd_client_registry_dec_startup_lock here -
+   * this function is "lock-neutral", similarly to list_names_cb (we would
+   * take a lock for ListActivatableNames then release the one used for
+   * ReloadConfig), so simplify by doing nothing */
+}
+
+static void
+mcd_client_registry_list_names_cb (TpDBusDaemon *proxy,
+    const gchar **names,
+    const GError *error,
+    gpointer user_data,
+    GObject *weak_object)
+{
+  McdClientRegistry *self = MCD_CLIENT_REGISTRY (weak_object);
+
+  if (error != NULL)
+    {
+      DEBUG ("ListNames returned error, assuming none: %s %d: %s",
+          g_quark_to_string (error->domain), error->code, error->message);
+    }
+  else if (names != NULL)
+    {
+      const gchar **iter = names;
+
+      DEBUG ("ListNames returned");
+
+      while (*iter != NULL)
+        {
+          _mcd_client_registry_found_name (self, *iter, NULL, FALSE);
+          iter++;
+        }
+    }
+
+  /* Call reload config because the dbus daemon often fails to notice newly
+   * installed .service files on its own. */
+  tp_cli_dbus_daemon_call_reload_config (proxy, -1,
+      mcd_client_registry_reload_config_cb, NULL, NULL, weak_object);
+  /* deliberately not calling _mcd_client_registry_dec_startup_lock here -
+   * this function is "lock-neutral" (we would take a lock for ReloadConfig
+   * then release the one used for ListNames), so simplify by doing
+   * nothing */
+}
+
+static void
 mcd_client_registry_constructed (GObject *object)
 {
   McdClientRegistry *self = MCD_CLIENT_REGISTRY (object);
@@ -252,6 +342,13 @@ mcd_client_registry_constructed (GObject *object)
 
   g_return_if_fail (self->priv->dbus_daemon != NULL);
 
+  /* FIXME: strictly speaking, we should connect to NameOwnerChanged
+   * *before* calling ListNames. This will be fixed when the NameOwnerChanged
+   * handling moves here too. */
+
+  tp_cli_dbus_daemon_call_list_names (self->priv->dbus_daemon, -1,
+      mcd_client_registry_list_names_cb, NULL, NULL, object);
+
   /* Dummy handle type, we're just using this as a string pool */
   self->priv->string_pool = tp_dynamic_handle_repo_new (TP_HANDLE_TYPE_CONTACT,
       NULL, NULL);
diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index 25b694f..48e32eb 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -1872,98 +1872,6 @@ mcd_dispatcher_update_client_caps (McdDispatcher *self,
 }
 
 static void
-list_activatable_names_cb (TpDBusDaemon *proxy,
-    const gchar **names,
-    const GError *error,
-    gpointer user_data,
-    GObject *weak_object)
-{
-    McdDispatcher *self = MCD_DISPATCHER (weak_object);
-
-    if (error != NULL)
-    {
-        DEBUG ("ListActivatableNames returned error, assuming none: %s %d: %s",
-               g_quark_to_string (error->domain), error->code, error->message);
-    }
-    else if (names != NULL)
-    {
-        const gchar **iter = names;
-
-        DEBUG ("ListActivatableNames returned");
-
-        while (*iter != NULL)
-        {
-            _mcd_client_registry_found_name (self->priv->clients,
-                                             *iter, NULL, TRUE);
-            iter++;
-        }
-    }
-
-    /* paired with the lock taken when the McdClientRegistry was constructed */
-    _mcd_client_registry_dec_startup_lock (self->priv->clients);
-}
-
-static void
-reload_config_cb (TpDBusDaemon *proxy,
-    const GError *error,
-    gpointer user_data,
-    GObject *weak_object)
-{
-    McdDispatcher *self = MCD_DISPATCHER (weak_object);
-
-    if (error != NULL)
-    {
-        DEBUG ("ReloadConfig returned error. Recent .service files may not be found: %s %d: %s",
-               g_quark_to_string (error->domain), error->code, error->message);
-    }
-
-    tp_cli_dbus_daemon_call_list_activatable_names (self->priv->dbus_daemon,
-        -1, list_activatable_names_cb, NULL, NULL, weak_object);
-    /* deliberately not calling _mcd_client_registry_dec_startup_lock here -
-     * this function is "lock-neutral", similarly to list_names_cb (we would
-     * take a lock for ListActivatableNames then release the one used for
-     * ReloadConfig), so simplify by doing nothing */
-}
-
-static void
-list_names_cb (TpDBusDaemon *proxy,
-    const gchar **names,
-    const GError *error,
-    gpointer user_data,
-    GObject *weak_object)
-{
-    McdDispatcher *self = MCD_DISPATCHER (weak_object);
-
-    if (error != NULL)
-    {
-        DEBUG ("ListNames returned error, assuming none: %s %d: %s",
-               g_quark_to_string (error->domain), error->code, error->message);
-    }
-    else if (names != NULL)
-    {
-        const gchar **iter = names;
-
-        DEBUG ("ListNames returned");
-
-        while (*iter != NULL)
-        {
-            _mcd_client_registry_found_name (self->priv->clients,
-                                             *iter, NULL, FALSE);
-            iter++;
-        }
-    }
-
-    /* Call reload config because the dbus daemon often fails to notice newly
-     * installed .service files on its own. */
-    tp_cli_dbus_daemon_call_reload_config (self->priv->dbus_daemon, -1,
-        reload_config_cb, NULL, NULL, weak_object);
-    /* deliberately not calling _mcd_client_registry_dec_startup_lock here -
-     * this function is "lock-neutral" (we would take a lock for ReloadConfig
-     * then release the one used for ListNames), so simplify by doing
-     * nothing */
-}
-
-static void
 name_owner_changed_cb (TpDBusDaemon *proxy,
     const gchar *name,
     const gchar *old_owner,
@@ -2029,9 +1937,6 @@ mcd_dispatcher_constructed (GObject *object)
     tp_cli_dbus_daemon_connect_to_name_owner_changed (priv->dbus_daemon,
         name_owner_changed_cb, NULL, NULL, object, NULL);
 
-    tp_cli_dbus_daemon_call_list_names (priv->dbus_daemon,
-        -1, list_names_cb, NULL, NULL, object);
-
     dgc = TP_PROXY (priv->dbus_daemon)->dbus_connection;
 
     if (!tp_dbus_daemon_request_name (priv->dbus_daemon,
-- 
1.5.6.5




More information about the telepathy-commits mailing list