[telepathy-mission-control/master] McdClientRegistry: actually store clients as the name promises

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


---
 src/client-registry.c |   64 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/client-registry.h |   16 ++++++++++++
 2 files changed, 80 insertions(+), 0 deletions(-)

diff --git a/src/client-registry.c b/src/client-registry.c
index 12ae6bb..673fe11 100644
--- a/src/client-registry.c
+++ b/src/client-registry.c
@@ -33,17 +33,75 @@ enum
 
 struct _McdClientRegistryPrivate
 {
+  /* hash table containing clients
+   * owned gchar * well_known_name -> owned McdClientProxy */
+  GHashTable *clients;
+
   TpDBusDaemon *dbus_daemon;
+
   /* Not really handles as such, but TpHandleRepoIface gives us a convenient
    * reference-counted string pool */
   TpHandleRepoIface *string_pool;
 };
 
+McdClientProxy *
+_mcd_client_registry_add_new (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);
+
+    client = _mcd_client_proxy_new (self->priv->dbus_daemon,
+        self->priv->string_pool, well_known_name, unique_name_if_known,
+        activatable);
+    g_hash_table_insert (self->priv->clients, g_strdup (well_known_name),
+        client);
+    return client;
+}
+
+McdClientProxy *
+_mcd_client_registry_lookup (McdClientRegistry *self,
+    const gchar *well_known_name)
+{
+  g_return_val_if_fail (MCD_IS_CLIENT_REGISTRY (self), NULL);
+  return g_hash_table_lookup (self->priv->clients, well_known_name);
+}
+
+gboolean
+_mcd_client_registry_remove (McdClientRegistry *self,
+    const gchar *well_known_name)
+{
+  g_return_val_if_fail (MCD_IS_CLIENT_REGISTRY (self), FALSE);
+  return g_hash_table_remove (self->priv->clients, well_known_name);
+}
+
+guint
+_mcd_client_registry_size (McdClientRegistry *self)
+{
+  g_return_val_if_fail (MCD_IS_CLIENT_REGISTRY (self), 0);
+  return g_hash_table_size (self->priv->clients);
+}
+
+void _mcd_client_registry_init_hash_iter (McdClientRegistry *self,
+    GHashTableIter *iter)
+{
+  g_return_if_fail (MCD_IS_CLIENT_REGISTRY (self));
+  g_hash_table_iter_init (iter, self->priv->clients);
+}
+
 static void
 _mcd_client_registry_init (McdClientRegistry *self)
 {
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, MCD_TYPE_CLIENT_REGISTRY,
       McdClientRegistryPrivate);
+
+  self->priv->clients = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
+      g_object_unref);
 }
 
 static void
@@ -123,6 +181,12 @@ mcd_client_registry_dispose (GObject *object)
       self->priv->string_pool = NULL;
     }
 
+  if (self->priv->clients != NULL)
+    {
+      g_hash_table_destroy (self->priv->clients);
+      self->priv->clients = NULL;
+    }
+
   if (chain_up != NULL)
     chain_up (object);
 }
diff --git a/src/client-registry.h b/src/client-registry.h
index 1bc2c85..38fdca5 100644
--- a/src/client-registry.h
+++ b/src/client-registry.h
@@ -26,6 +26,8 @@
 #include <telepathy-glib/dbus.h>
 #include <telepathy-glib/handle-repo.h>
 
+#include "mcd-client-priv.h"
+
 G_BEGIN_DECLS
 
 typedef struct _McdClientRegistry McdClientRegistry;
@@ -64,6 +66,20 @@ GType _mcd_client_registry_get_type (void);
 G_GNUC_INTERNAL McdClientRegistry *_mcd_client_registry_new (
     TpDBusDaemon *dbus_daemon);
 
+G_GNUC_INTERNAL McdClientProxy *_mcd_client_registry_lookup (
+    McdClientRegistry *self, const gchar *well_known_name);
+
+/* Temporary API for porting */
+
+G_GNUC_INTERNAL McdClientProxy *_mcd_client_registry_add_new (
+    McdClientRegistry *self, const gchar *well_known_name,
+    const gchar *unique_name_if_known, gboolean activatable);
+G_GNUC_INTERNAL guint _mcd_client_registry_size (McdClientRegistry *self);
+G_GNUC_INTERNAL gboolean _mcd_client_registry_remove (McdClientRegistry *self,
+    const gchar *well_known_name);
+G_GNUC_INTERNAL void _mcd_client_registry_init_hash_iter (
+    McdClientRegistry *self, GHashTableIter *iter);
+
 G_END_DECLS
 
 #endif
-- 
1.5.6.5




More information about the telepathy-commits mailing list