[telepathy-mission-control/master] _mcd_client_registry_found_name: combine _mcd_client_registry_add_new with mcd_dispatcher_add_client

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


---
 src/client-registry.c |   50 +++++++++++++++++++++++++++++++++------
 src/client-registry.h |    2 +-
 src/mcd-dispatcher.c  |   62 ++++--------------------------------------------
 3 files changed, 49 insertions(+), 65 deletions(-)

diff --git a/src/client-registry.c b/src/client-registry.c
index 6328e8b..7dcbc37 100644
--- a/src/client-registry.c
+++ b/src/client-registry.c
@@ -21,6 +21,7 @@
 
 #include "client-registry.h"
 
+#include <telepathy-glib/defs.h>
 #include <telepathy-glib/handle-repo-dynamic.h>
 
 #include "mcd-debug.h"
@@ -108,17 +109,52 @@ static void mcd_client_registry_ready_cb (McdClientProxy *client,
 static void mcd_client_registry_gone_cb (McdClientProxy *client,
     McdClientRegistry *self);
 
-McdClientProxy *
-_mcd_client_registry_add_new (McdClientRegistry *self,
+void
+_mcd_client_registry_found_name (McdClientRegistry *self,
     const gchar *well_known_name,
     const gchar *unique_name_if_known,
     gboolean activatable)
 {
   McdClientProxy *client;
 
-  g_return_val_if_fail (MCD_IS_CLIENT_REGISTRY (self), NULL);
-  g_return_val_if_fail (g_hash_table_lookup (self->priv->clients,
-        well_known_name) == NULL, NULL);
+  g_return_if_fail (MCD_IS_CLIENT_REGISTRY (self));
+
+  if (!g_str_has_prefix (well_known_name, TP_CLIENT_BUS_NAME_BASE))
+    {
+      /* This is not a Telepathy Client */
+      return;
+    }
+
+  if (!_mcd_client_check_valid_name (
+        well_known_name + MC_CLIENT_BUS_NAME_BASE_LEN, NULL))
+    {
+      /* This is probably meant to be a Telepathy Client, but it's not */
+      DEBUG ("Ignoring invalid Client name: %s",
+          well_known_name + MC_CLIENT_BUS_NAME_BASE_LEN);
+      return;
+    }
+
+  client = g_hash_table_lookup (self->priv->clients, well_known_name);
+
+  if (client != NULL)
+    {
+      if (activatable)
+        {
+          /* We already knew that it was active, but now we also know that
+           * it is activatable */
+          _mcd_client_proxy_set_activatable (client);
+        }
+      else
+        {
+          /* We already knew that it was activatable, but now we also know
+           * that it is active */
+          _mcd_client_proxy_set_active (client, unique_name_if_known);
+        }
+
+      return;
+    }
+
+  DEBUG ("Registering client %s", well_known_name);
 
   client = _mcd_client_proxy_new (self->priv->dbus_daemon,
       self->priv->string_pool, well_known_name, unique_name_if_known,
@@ -139,8 +175,6 @@ _mcd_client_registry_add_new (McdClientRegistry *self,
                     self);
 
   g_signal_emit (self, signals[S_CLIENT_ADDED], 0, client);
-
-  return client;
 }
 
 McdClientProxy *
@@ -345,7 +379,7 @@ mcd_client_registry_ready_cb (McdClientProxy *client,
   g_signal_handlers_disconnect_by_func (client,
       mcd_client_registry_ready_cb, self);
 
-  /* paired with the one in _mcd_client_registry_add_new */
+  /* paired with the one in _mcd_client_registry_found_name */
   _mcd_client_registry_dec_startup_lock (self);
 }
 
diff --git a/src/client-registry.h b/src/client-registry.h
index 3093f0b..6701f37 100644
--- a/src/client-registry.h
+++ b/src/client-registry.h
@@ -77,7 +77,7 @@ G_GNUC_INTERNAL gboolean _mcd_client_registry_is_ready (
 
 /* Temporary API for porting */
 
-G_GNUC_INTERNAL McdClientProxy *_mcd_client_registry_add_new (
+G_GNUC_INTERNAL void _mcd_client_registry_found_name (
     McdClientRegistry *self, const gchar *well_known_name,
     const gchar *unique_name_if_known, gboolean activatable);
 G_GNUC_INTERNAL void _mcd_client_registry_init_hash_iter (
diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index 347bcbb..25b694f 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -1871,59 +1871,6 @@ mcd_dispatcher_update_client_caps (McdDispatcher *self,
     g_ptr_array_free (vas, TRUE);
 }
 
-/* Check the list of strings whether they are valid well-known names of
- * Telepathy clients and create McdClientProxy objects for each of them.
- */
-static void
-mcd_dispatcher_add_client (McdDispatcher *self,
-                           const gchar *name,
-                           gboolean activatable,
-                           const gchar *owner)
-{
-    McdDispatcherPrivate *priv = MCD_DISPATCHER_PRIV (self);
-    McdClientProxy *client;
-
-    if (!g_str_has_prefix (name, TP_CLIENT_BUS_NAME_BASE))
-    {
-        /* This is not a Telepathy Client */
-        return;
-    }
-
-    if (!_mcd_client_check_valid_name (name + MC_CLIENT_BUS_NAME_BASE_LEN,
-                                       NULL))
-    {
-        /* This is probably meant to be a Telepathy Client, but it's not */
-        DEBUG ("Ignoring invalid Client name: %s",
-               name + MC_CLIENT_BUS_NAME_BASE_LEN);
-
-        return;
-    }
-
-    client = _mcd_client_registry_lookup (priv->clients, name);
-
-    if (client)
-    {
-        /* This Telepathy Client is already known so don't create it
-         * again. However, set the activatable bit now.
-         */
-        if (activatable)
-        {
-            _mcd_client_proxy_set_activatable (client);
-        }
-        else
-        {
-            _mcd_client_proxy_set_active (client, owner);
-        }
-
-        return;
-    }
-
-    DEBUG ("Register client %s", name);
-
-    client = _mcd_client_registry_add_new (self->priv->clients,
-        name, owner, activatable);
-}
-
 static void
 list_activatable_names_cb (TpDBusDaemon *proxy,
     const gchar **names,
@@ -1946,7 +1893,8 @@ list_activatable_names_cb (TpDBusDaemon *proxy,
 
         while (*iter != NULL)
         {
-            mcd_dispatcher_add_client (self, *iter, TRUE, NULL);
+            _mcd_client_registry_found_name (self->priv->clients,
+                                             *iter, NULL, TRUE);
             iter++;
         }
     }
@@ -1999,7 +1947,8 @@ list_names_cb (TpDBusDaemon *proxy,
 
         while (*iter != NULL)
         {
-            mcd_dispatcher_add_client (self, *iter, FALSE, NULL);
+            _mcd_client_registry_found_name (self->priv->clients,
+                                             *iter, NULL, FALSE);
             iter++;
         }
     }
@@ -2032,7 +1981,8 @@ name_owner_changed_cb (TpDBusDaemon *proxy,
 
     if (old_owner[0] == '\0' && new_owner[0] != '\0')
     {
-        mcd_dispatcher_add_client (self, name, FALSE, new_owner);
+        _mcd_client_registry_found_name (self->priv->clients,
+                                         name, new_owner, FALSE);
     }
     else if (old_owner[0] != '\0' && new_owner[0] == '\0')
     {
-- 
1.5.6.5




More information about the telepathy-commits mailing list