[Telepathy-commits] [telepathy-mission-control/master] Fix online requests
Alberto Mardegan
alberto.mardegan at nokia.com
Mon Dec 1 08:37:13 PST 2008
Online requests can be proceed asynchronously, so we can not expect
priv->connection to be immediately set.
Implement handling of asynchronous errors.
---
src/mcd-account-connection.c | 9 +++++++
src/mcd-account-priv.h | 3 ++
src/mcd-account.c | 48 +++++++++++++++++++++--------------------
3 files changed, 37 insertions(+), 23 deletions(-)
diff --git a/src/mcd-account-connection.c b/src/mcd-account-connection.c
index 1d46fa4..833ba7e 100644
--- a/src/mcd-account-connection.c
+++ b/src/mcd-account-connection.c
@@ -103,6 +103,15 @@ mcd_account_connection_proceed (McdAccount *account, gboolean success)
{
_mcd_account_connect (account, ctx->params);
}
+ else
+ {
+ GError *error;
+
+ error = g_error_new (TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
+ "Plugins refused connection to account %s",
+ mcd_account_get_unique_name (account));
+ _mcd_account_online_request_completed (account, error);
+ }
g_object_set_qdata ((GObject *)account,
account_connection_context_quark, NULL);
}
diff --git a/src/mcd-account-priv.h b/src/mcd-account-priv.h
index bd27e41..7fd4ada 100644
--- a/src/mcd-account-priv.h
+++ b/src/mcd-account-priv.h
@@ -51,6 +51,9 @@ gboolean _mcd_account_online_request (McdAccount *account,
gpointer userdata,
GError **imm_error);
void _mcd_account_request_connection (McdAccount *account);
+G_GNUC_INTERNAL
+void _mcd_account_online_request_completed (McdAccount *account,
+ GError *error);
#endif /* __MCD_ACCOUNT_PRIV_H__ */
diff --git a/src/mcd-account.c b/src/mcd-account.c
index 9d7f43d..33b82af 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -1928,38 +1928,47 @@ mcd_account_get_alias (McdAccount *account)
MC_ACCOUNTS_KEY_ALIAS, NULL);
}
+void
+_mcd_account_online_request_completed (McdAccount *account, GError *error)
+{
+ McdAccountPrivate *priv = MCD_ACCOUNT_PRIV (account);
+ McdOnlineRequestData data;
+
+ if (!priv->online_requests) return;
+
+ data.error = error;
+ data.account = account;
+ g_hash_table_foreach (priv->online_requests,
+ process_online_request,
+ &data);
+ if (error)
+ g_error_free (error);
+ g_hash_table_destroy (priv->online_requests);
+ priv->online_requests = NULL;
+}
+
static inline void
process_online_requests (McdAccount *account,
TpConnectionStatus status,
TpConnectionStatusReason reason)
{
McdAccountPrivate *priv = MCD_ACCOUNT_PRIV (account);
- McdOnlineRequestData data;
-
- if (!priv->online_requests) return;
+ GError *error;
switch (status)
{
case TP_CONNECTION_STATUS_CONNECTED:
- data.error = NULL;
+ error = NULL;
break;
case TP_CONNECTION_STATUS_DISCONNECTED:
- data.error = NULL;
- g_set_error (&data.error, TP_ERRORS, TP_ERROR_DISCONNECTED,
- "Account %s disconnected with reason %d",
- priv->unique_name, reason);
+ error = g_error_new (TP_ERRORS, TP_ERROR_DISCONNECTED,
+ "Account %s disconnected with reason %d",
+ priv->unique_name, reason);
break;
default:
return;
}
- data.account = account;
- g_hash_table_foreach (priv->online_requests,
- process_online_request,
- &data);
- if (data.error)
- g_error_free (data.error);
- g_hash_table_destroy (priv->online_requests);
- priv->online_requests = NULL;
+ _mcd_account_online_request_completed (account, error);
}
void
@@ -2110,13 +2119,6 @@ _mcd_account_online_request (McdAccount *account,
/* listen to the StatusChanged signal */
if (priv->conn_status == TP_CONNECTION_STATUS_DISCONNECTED)
_mcd_account_request_connection (account);
- if (!priv->connection)
- {
- g_set_error (imm_error, TP_ERRORS, TP_ERROR_NOT_AVAILABLE,
- "Could not create a connection for account %s",
- priv->unique_name);
- return FALSE;
- }
/* now the connection should be in connecting state; insert the
* callback in the online_requests hash table, which will be processed
--
1.5.6.5
More information about the Telepathy-commits
mailing list