telepathy-logger: client-factory: turn to a singleton

Guillaume Desmottes gdesmott at kemper.freedesktop.org
Wed Sep 25 07:38:46 PDT 2013


Module: telepathy-logger
Branch: master
Commit: 30f231cc4b89aac17dd0c1426ac0f11df7056454
URL:    http://cgit.freedesktop.org/telepathy/telepathy-logger/commit/?id=30f231cc4b89aac17dd0c1426ac0f11df7056454

Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date:   Mon Sep 23 17:28:56 2013 +0200

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,



More information about the telepathy-commits mailing list