summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2010-10-11 12:15:52 +0200
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2010-10-11 12:15:52 +0200
commita1aab2965eadc7a347cc862d7f533f1dc984365a (patch)
treea2e55614877fd083a765b037ff8b2b335e414c67
parent3fe8b3261dbb4933920485f56219ed8c98f2e4ff (diff)
downloadtelepathy-glib-a1aab2965eadc7a347cc862d7f533f1dc984365a.tar.gz
add tp_basic_proxy_factory_dup()
-rw-r--r--docs/reference/telepathy-glib-sections.txt1
-rw-r--r--telepathy-glib/basic-proxy-factory.c26
-rw-r--r--telepathy-glib/basic-proxy-factory.h2
-rw-r--r--tests/dbus/client-channel-factory.c18
4 files changed, 47 insertions, 0 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 02e3b1e35..e8973a2d7 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -4875,6 +4875,7 @@ tp_client_channel_factory_get_type
TpBasicProxyFactory
TpBasicProxyFactoryClass
tp_basic_proxy_factory_new
+tp_basic_proxy_factory_dup
<SUBSECTION Standard>
TP_BASIC_PROXY_FACTORY
TP_BASIC_PROXY_FACTORY_GET_CLASS
diff --git a/telepathy-glib/basic-proxy-factory.c b/telepathy-glib/basic-proxy-factory.c
index fab0bb8ef..c32e06e35 100644
--- a/telepathy-glib/basic-proxy-factory.c
+++ b/telepathy-glib/basic-proxy-factory.c
@@ -96,3 +96,29 @@ tp_basic_proxy_factory_new (void)
return g_object_new (TP_TYPE_BASIC_PROXY_FACTORY,
NULL);
}
+
+/**
+ * tp_basic_proxy_factory_dup:
+ *
+ * Returns a cached #TpBasicProxyFactory; the same #TpBasicProxyFactory object
+ * will be returned by this function repeatedly, as long as at least one
+ * reference exists.
+ *
+ * Returns: (transfer full): a #TpBasicProxyFactory
+ *
+ * Since: 0.13.UNRELEASED
+ */
+TpBasicProxyFactory *
+tp_basic_proxy_factory_dup (void)
+{
+ static TpBasicProxyFactory *singleton = NULL;
+
+ if (singleton != NULL)
+ return g_object_ref (singleton);
+
+ singleton = tp_basic_proxy_factory_new ();
+
+ g_object_add_weak_pointer (G_OBJECT (singleton), (gpointer) &singleton);
+
+ return singleton;
+}
diff --git a/telepathy-glib/basic-proxy-factory.h b/telepathy-glib/basic-proxy-factory.h
index 0701dba12..fc19c3a24 100644
--- a/telepathy-glib/basic-proxy-factory.h
+++ b/telepathy-glib/basic-proxy-factory.h
@@ -58,6 +58,8 @@ GType tp_basic_proxy_factory_get_type (void);
TpBasicProxyFactory * tp_basic_proxy_factory_new (void);
+TpBasicProxyFactory * tp_basic_proxy_factory_dup (void);
+
G_END_DECLS
#endif
diff --git a/tests/dbus/client-channel-factory.c b/tests/dbus/client-channel-factory.c
index cb5335464..9896bcd27 100644
--- a/tests/dbus/client-channel-factory.c
+++ b/tests/dbus/client-channel-factory.c
@@ -184,6 +184,22 @@ test_auto_stream_tube (Test *test,
g_hash_table_unref (props);
}
+static void
+test_basic_dup (Test *test,
+ gconstpointer data G_GNUC_UNUSED)
+{
+ TpBasicProxyFactory *fac;
+
+ test->factory = TP_CLIENT_CHANNEL_FACTORY (tp_basic_proxy_factory_dup ());
+ g_assert (TP_IS_BASIC_PROXY_FACTORY (test->factory));
+ g_assert (TP_IS_CLIENT_CHANNEL_FACTORY (test->factory));
+
+ fac = tp_basic_proxy_factory_dup ();
+ g_assert ((gpointer) fac == (gpointer) test->factory);
+
+ g_object_unref (fac);
+}
+
int
main (int argc,
char **argv)
@@ -202,6 +218,8 @@ main (int argc,
test_basic_stream_tube, teardown);
g_test_add ("/client-channel-factory/auto/stream-tube", Test, NULL, setup,
test_auto_stream_tube, teardown);
+ g_test_add ("/client-channel-factory/basic/dup", Test, NULL, setup,
+ test_basic_dup, teardown);
return g_test_run ();
}