[telepathy-mission-control/master] McdConnection: provide Connection status to McdAccount via a signal rather than calling methods
Simon McVittie
simon.mcvittie at collabora.co.uk
Thu Apr 16 08:24:32 PDT 2009
---
.../tmpl/mcd-connection.sgml | 9 ++++++
src/mcd-account-priv.h | 3 --
src/mcd-account.c | 16 +++++++---
src/mcd-connection.c | 31 ++++++++++++-------
4 files changed, 39 insertions(+), 20 deletions(-)
diff --git a/doc/reference/libmissioncontrol-server/tmpl/mcd-connection.sgml b/doc/reference/libmissioncontrol-server/tmpl/mcd-connection.sgml
index a1681d5..1465356 100644
--- a/doc/reference/libmissioncontrol-server/tmpl/mcd-connection.sgml
+++ b/doc/reference/libmissioncontrol-server/tmpl/mcd-connection.sgml
@@ -23,6 +23,15 @@ McdConnection
</para>
+<!-- ##### SIGNAL McdConnection::connection-status-changed ##### -->
+<para>
+
+</para>
+
+ at mcdconnection: the object which received the signal.
+ at arg1:
+ at arg2:
+
<!-- ##### SIGNAL McdConnection::self-presence-changed ##### -->
<para>
diff --git a/src/mcd-account-priv.h b/src/mcd-account-priv.h
index 953cea4..2db17f8 100644
--- a/src/mcd-account-priv.h
+++ b/src/mcd-account-priv.h
@@ -79,9 +79,6 @@ G_GNUC_INTERNAL void _mcd_account_load (McdAccount *account,
G_GNUC_INTERNAL void _mcd_account_set_connection (McdAccount *account,
McdConnection *connection);
-G_GNUC_INTERNAL void _mcd_account_set_connection_status (McdAccount *account,
- TpConnectionStatus status, TpConnectionStatusReason reason);
-
typedef void (*McdOnlineRequestCb) (McdAccount *account, gpointer userdata,
const GError *error);
void _mcd_account_online_request (McdAccount *account,
diff --git a/src/mcd-account.c b/src/mcd-account.c
index a7eefa7..d23a7e2 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -2224,10 +2224,11 @@ process_online_requests (McdAccount *account,
_mcd_account_online_request_completed (account, error);
}
-void
-_mcd_account_set_connection_status (McdAccount *account,
- TpConnectionStatus status,
- TpConnectionStatusReason reason)
+static void
+on_conn_status_changed (McdConnection *connection,
+ TpConnectionStatus status,
+ TpConnectionStatusReason reason,
+ McdAccount *account)
{
McdAccountPrivate *priv = MCD_ACCOUNT_PRIV (account);
gboolean changed = FALSE;
@@ -2381,7 +2382,7 @@ _mcd_account_online_request (McdAccount *account,
/* now the connection should be in connecting state; insert the
* callback in the online_requests hash table, which will be processed
- * in the _mcd_account_set_connection_status function */
+ * in the connection-status-changed callback */
data = g_slice_new (McdOnlineRequestData);
data->callback = callback;
data->user_data = userdata;
@@ -2436,6 +2437,9 @@ _mcd_account_set_connection (McdAccount *account, McdConnection *connection)
g_signal_handlers_disconnect_by_func (priv->connection,
on_conn_self_presence_changed,
account);
+ g_signal_handlers_disconnect_by_func (priv->connection,
+ on_conn_status_changed,
+ account);
g_object_unref (priv->connection);
}
priv->connection = connection;
@@ -2445,6 +2449,8 @@ _mcd_account_set_connection (McdAccount *account, McdConnection *connection)
g_object_ref (connection);
g_signal_connect (connection, "self-presence-changed",
G_CALLBACK (on_conn_self_presence_changed), account);
+ g_signal_connect (connection, "connection-status-changed",
+ G_CALLBACK (on_conn_status_changed), account);
g_signal_connect (connection, "abort",
G_CALLBACK (on_connection_abort), account);
}
diff --git a/src/mcd-connection.c b/src/mcd-connection.c
index 092b957..a8ca93d 100644
--- a/src/mcd-connection.c
+++ b/src/mcd-connection.c
@@ -170,6 +170,7 @@ enum
enum
{
SELF_PRESENCE_CHANGED,
+ CONNECTION_STATUS_CHANGED,
N_SIGNALS
};
@@ -1099,15 +1100,15 @@ on_connection_status_changed (TpConnection *tp_conn, GParamSpec *pspec,
switch (conn_status)
{
case TP_CONNECTION_STATUS_CONNECTING:
- _mcd_account_set_connection_status (priv->account,
- conn_status, conn_reason);
+ g_signal_emit (connection, signals[CONNECTION_STATUS_CHANGED], 0,
+ conn_status, conn_reason);
priv->abort_reason = TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED;
break;
case TP_CONNECTION_STATUS_CONNECTED:
{
- _mcd_account_set_connection_status (priv->account,
- conn_status, conn_reason);
+ g_signal_emit (connection, signals[CONNECTION_STATUS_CHANGED], 0,
+ conn_status, conn_reason);
priv->reconnect_interval = INITIAL_RECONNECTION_TIME;
}
break;
@@ -1571,7 +1572,7 @@ request_connection_cb (TpConnectionManager *proxy, const gchar *bus_name,
g_warning ("%s: RequestConnection failed: %s",
G_STRFUNC, tperror->message);
- _mcd_account_set_connection_status (priv->account,
+ g_signal_emit (connection, signals[CONNECTION_STATUS_CHANGED], 0,
TP_CONNECTION_STATUS_DISCONNECTED,
TP_CONNECTION_STATUS_REASON_NETWORK_ERROR);
return;
@@ -1606,9 +1607,9 @@ _mcd_connection_connect_with_params (McdConnection *connection,
DEBUG ("Trying connect account: %s",
mcd_account_get_unique_name (priv->account));
- _mcd_account_set_connection_status (priv->account,
- TP_CONNECTION_STATUS_CONNECTING,
- TP_CONNECTION_STATUS_REASON_REQUESTED);
+ g_signal_emit (connection, signals[CONNECTION_STATUS_CHANGED], 0,
+ TP_CONNECTION_STATUS_CONNECTING,
+ TP_CONNECTION_STATUS_REASON_REQUESTED);
/* TODO: add extra parameters? */
tp_cli_connection_manager_call_request_connection (priv->tp_conn_mgr, -1,
@@ -1645,9 +1646,9 @@ _mcd_connection_release_tp_connection (McdConnection *connection)
DEBUG ("%p", connection);
g_signal_emit (connection, signals[SELF_PRESENCE_CHANGED], 0,
TP_CONNECTION_PRESENCE_TYPE_OFFLINE, "offline", "");
- _mcd_account_set_connection_status (priv->account,
- TP_CONNECTION_STATUS_DISCONNECTED,
- priv->abort_reason);
+ g_signal_emit (connection, signals[CONNECTION_STATUS_CHANGED], 0,
+ TP_CONNECTION_STATUS_DISCONNECTED,
+ priv->abort_reason);
if (priv->tp_conn)
{
/* Disconnect signals */
@@ -1966,6 +1967,12 @@ mcd_connection_class_init (McdConnectionClass * klass)
G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, 0,
NULL, NULL, _mcd_marshal_VOID__UINT_STRING_STRING,
G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
+
+ signals[CONNECTION_STATUS_CHANGED] = g_signal_new (
+ "connection-status-changed", G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED, 0,
+ NULL, NULL, _mcd_marshal_VOID__UINT_UINT,
+ G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
}
static void
@@ -2568,7 +2575,7 @@ _mcd_connection_set_tp_connection (McdConnection *connection,
obj_path, error);
if (!priv->tp_conn)
{
- _mcd_account_set_connection_status (priv->account,
+ g_signal_emit (connection, signals[CONNECTION_STATUS_CHANGED], 0,
TP_CONNECTION_STATUS_DISCONNECTED,
TP_CONNECTION_STATUS_REASON_NETWORK_ERROR);
return;
--
1.5.6.5
More information about the telepathy-commits
mailing list