[telepathy-mission-control/master] McdClientRegistry: remove clients automatically when they disappear
Simon McVittie
simon.mcvittie at collabora.co.uk
Mon Oct 19 07:01:08 PDT 2009
Previously, McdDispatcher did this.
---
src/client-registry.c | 40 +++++++++++++++++++++++++++++++++++++---
src/client-registry.h | 2 --
src/mcd-dispatcher.c | 2 --
3 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/src/client-registry.c b/src/client-registry.c
index c0e807b..851cdf6 100644
--- a/src/client-registry.c
+++ b/src/client-registry.c
@@ -52,6 +52,9 @@ struct _McdClientRegistryPrivate
TpHandleRepoIface *string_pool;
};
+static void mcd_client_registry_gone_cb (McdClientProxy *client,
+ McdClientRegistry *self);
+
McdClientProxy *
_mcd_client_registry_add_new (McdClientRegistry *self,
const gchar *well_known_name,
@@ -70,6 +73,10 @@ _mcd_client_registry_add_new (McdClientRegistry *self,
g_hash_table_insert (self->priv->clients, g_strdup (well_known_name),
client);
+ g_signal_connect (client, "gone",
+ G_CALLBACK (mcd_client_registry_gone_cb),
+ self);
+
g_signal_emit (self, signals[S_CLIENT_ADDED], 0, client);
return client;
@@ -83,12 +90,29 @@ _mcd_client_registry_lookup (McdClientRegistry *self,
return g_hash_table_lookup (self->priv->clients, well_known_name);
}
-gboolean
+static void
+mcd_client_registry_disconnect_client_signals (gpointer k G_GNUC_UNUSED,
+ gpointer v,
+ gpointer data)
+{
+ g_signal_handlers_disconnect_by_func (v, mcd_client_registry_gone_cb, data);
+}
+
+static void
_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);
+ McdClientProxy *client;
+
+ client = g_hash_table_lookup (self->priv->clients, well_known_name);
+
+ if (client != NULL)
+ {
+ mcd_client_registry_disconnect_client_signals (NULL,
+ client, self);
+ }
+
+ g_hash_table_remove (self->priv->clients, well_known_name);
}
guint
@@ -194,6 +218,9 @@ mcd_client_registry_dispose (GObject *object)
if (self->priv->clients != NULL)
{
+ g_hash_table_foreach (self->priv->clients,
+ mcd_client_registry_disconnect_client_signals, self);
+
g_hash_table_destroy (self->priv->clients);
self->priv->clients = NULL;
}
@@ -234,3 +261,10 @@ _mcd_client_registry_new (TpDBusDaemon *dbus_daemon)
"dbus-daemon", dbus_daemon,
NULL);
}
+
+static void
+mcd_client_registry_gone_cb (McdClientProxy *client,
+ McdClientRegistry *self)
+{
+ _mcd_client_registry_remove (self, tp_proxy_get_bus_name (client));
+}
diff --git a/src/client-registry.h b/src/client-registry.h
index 38fdca5..172758c 100644
--- a/src/client-registry.h
+++ b/src/client-registry.h
@@ -75,8 +75,6 @@ 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);
diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index 34ec253..4b25c8b 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -1765,8 +1765,6 @@ mcd_dispatcher_client_gone_cb (McdClientProxy *client,
McdDispatcher *self)
{
mcd_dispatcher_discard_client (self, client);
- _mcd_client_registry_remove (self->priv->clients,
- tp_proxy_get_bus_name (client));
}
static void
--
1.5.6.5
More information about the telepathy-commits
mailing list