[Pkg-telepathy-commits] [telepathy-glib-1] 66/212: TpAccountManager: Always create from a 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 38e81634ed2e5de02350f6dd6211529b6ae43b9a
Author: Xavier Claessens <xavier.claessens at collabora.com>
Date:   Fri Mar 28 23:35:36 2014 -0400

    TpAccountManager: Always create from a factory
---
 .../telepathy-glib/telepathy-glib-sections.txt     |   6 +-
 telepathy-glib/account-manager.c                   | 164 ++-------------------
 telepathy-glib/account-manager.h                   |  12 --
 telepathy-glib/client-factory-internal.h           |   2 +
 telepathy-glib/client-factory.c                    |  28 ++++
 telepathy-glib/client-factory.h                    |   3 +
 telepathy-glib/versions/main-1.0.abi               |   4 -
 tests/dbus/account-manager.c                       |  17 ++-
 tests/dbus/simple-approver.c                       |   2 +-
 9 files changed, 67 insertions(+), 171 deletions(-)

diff --git a/docs/reference/telepathy-glib/telepathy-glib-sections.txt b/docs/reference/telepathy-glib/telepathy-glib-sections.txt
index 675cc4d..e958afd 100644
--- a/docs/reference/telepathy-glib/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib/telepathy-glib-sections.txt
@@ -4084,10 +4084,6 @@ TpAccountRequestPrivate
 <TITLE>account-manager</TITLE>
 TpAccountManager
 TpAccountManagerClass
-tp_account_manager_new
-tp_account_manager_new_with_factory
-tp_account_manager_set_default
-tp_account_manager_can_set_default
 tp_account_manager_dup
 tp_account_manager_create_account_async
 tp_account_manager_create_account_finish
@@ -5734,6 +5730,8 @@ tp_client_factory_can_set_default
 tp_client_factory_get_dbus_daemon
 tp_client_factory_get_dbus_connection
 <SUBSECTION>
+tp_client_factory_dup_account_manager
+<SUBSECTION>
 tp_client_factory_ensure_account
 tp_client_factory_dup_account_features
 tp_client_factory_add_account_features
diff --git a/telepathy-glib/account-manager.c b/telepathy-glib/account-manager.c
index 8eb3da3..a013826 100644
--- a/telepathy-glib/account-manager.c
+++ b/telepathy-glib/account-manager.c
@@ -503,8 +503,6 @@ _tp_account_manager_constructed (GObject *object)
 
   g_return_if_fail (tp_proxy_get_dbus_daemon (self) != NULL);
 
-  _tp_proxy_ensure_factory (self, NULL);
-
   tp_cli_account_manager_connect_to_account_usability_changed (self,
       _tp_account_manager_usability_changed_cb, NULL,
       NULL, G_OBJECT (self), NULL);
@@ -662,13 +660,13 @@ tp_account_manager_class_init (TpAccountManagerClass *klass)
         G_TYPE_STRING); /* stauts message*/
 }
 
-static TpAccountManager *
-_tp_account_manager_new_internal (TpClientFactory *factory,
-    TpDBusDaemon *bus_daemon)
+TpAccountManager *
+_tp_account_manager_new (TpClientFactory *factory)
 {
+  g_return_val_if_fail (TP_IS_CLIENT_FACTORY (factory), NULL);
+
   return TP_ACCOUNT_MANAGER (g_object_new (TP_TYPE_ACCOUNT_MANAGER,
-          "dbus-daemon", bus_daemon,
-          "dbus-connection", tp_proxy_get_dbus_connection (bus_daemon),
+          "dbus-daemon", tp_client_factory_get_dbus_daemon (factory),
           "bus-name", TP_ACCOUNT_MANAGER_BUS_NAME,
           "object-path", TP_ACCOUNT_MANAGER_OBJECT_PATH,
           "factory", factory,
@@ -676,165 +674,35 @@ _tp_account_manager_new_internal (TpClientFactory *factory,
 }
 
 /**
- * tp_account_manager_new:
- * @bus_daemon: Proxy for the D-Bus daemon
- *
- * Convenience function to create a new account manager proxy. The returned
- * #TpAccountManager is not guaranteed to be prepared on return.
- * Its #TpProxy:factory will be a new #TpAutomaticClientFactory for
- * @bus_daemon.
- *
- * Use tp_account_manager_dup() instead if you want an account manager proxy
- * on the session bus (which is almost always the right thing fo
- * Telepathy).
- *
- * Returns: a new reference to an account manager proxy
- */
-TpAccountManager *
-tp_account_manager_new (TpDBusDaemon *bus_daemon)
-{
-  g_return_val_if_fail (TP_IS_DBUS_DAEMON (bus_daemon), NULL);
-
-  return _tp_account_manager_new_internal (NULL, bus_daemon);
-}
-
-/**
- * tp_account_manager_new_with_factory:
- * @factory: a #TpClientFactory
- *
- * Convenience function to create a new account manager proxy. The returned
- * #TpAccountManager is not guaranteed to be ready on return.
- *
- * Should be used only by applications having their own #TpClientFactory
- * subclass. Usually this should be done at application startup and followed by
- * a call to tp_account_manager_set_default() to ensure other libraries/plugins
- * will use this custom factory as well.
- *
- * Returns: a new reference to an account manager proxy
- */
-TpAccountManager *
-tp_account_manager_new_with_factory (TpClientFactory *factory)
-{
-  g_return_val_if_fail (TP_IS_CLIENT_FACTORY (factory), NULL);
-
-  return _tp_account_manager_new_internal (factory,
-      tp_client_factory_get_dbus_daemon (factory));
-}
-
-static gpointer default_account_manager_proxy = NULL;
-
-/**
- * tp_account_manager_set_default:
- * @manager: a #TpAccountManager
- *
- * Define the #TpAccountManager singleton that will be returned by
- * tp_account_manager_dup().
- *
- * This function may only be called before the first call to
- * tp_account_manager_dup(), and may not be called more than once. Applications
- * which use a custom #TpClientFactory and want the default
- * #TpAccountManager to use that factory should call this after calling
- * tp_account_manager_new_with_factory().
- *
- * Only a weak reference is taken on @manager. It is the caller's responsibility
- * to keep it alive. If @manager is disposed after calling this function, the
- * next call to tp_account_manager_dup() will return a newly created
- * #TpAccountManager.
- *
- * Note that @manager must use the default #TpDBusDaemon as returned by
- * tp_dbus_daemon_dup().
- *
- * Since: 0.15.5
- */
-void
-tp_account_manager_set_default (TpAccountManager *manager)
-{
-  g_return_if_fail (TP_IS_ACCOUNT_MANAGER (manager));
-
-  if (!_tp_dbus_daemon_is_the_shared_one (tp_proxy_get_dbus_daemon (manager)))
-    {
-      CRITICAL ("'manager' must use the TpDBusDaemon returned by"
-          "tp_dbus_daemon_dup()");
-      g_return_if_reached ();
-    }
-
-  if (default_account_manager_proxy != NULL)
-    {
-      CRITICAL ("tp_account_manager_set_default() may only be called once and"
-          "before first call of tp_account_manager_dup()");
-      g_return_if_reached ();
-    }
-
-  default_account_manager_proxy = manager;
-  g_object_add_weak_pointer (default_account_manager_proxy,
-      &default_account_manager_proxy);
-}
-
-/**
- * tp_account_manager_can_set_default:
- *
- * Check if tp_account_manager_set_default() has already successfully been
- * called.
- *
- * Returns: %TRUE if tp_account_manager_set_default() has already successfully
- * been called in this process, %FALSE otherwise.
- *
- * Since: 0.19.6
- */
-gboolean
-tp_account_manager_can_set_default (void)
-{
-  return default_account_manager_proxy == NULL;
-}
-
-/**
  * tp_account_manager_dup:
  *
- * Returns an account manager proxy on the session bus.
- * This account manager will always have
- * the result of tp_dbus_daemon_dup() as its #TpProxy:dbus-daemon.
+ * Returns the default #TpClientFactory's #TpAccountManager. It will use
+ * tp_client_factory_dup(), print a warning and return %NULL if it fails.
  *
- * The returned #TpAccountManager is cached; the same #TpAccountManager object
- * will be returned by this function repeatedly, as long as at least one
- * reference exists. Note that the returned #TpAccountManager is not guaranteed
- * to be ready on return.
- *
- * If tp_account_manager_set_default() has been called successfully,
- * that #TpAccountManager will be returned. Otherwise, a new #TpAccountManager
- * will be created the first time this function is called, using a new
- * #TpAutomaticClientFactory as its #TpProxy:factory.
- *
- * Returns: (transfer full): an account manager proxy on the session
- *          bus, or %NULL if it wasn't possible to get a dbus daemon proxy for
- *          the appropriate bus
+ * Returns: (transfer full): a reference on a #TpAccountManager singleton.
  *
  * Since: 0.9.0
  */
 TpAccountManager *
 tp_account_manager_dup (void)
 {
-  TpDBusDaemon *dbus;
+  TpAccountManager *self;
+  TpClientFactory *factory;
   GError *error = NULL;
 
-  if (default_account_manager_proxy != NULL)
-    return g_object_ref (default_account_manager_proxy);
-
-  dbus = tp_dbus_daemon_dup (&error);
-  if (dbus == NULL)
+  factory = tp_client_factory_dup (&error);
+  if (factory == NULL)
     {
-      WARNING ("Error getting default TpDBusDaemon: %s", error->message);
+      WARNING ("Error getting default TpClientFactory: %s", error->message);
       g_clear_error (&error);
       return NULL;
     }
 
-  default_account_manager_proxy = tp_account_manager_new (dbus);
-  g_assert (default_account_manager_proxy != NULL);
-  g_object_add_weak_pointer (default_account_manager_proxy,
-      &default_account_manager_proxy);
+  self = tp_client_factory_dup_account_manager (factory);
 
-  g_object_unref (dbus);
+  g_object_unref (factory);
 
-  return default_account_manager_proxy;
+  return self;
 }
 
 static void
diff --git a/telepathy-glib/account-manager.h b/telepathy-glib/account-manager.h
index f66a82f..9f28c52 100644
--- a/telepathy-glib/account-manager.h
+++ b/telepathy-glib/account-manager.h
@@ -74,18 +74,6 @@ GType tp_account_manager_get_type (void);
 
 GQuark tp_account_manager_get_feature_quark_core (void) G_GNUC_CONST;
 
-TpAccountManager *tp_account_manager_new (TpDBusDaemon *bus_daemon)
-  G_GNUC_WARN_UNUSED_RESULT;
-
-TpAccountManager *tp_account_manager_new_with_factory (
-    TpClientFactory *factory) G_GNUC_WARN_UNUSED_RESULT;
-
-_TP_AVAILABLE_IN_0_16
-void tp_account_manager_set_default (TpAccountManager *manager);
-
-_TP_AVAILABLE_IN_0_20
-gboolean tp_account_manager_can_set_default (void);
-
 TpAccountManager *tp_account_manager_dup (void) G_GNUC_WARN_UNUSED_RESULT;
 
 _TP_AVAILABLE_IN_0_20
diff --git a/telepathy-glib/client-factory-internal.h b/telepathy-glib/client-factory-internal.h
index 26d8cae..15a0a67 100644
--- a/telepathy-glib/client-factory-internal.h
+++ b/telepathy-glib/client-factory-internal.h
@@ -76,6 +76,8 @@ TpTLSCertificate *_tp_tls_certificate_new (TpProxy *conn_or_chan,
     const gchar *object_path,
     GError **error);
 
+TpAccountManager *_tp_account_manager_new (TpClientFactory *factory);
+
 G_END_DECLS
 
 #endif
diff --git a/telepathy-glib/client-factory.c b/telepathy-glib/client-factory.c
index 2a86a90..ff1d8e5 100644
--- a/telepathy-glib/client-factory.c
+++ b/telepathy-glib/client-factory.c
@@ -126,6 +126,7 @@
 #include "telepathy-glib/client-factory.h"
 
 #include <telepathy-glib/automatic-client-factory.h>
+#include <telepathy-glib/interfaces.h>
 #include <telepathy-glib/util.h>
 
 #define DEBUG_FLAG TP_DEBUG_CLIENT
@@ -624,6 +625,33 @@ tp_client_factory_get_dbus_connection (TpClientFactory *self)
 }
 
 /**
+ * tp_client_factory_dup_account_manager:
+ * @self: a #TpClientFactory object
+ *
+ * <!-- -->
+ *
+ * Returns: (transfer full): a reference to a #TpAccountManager singleton.
+ *
+ * Since: 0.UNRELEASED
+ */
+TpAccountManager *
+tp_client_factory_dup_account_manager (TpClientFactory *self)
+{
+  TpAccountManager *account_manager;
+
+  g_return_val_if_fail (TP_IS_CLIENT_FACTORY (self), NULL);
+
+  account_manager = lookup_proxy (self, TP_ACCOUNT_MANAGER_OBJECT_PATH);
+  if (account_manager != NULL)
+    return g_object_ref (account_manager);
+
+  account_manager = _tp_account_manager_new (self);
+  insert_proxy (self, account_manager);
+
+  return account_manager;
+}
+
+/**
  * tp_client_factory_ensure_account:
  * @self: a #TpClientFactory object
  * @object_path: the object path of an account
diff --git a/telepathy-glib/client-factory.h b/telepathy-glib/client-factory.h
index ed409ec..889a861 100644
--- a/telepathy-glib/client-factory.h
+++ b/telepathy-glib/client-factory.h
@@ -26,6 +26,7 @@
 #define __TP_CLIENT_FACTORY_H__
 
 #include <telepathy-glib/account.h>
+#include <telepathy-glib/account-manager.h>
 #include <telepathy-glib/channel.h>
 #include <telepathy-glib/channel-dispatch-operation.h>
 #include <telepathy-glib/channel-request.h>
@@ -131,6 +132,8 @@ gboolean tp_client_factory_can_set_default (void);
 TpDBusDaemon *tp_client_factory_get_dbus_daemon (TpClientFactory *self);
 GDBusConnection *tp_client_factory_get_dbus_connection (TpClientFactory *self);
 
+TpAccountManager *tp_client_factory_dup_account_manager (TpClientFactory *self);
+
 /* TpAccount */
 TpAccount *tp_client_factory_ensure_account (TpClientFactory *self,
     const gchar *object_path,
diff --git a/telepathy-glib/versions/main-1.0.abi b/telepathy-glib/versions/main-1.0.abi
index c335370..a706223 100644
--- a/telepathy-glib/versions/main-1.0.abi
+++ b/telepathy-glib/versions/main-1.0.abi
@@ -74,7 +74,6 @@ tp_account_get_type
 tp_account_get_uri_schemes
 tp_account_is_enabled
 tp_account_is_usable
-tp_account_manager_can_set_default
 tp_account_manager_create_account_async
 tp_account_manager_create_account_finish
 tp_account_manager_dup
@@ -83,10 +82,7 @@ tp_account_manager_enable_restart
 tp_account_manager_get_feature_quark_core
 tp_account_manager_get_most_available_presence
 tp_account_manager_get_type
-tp_account_manager_new
-tp_account_manager_new_with_factory
 tp_account_manager_set_all_requested_presences
-tp_account_manager_set_default
 tp_account_reconnect_async
 tp_account_reconnect_finish
 tp_account_remove_async
diff --git a/tests/dbus/account-manager.c b/tests/dbus/account-manager.c
index 42d3803..2bd254d 100644
--- a/tests/dbus/account-manager.c
+++ b/tests/dbus/account-manager.c
@@ -47,6 +47,19 @@ typedef struct {
     GError *error /* initialized where needed */;
 } Test;
 
+static TpAccountManager *
+account_manager_new (TpDBusDaemon *dbus)
+{
+  TpClientFactory *factory;
+  TpAccountManager *am;
+
+  factory = tp_client_factory_new (dbus);
+  am = tp_client_factory_dup_account_manager (factory);
+  g_object_unref (factory);
+
+  return am;
+}
+
 /**
   * Functions for manipulating scripts follow this comment.
   * In order to be generally useful, the script should probably be stored in its
@@ -229,7 +242,7 @@ static void
 test_new (Test *test,
     gconstpointer data G_GNUC_UNUSED)
 {
-  test->am = tp_account_manager_new (test->dbus);
+  test->am = account_manager_new (test->dbus);
 }
 
 static void
@@ -298,7 +311,7 @@ manager_new_action (gpointer script_data,
 {
   Test *test = (Test *) script_data;
 
-  test->am = tp_account_manager_new (test->dbus);
+  test->am = account_manager_new (test->dbus);
   script_continue (test);
 }
 
diff --git a/tests/dbus/simple-approver.c b/tests/dbus/simple-approver.c
index d61e9df..714b62a 100644
--- a/tests/dbus/simple-approver.c
+++ b/tests/dbus/simple-approver.c
@@ -75,7 +75,7 @@ setup (Test *test,
   tp_dbus_daemon_register_object (test->dbus, ACCOUNT_PATH,
       test->account_service);
 
-  test->account_manager = tp_account_manager_new (test->dbus);
+  test->account_manager = tp_account_manager_dup ();
   g_assert (test->account_manager != NULL);
 
    /* Create client-side Account object */

-- 
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