[Pkg-telepathy-commits] [telepathy-glib-1] 64/212: TpClientFactory: Add a singleton factory
Simon McVittie
smcv at debian.org
Wed May 14 12:08:52 UTC 2014
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch debian
in repository telepathy-glib-1.
commit bdb6dd9ff6aaae5690b29916c8f497a920014d1c
Author: Xavier Claessens <xavier.claessens at collabora.com>
Date: Sat Mar 29 16:00:05 2014 -0400
TpClientFactory: Add a singleton factory
tp_client_factory_dup()'s documentation is a preview from what
it will be in a future commit. I did not write a temporary
documentation in the meantime.
---
.../telepathy-glib/telepathy-glib-sections.txt | 3 +
telepathy-glib/client-factory.c | 101 +++++++++++++++++++++
telepathy-glib/client-factory.h | 3 +
3 files changed, 107 insertions(+)
diff --git a/docs/reference/telepathy-glib/telepathy-glib-sections.txt b/docs/reference/telepathy-glib/telepathy-glib-sections.txt
index 04c1064..8ba81ea 100644
--- a/docs/reference/telepathy-glib/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib/telepathy-glib-sections.txt
@@ -5728,6 +5728,9 @@ tp_cli_call_stream_endpoint_add_signals
TpClientFactory
TpClientFactoryClass
tp_client_factory_new
+tp_client_factory_dup
+tp_client_factory_set_default
+tp_client_factory_can_set_default
tp_client_factory_get_dbus_daemon
<SUBSECTION>
tp_client_factory_ensure_account
diff --git a/telepathy-glib/client-factory.c b/telepathy-glib/client-factory.c
index ed9080a..7dfb58c 100644
--- a/telepathy-glib/client-factory.c
+++ b/telepathy-glib/client-factory.c
@@ -125,6 +125,7 @@
#include "telepathy-glib/client-factory.h"
+#include <telepathy-glib/automatic-client-factory.h>
#include <telepathy-glib/util.h>
#define DEBUG_FLAG TP_DEBUG_CLIENT
@@ -484,6 +485,106 @@ tp_client_factory_new (TpDBusDaemon *dbus)
NULL);
}
+static GWeakRef singleton;
+
+/**
+ * tp_client_factory_dup:
+ * @error: Used to raise an error if getting the session #GDBusConnection fails
+ *
+ * Get a reference to a #TpClientFactory singleton. It can fail and block only
+ * if the session #GDBusConnection singleton doesn't exist yet. It is thus
+ * recommended to call g_bus_get() before using a #TpClientFactory if the
+ * application must not block.
+ *
+ * By default it will create a #TpAutomaticClientFactory.
+ *
+ * Returns: (transfer full): a reference to a #TpClientFactory singleton.
+ * Since: 0.UNRELEASED
+ */
+TpClientFactory *
+tp_client_factory_dup (GError **error)
+{
+ TpClientFactory *self;
+
+ self = g_weak_ref_get (&singleton);
+ if (self == NULL)
+ {
+ TpDBusDaemon *dbus;
+
+ dbus = tp_dbus_daemon_dup (error);
+ if (dbus == NULL)
+ return NULL;
+
+ self = tp_automatic_client_factory_new (dbus);
+ g_weak_ref_set (&singleton, self);
+ g_object_unref (dbus);
+ }
+
+ return self;
+}
+
+/**
+ * tp_client_factory_set_default:
+ * @self: a #TpClientFactory
+ *
+ * Define the #TpClientFactory singleton that will be returned by
+ * tp_client_factory_dup().
+ *
+ * This function may only be called before the first call to
+ * tp_client_factory_dup(), and may not be called more than once. Applications
+ * which use a custom #TpClientFactory and want it to be the default factory
+ * should call this.
+ *
+ * Only a weak reference is taken on @self. It is the caller's responsibility
+ * to keep it alive. If @self is disposed after calling this function, the
+ * next call to tp_client_factory_dup() will return a newly created
+ * #TpClientFactory.
+ *
+ * Since: 0.UNRELEASED
+ */
+void
+tp_client_factory_set_default (TpClientFactory *self)
+{
+ TpClientFactory *tmp;
+
+ g_return_if_fail (TP_IS_CLIENT_FACTORY (self));
+
+ tmp = g_weak_ref_get (&singleton);
+ if (tmp != NULL)
+ {
+ CRITICAL ("tp_client_factory_set_default() may only be called once and"
+ "before first call of tp_client_factory_dup()");
+ g_object_unref (tmp);
+ g_return_if_reached ();
+ }
+
+ g_weak_ref_set (&singleton, self);
+}
+
+/**
+ * tp_client_factory_can_set_default:
+ *
+ * Check if tp_client_factory_set_default() has already successfully been
+ * called.
+ *
+ * Returns: %TRUE if tp_client_factory_set_default() has already successfully
+ * been called in this process, %FALSE otherwise.
+ *
+ * Since: 0.UNRELEASED
+ */
+gboolean
+tp_client_factory_can_set_default (void)
+{
+ TpClientFactory *tmp;
+ gboolean ret;
+
+ tmp = g_weak_ref_get (&singleton);
+ ret = (tmp == NULL);
+ g_clear_object (&tmp);
+
+ return ret;
+}
+
/**
* tp_client_factory_get_dbus_daemon:
* @self: a #TpClientFactory object
diff --git a/telepathy-glib/client-factory.h b/telepathy-glib/client-factory.h
index 38afd5c..38bccb5 100644
--- a/telepathy-glib/client-factory.h
+++ b/telepathy-glib/client-factory.h
@@ -124,6 +124,9 @@ GType tp_client_factory_get_type (void);
TpClientFactoryClass))
TpClientFactory * tp_client_factory_new (TpDBusDaemon *dbus);
+TpClientFactory * tp_client_factory_dup (GError **error);
+void tp_client_factory_set_default (TpClientFactory *self);
+gboolean tp_client_factory_can_set_default (void);
TpDBusDaemon *tp_client_factory_get_dbus_daemon (TpClientFactory *self);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-telepathy/telepathy-glib-1.git
More information about the Pkg-telepathy-commits
mailing list