From a62c0648bcbf7347012197a8e68c6fad3f5b3ee9 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 14 Sep 2012 15:02:02 +0100 Subject: [PATCH 15/21] McdAccountManager: have a TpSimpleClientFactory Signed-off-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=55391 --- src/mcd-account-manager.c | 43 +++++++++++++++++++++++++++++++++---------- src/mcd-account-manager.h | 3 ++- src/mcd-master.c | 8 ++++++-- 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/mcd-account-manager.c b/src/mcd-account-manager.c index ff05c36..5032379 100644 --- a/src/mcd-account-manager.c +++ b/src/mcd-account-manager.c @@ -88,8 +88,8 @@ G_DEFINE_TYPE_WITH_CODE (McdAccountManager, mcd_account_manager, G_TYPE_OBJECT, struct _McdAccountManagerPrivate { - /* DBUS connection */ TpDBusDaemon *dbus_daemon; + TpSimpleClientFactory *client_factory; McdStorage *storage; GHashTable *accounts; @@ -131,6 +131,7 @@ enum { PROP_0, PROP_DBUS_DAEMON, + PROP_CLIENT_FACTORY }; static guint write_conf_id = 0; @@ -591,15 +592,23 @@ list_connection_names_cb (const gchar * const *names, gsize n, { /* Close the connection */ TpConnection *proxy; + gchar *path; + + path = g_strdup_printf ("/%s", names[i]); + g_strdelimit (path, ".", '/'); DEBUG ("Killing connection"); - proxy = tp_connection_new (priv->dbus_daemon, names[i], NULL, NULL); + proxy = tp_simple_client_factory_ensure_connection ( + priv->client_factory, path, NULL, NULL); + if (proxy) { tp_cli_connection_call_disconnect (proxy, -1, NULL, NULL, NULL, NULL); g_object_unref (proxy); } + + g_free (path); } } g_free (contents); @@ -1508,10 +1517,15 @@ set_property (GObject *obj, guint prop_id, switch (prop_id) { - case PROP_DBUS_DAEMON: - tp_clear_object (&priv->dbus_daemon); - priv->dbus_daemon = TP_DBUS_DAEMON (g_value_dup_object (val)); - break; + case PROP_CLIENT_FACTORY: + g_assert (priv->client_factory == NULL); /* construct-only */ + priv->client_factory = + TP_SIMPLE_CLIENT_FACTORY (g_value_dup_object (val)); + priv->dbus_daemon = + tp_simple_client_factory_get_dbus_daemon (priv->client_factory); + g_object_ref (priv->dbus_daemon); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); break; @@ -1562,6 +1576,7 @@ _mcd_account_manager_dispose (GObject *object) McdAccountManagerPrivate *priv = MCD_ACCOUNT_MANAGER_PRIV (object); tp_clear_object (&priv->dbus_daemon); + tp_clear_object (&priv->client_factory); G_OBJECT_CLASS (mcd_account_manager_parent_class)->dispose (object); } @@ -1582,7 +1597,15 @@ mcd_account_manager_class_init (McdAccountManagerClass *klass) (object_class, PROP_DBUS_DAEMON, g_param_spec_object ("dbus-daemon", "DBus daemon", "DBus daemon", TP_TYPE_DBUS_DAEMON, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + G_PARAM_READABLE)); + + g_object_class_install_property + (object_class, PROP_CLIENT_FACTORY, + g_param_spec_object ("client-factory", + "Client factory", + "Client factory", + TP_TYPE_SIMPLE_CLIENT_FACTORY, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); } static const gchar * @@ -1655,13 +1678,13 @@ _mcd_account_manager_constructed (GObject *obj) } McdAccountManager * -mcd_account_manager_new (TpDBusDaemon *dbus_daemon) +mcd_account_manager_new (TpSimpleClientFactory *client_factory) { gpointer *obj; obj = g_object_new (MCD_TYPE_ACCOUNT_MANAGER, - "dbus-daemon", dbus_daemon, - NULL); + "client-factory", client_factory, + NULL); return MCD_ACCOUNT_MANAGER (obj); } diff --git a/src/mcd-account-manager.h b/src/mcd-account-manager.h index 373dffa..8241082 100644 --- a/src/mcd-account-manager.h +++ b/src/mcd-account-manager.h @@ -59,7 +59,8 @@ struct _McdAccountManagerClass }; GType mcd_account_manager_get_type (void); -McdAccountManager *mcd_account_manager_new (TpDBusDaemon *dbus_daemon); +McdAccountManager *mcd_account_manager_new ( + TpSimpleClientFactory *client_factory); TpDBusDaemon *mcd_account_manager_get_dbus_daemon (McdAccountManager *account_manager); diff --git a/src/mcd-master.c b/src/mcd-master.c index c7f1d97..22ee8c2 100644 --- a/src/mcd-master.c +++ b/src/mcd-master.c @@ -94,8 +94,9 @@ typedef struct _McdMasterPrivate McdAccountManager *account_manager; McdDispatcher *dispatcher; - /* We create this for our member objects */ + /* We create these for our member objects */ TpDBusDaemon *dbus_daemon; + TpSimpleClientFactory *client_factory; GPtrArray *transport_plugins; GList *account_connections; @@ -352,6 +353,7 @@ _mcd_master_dispose (GObject * object) tp_clear_object (&priv->account_manager); tp_clear_object (&priv->dbus_daemon); tp_clear_object (&priv->dispatcher); + tp_clear_object (&priv->client_factory); if (default_master == (McdMaster *) object) { @@ -379,8 +381,10 @@ mcd_master_constructor (GType type, guint n_params, umask (0077); #endif + priv->client_factory = tp_simple_client_factory_new (priv->dbus_daemon); + if (!priv->account_manager) - priv->account_manager = mcd_account_manager_new (priv->dbus_daemon); + priv->account_manager = mcd_account_manager_new (priv->client_factory); priv->dispatcher = mcd_dispatcher_new (priv->dbus_daemon, master); g_assert (MCD_IS_DISPATCHER (priv->dispatcher)); -- 1.7.10.4