From b83def2e805e7583149eaab7a2162da2c8c4be73 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 29 Aug 2013 16:41:22 +0100 Subject: [PATCH 12/16] McdAccount: respond to connectivity status changes Instead of proxying through the transport plugin and the McdMaster, just watch the McdConnectivityMonitor. Much simpler! --- src/connectivity-monitor.c | 5 ++- src/kludge-transport.c | 20 --------- src/mcd-account.c | 28 ++++++++++++ src/mcd-master.c | 108 --------------------------------------------- 4 files changed, 32 insertions(+), 129 deletions(-) diff --git a/src/connectivity-monitor.c b/src/connectivity-monitor.c index 3bf428d..7015ef2 100644 --- a/src/connectivity-monitor.c +++ b/src/connectivity-monitor.c @@ -109,7 +109,10 @@ connectivity_monitor_change_states ( priv->connectivity = connectivity; if (old_total != new_total) - g_signal_emit (self, signals[STATE_CHANGE], 0, new_total); + { + DEBUG ("%s", new_total ? "connected" : "disconnected"); + g_signal_emit (self, signals[STATE_CHANGE], 0, new_total); + } } #ifdef HAVE_NM diff --git a/src/kludge-transport.c b/src/kludge-transport.c index 06c30a2..664b8c3 100644 --- a/src/kludge-transport.c +++ b/src/kludge-transport.c @@ -45,10 +45,6 @@ struct _McdKludgeTransportPrivate { static void transport_iface_init ( gpointer g_iface, gpointer iface_data); -static void monitor_state_changed_cb ( - McdConnectivityMonitor *monitor, - gboolean connected, - gpointer user_data); G_DEFINE_TYPE_WITH_CODE (McdKludgeTransport, mcd_kludge_transport, G_TYPE_OBJECT, @@ -158,20 +154,6 @@ transport_iface_init ( klass->get_transport_status = mcd_kludge_transport_get_transport_status; } -static void -monitor_state_changed_cb ( - McdConnectivityMonitor *monitor, - gboolean connected, - gpointer user_data) -{ - McdKludgeTransport *self = MCD_KLUDGE_TRANSPORT (user_data); - McdTransportStatus new_status = - connected ? MCD_TRANSPORT_STATUS_CONNECTED - : MCD_TRANSPORT_STATUS_DISCONNECTED; - - g_signal_emit_by_name (self, "status-changed", self, new_status); -} - static McdTransportPlugin * mcd_kludge_transport_new (McdConnectivityMonitor *connectivity_monitor) { @@ -180,8 +162,6 @@ mcd_kludge_transport_new (McdConnectivityMonitor *connectivity_monitor) /* Strictly speaking this should be done with properties, but I'm * going to delete this class soon anyway. */ self->priv->minotaur = connectivity_monitor; - tp_g_signal_connect_object (self->priv->minotaur, "state-change", - (GCallback) monitor_state_changed_cb, self, 0); return MCD_TRANSPORT_PLUGIN (self); } diff --git a/src/mcd-account.c b/src/mcd-account.c index 863ece6..5d4837d 100644 --- a/src/mcd-account.c +++ b/src/mcd-account.c @@ -3609,6 +3609,34 @@ monitor_state_changed_cb ( { McdAccount *self = MCD_ACCOUNT (user_data); + if (connected) + { + if (mcd_account_would_like_to_connect (self)) + { + DEBUG ("account %s would like to connect", + self->priv->unique_name); + _mcd_account_connect_with_auto_presence (self, FALSE); + } + } + else + { + if (_mcd_account_needs_dispatch (self)) + { + /* special treatment for cellular accounts */ + DEBUG ("account %s is always dispatched and does not need a " + "transport", self->priv->unique_name); + } + else + { + McdConnection *connection; + + DEBUG ("account %s must disconnect", self->priv->unique_name); + connection = mcd_account_get_connection (self); + if (connection) + mcd_connection_close (connection); + } + } + if (!self->priv->waiting_for_connectivity) return; diff --git a/src/mcd-master.c b/src/mcd-master.c index e673335..f1cbbf7 100644 --- a/src/mcd-master.c +++ b/src/mcd-master.c @@ -126,71 +126,6 @@ typedef struct { #define POISONED_MASTER ((McdMaster *) 0xdeadbeef) static McdMaster *default_master = NULL; - -static void -mcd_master_transport_connected (McdMaster *master, McdTransportPlugin *plugin, - McdTransport *transport) -{ - McdMasterPrivate *priv = master->priv; - GHashTable *accounts; - GHashTableIter iter; - gpointer v; - - DEBUG ("%s", mcd_transport_get_name (plugin, transport)); - - accounts = _mcd_account_manager_get_accounts (priv->account_manager); - g_hash_table_iter_init (&iter, accounts); - - while (g_hash_table_iter_next (&iter, NULL, &v)) - { - McdAccount *account = MCD_ACCOUNT (v); - - if (!mcd_account_would_like_to_connect (account)) - continue; - - DEBUG ("account %s would like to connect", - mcd_account_get_unique_name (account)); - _mcd_account_connect_with_auto_presence (account, FALSE); - } -} - -static void -mcd_master_transport_disconnected (McdMaster *master, McdTransportPlugin *plugin, - McdTransport *transport) -{ - McdMasterPrivate *priv = master->priv; - GHashTable *accounts; - GHashTableIter iter; - gpointer v; - - DEBUG ("%s", mcd_transport_get_name (plugin, transport)); - - accounts = _mcd_account_manager_get_accounts (priv->account_manager); - g_hash_table_iter_init (&iter, accounts); - - while (g_hash_table_iter_next (&iter, NULL, &v)) - { - McdAccount *account = MCD_ACCOUNT (v); - - if (_mcd_account_needs_dispatch (account)) - { - /* special treatment for cellular accounts */ - DEBUG ("account %s is always dispatched and does not need a " - "transport", mcd_account_get_unique_name (account)); - } - else - { - McdConnection *connection; - - DEBUG ("account %s must disconnect", - mcd_account_get_unique_name (account)); - connection = mcd_account_get_connection (account); - if (connection) - mcd_connection_close (connection); - } - } -} - static void mcd_master_connect_automatic_accounts (McdMaster *master) { @@ -207,43 +142,6 @@ mcd_master_connect_automatic_accounts (McdMaster *master) } } -static const gchar * -mcd_transport_status_to_string (McdTransportStatus status) -{ - switch (status) - { - case MCD_TRANSPORT_STATUS_CONNECTED: - return "connected"; - case MCD_TRANSPORT_STATUS_CONNECTING: - return "connecting"; - case MCD_TRANSPORT_STATUS_DISCONNECTED: - return "disconnected"; - case MCD_TRANSPORT_STATUS_DISCONNECTING: - return "disconnecting"; - } - - return "invalid"; -} - -static void -on_transport_status_changed (McdTransportPlugin *plugin, - McdTransport *transport, - McdTransportStatus status, McdMaster *master) -{ - DEBUG ("Transport %s changed status to %u (%s)", - mcd_transport_get_name (plugin, transport), status, - mcd_transport_status_to_string (status)); - - if (status == MCD_TRANSPORT_STATUS_CONNECTED) - mcd_master_transport_connected (master, plugin, transport); - else if (status == MCD_TRANSPORT_STATUS_DISCONNECTING || - status == MCD_TRANSPORT_STATUS_DISCONNECTED) - { - /* disconnect all accounts that were using this transport */ - mcd_master_transport_disconnected (master, plugin, transport); - } -} - static void _mcd_master_get_property (GObject * obj, guint prop_id, GValue * val, GParamSpec * pspec) @@ -308,9 +206,6 @@ _mcd_master_dispose (GObject * object) { McdTransportPlugin *plugin; plugin = g_ptr_array_index (priv->transport_plugins, i); - g_signal_handlers_disconnect_by_func (plugin, - on_transport_status_changed, - object); g_object_unref (plugin); } g_ptr_array_unref (priv->transport_plugins); @@ -507,9 +402,6 @@ mcd_master_register_transport (McdMaster *master, McdTransportPlugin *transport_plugin) { DEBUG ("called"); - g_signal_connect (transport_plugin, "status-changed", - G_CALLBACK (on_transport_status_changed), - master); g_ptr_array_add (master->priv->transport_plugins, transport_plugin); } -- 1.8.4.rc3