[telepathy-glib/master] account-manager: add tp_account_manager_dup and remove the GObject singleton code
Jonny Lamb
jonny.lamb at collabora.co.uk
Mon Sep 28 07:38:55 PDT 2009
This is to copy the behaviour of #TpDBusDaemon, where in reality you
only ever want one TpAccountManager proxy -- on the starter/session
bus.
Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
---
docs/reference/telepathy-glib-sections.txt | 1 +
telepathy-glib/account-manager.c | 73 +++++++++++++++++-----------
telepathy-glib/account-manager.h | 2 +
3 files changed, 47 insertions(+), 29 deletions(-)
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index 2042c04..1ddad05 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -3063,6 +3063,7 @@ TpAccountManager
TpAccountManagerClass
tp_account_manager_new
tp_account_manager_init_known_interfaces
+tp_account_manager_dup
tp_account_manager_create_account_async
tp_account_manager_create_account_finish
tp_account_manager_ensure_account
diff --git a/telepathy-glib/account-manager.c b/telepathy-glib/account-manager.c
index 68ba06e..42de60a 100644
--- a/telepathy-glib/account-manager.c
+++ b/telepathy-glib/account-manager.c
@@ -102,7 +102,6 @@ enum {
};
static guint signals[LAST_SIGNAL];
-static gpointer manager_singleton = NULL;
G_DEFINE_TYPE (TpAccountManager, tp_account_manager, TP_TYPE_PROXY);
@@ -376,28 +375,6 @@ _tp_account_manager_dispose (GObject *object)
G_OBJECT_CLASS (tp_account_manager_parent_class)->dispose (object);
}
-static GObject *
-_tp_account_manager_constructor (GType type,
- guint n_construct_params,
- GObjectConstructParam *construct_params)
-{
- GObject *retval;
-
- if (manager_singleton == NULL)
- {
- retval = G_OBJECT_CLASS (tp_account_manager_parent_class)->constructor (
- type, n_construct_params, construct_params);
- manager_singleton = retval;
- g_object_add_weak_pointer (retval, &manager_singleton);
- }
- else
- {
- retval = g_object_ref (G_OBJECT (manager_singleton));
- }
-
- return retval;
-}
-
static void
_tp_account_manager_get_property (GObject *object,
guint prop_id,
@@ -428,7 +405,6 @@ tp_account_manager_class_init (TpAccountManagerClass *klass)
object_class->constructed = _tp_account_manager_constructed;
object_class->finalize = _tp_account_manager_finalize;
object_class->dispose = _tp_account_manager_dispose;
- object_class->constructor = _tp_account_manager_constructor;
object_class->get_property = _tp_account_manager_get_property;
proxy_class->interface = TP_IFACE_QUARK_ACCOUNT_MANAGER;
@@ -644,12 +620,11 @@ tp_account_manager_init_known_interfaces (void)
*
* Convenience function to create a new account manager proxy.
*
- * The returned #TpAccountManager is cached; the same #TpAccountManager object
- * will be returned by this function repeatedly, as long as at least one
- * reference exists.
+ * Use tp_account_manager_dup() instead if you want an account managerproxy
+ * on the starter or session bus (which is almost always the right thing for
+ * Telepathy).
*
- * Returns: a reference to the cached #TpAccountManager object, or a new
- * instance
+ * Returns: a new reference to an account manager proxy
*/
TpAccountManager *
tp_account_manager_new (TpDBusDaemon *bus_daemon)
@@ -668,6 +643,46 @@ tp_account_manager_new (TpDBusDaemon *bus_daemon)
return self;
}
+static gpointer starter_account_manager_proxy = NULL;
+
+/**
+ * tp_account_manager_dup:
+ *
+ * Returns an account manager proxy on the D-Bus daemon on which this
+ * process was activated (if it was launched by D-Bus service activation), or
+ * the session bus (otherwise).
+ *
+ * The returned #TpAccountManager is cached; the same #TpAccountManager object
+ * will be returned by this function repeatedly, as long as at least one
+ * reference exists.
+ *
+ * Returns: an account manager proxy on the starter or session bus, or %NULL
+ * if it wasn't possible to get a dbus daemon proxy for the
+ * appropriate bus
+ *
+ * Since: 0.7.UNRELEASED
+ */
+TpAccountManager *
+tp_account_manager_dup (void)
+{
+ TpDBusDaemon *dbus;
+
+ if (starter_account_manager_proxy != NULL)
+ return g_object_ref (starter_account_manager_proxy);
+
+ dbus = tp_dbus_daemon_dup (NULL);
+
+ if (dbus == NULL)
+ return NULL;
+
+ starter_account_manager_proxy = tp_account_manager_new (dbus);
+ g_assert (starter_account_manager_proxy != NULL);
+ g_object_add_weak_pointer (starter_account_manager_proxy,
+ &starter_account_manager_proxy);
+
+ return starter_account_manager_proxy;
+}
+
static void
_tp_account_manager_account_connection_cb (TpAccount *account,
GParamSpec *spec,
diff --git a/telepathy-glib/account-manager.h b/telepathy-glib/account-manager.h
index 428bb6f..0a3d24d 100644
--- a/telepathy-glib/account-manager.h
+++ b/telepathy-glib/account-manager.h
@@ -66,6 +66,8 @@ GType tp_account_manager_get_type (void);
TpAccountManager *tp_account_manager_new (TpDBusDaemon *bus_daemon);
+TpAccountManager *tp_account_manager_dup (void);
+
void tp_account_manager_init_known_interfaces (void);
gboolean tp_account_manager_is_ready (TpAccountManager *manager);
--
1.5.6.5
More information about the telepathy-commits
mailing list