From 47c133f5b33ebb07a4bb814ea03927d645df0f51 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 23 Sep 2013 17:28:56 +0200 Subject: [PATCH 08/15] client-factory: turn to a singleton https://bugs.freedesktop.org/show_bug.cgi?id=69797 --- telepathy-logger/client-factory-internal.h | 2 +- telepathy-logger/client-factory.c | 18 +++++++++++++++++- telepathy-logger/observer.c | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/telepathy-logger/client-factory-internal.h b/telepathy-logger/client-factory-internal.h index 9612c30..a9e9337 100644 --- a/telepathy-logger/client-factory-internal.h +++ b/telepathy-logger/client-factory-internal.h @@ -54,6 +54,6 @@ GType _tpl_client_factory_get_type (void); (G_TYPE_INSTANCE_GET_CLASS ((obj), TPL_TYPE_CLIENT_FACTORY, \ TplClientFactoryClass)) -TpSimpleClientFactory *_tpl_client_factory_new (TpDBusDaemon *dbus); +TpSimpleClientFactory *_tpl_client_factory_dup (TpDBusDaemon *dbus); #endif /* __TPL_CLIENT_FACTORY_H__ */ diff --git a/telepathy-logger/client-factory.c b/telepathy-logger/client-factory.c index 0d4b131..b3dd9fe 100644 --- a/telepathy-logger/client-factory.c +++ b/telepathy-logger/client-factory.c @@ -94,10 +94,26 @@ _tpl_client_factory_class_init (TplClientFactoryClass *cls) simple_class->dup_channel_features = dup_channel_features_impl; } -TpSimpleClientFactory * + +static TpSimpleClientFactory * _tpl_client_factory_new (TpDBusDaemon *dbus) { return g_object_new (TPL_TYPE_CLIENT_FACTORY, "dbus-daemon", dbus, NULL); } + +TpSimpleClientFactory * +_tpl_client_factory_dup (TpDBusDaemon *dbus) +{ + static TpSimpleClientFactory *singleton = NULL; + + if (singleton != NULL) + return g_object_ref (singleton); + + singleton = _tpl_client_factory_new (dbus); + + g_object_add_weak_pointer (G_OBJECT (singleton), (gpointer) &singleton); + + return singleton; +} diff --git a/telepathy-logger/observer.c b/telepathy-logger/observer.c index ff9a07b..02c0d1d 100644 --- a/telepathy-logger/observer.c +++ b/telepathy-logger/observer.c @@ -289,7 +289,7 @@ _tpl_observer_dup (GError **error) return NULL; } - factory = _tpl_client_factory_new (dbus); + factory = _tpl_client_factory_dup (dbus); /* Pre-select feature to be initialized. */ tp_simple_client_factory_add_contact_features_varargs (factory, -- 1.8.3.1