[telepathy-mission-control/master] _mcd_account_online_request: remove confusing error handling

Simon McVittie simon.mcvittie at collabora.co.uk
Fri Apr 3 07:00:07 PDT 2009


This function had two ways to signal error (giving it to the callback,
or returning it immediately) but only actually used the former. Documenting
that this is the only way an error can happen results in an immediate
simplification in account-requests.
---
 src/mcd-account-priv.h     |    7 +++----
 src/mcd-account-requests.c |   19 +++----------------
 src/mcd-account.c          |   16 ++++++----------
 3 files changed, 12 insertions(+), 30 deletions(-)

diff --git a/src/mcd-account-priv.h b/src/mcd-account-priv.h
index 96e7b11..ac669d1 100644
--- a/src/mcd-account-priv.h
+++ b/src/mcd-account-priv.h
@@ -47,10 +47,9 @@ void _mcd_account_connect (McdAccount *account, GHashTable *params);
 
 typedef void (*McdOnlineRequestCb) (McdAccount *account, gpointer userdata,
 				    const GError *error);
-gboolean _mcd_account_online_request (McdAccount *account,
-                                      McdOnlineRequestCb callback,
-                                      gpointer userdata,
-                                      GError **imm_error);
+void _mcd_account_online_request (McdAccount *account,
+                                  McdOnlineRequestCb callback,
+                                  gpointer userdata);
 void _mcd_account_request_connection (McdAccount *account);
 G_GNUC_INTERNAL
 void _mcd_account_online_request_completed (McdAccount *account,
diff --git a/src/mcd-account-requests.c b/src/mcd-account-requests.c
index 85504d9..fb5af1a 100644
--- a/src/mcd-account-requests.c
+++ b/src/mcd-account-requests.c
@@ -184,22 +184,9 @@ create_request (McdAccount *account, GHashTable *properties,
     g_signal_connect_after (channel, "status-changed",
                             G_CALLBACK (on_channel_status_changed), account);
 
-    _mcd_account_online_request (account, online_request_cb, channel, error);
-    if (*error)
-    {
-        g_warning ("_mcd_account_online_request: %s",
-                   (*error)->message);
-        mcd_channel_take_error (channel, g_error_copy (*error));
-        /* no unref here, as this will invoke our handler which will
-         * unreference the channel */
-        channel = NULL;
-    }
-    else
-    {
-        /* the channel must be kept alive until online_request_cb is called;
-         * this reference will be removed in that callback */
-        g_object_ref (channel);
-    }
+    /* the callback releases this reference */
+    _mcd_account_online_request (account, online_request_cb,
+                                 g_object_ref (channel));
 
     return channel;
 }
diff --git a/src/mcd-account.c b/src/mcd-account.c
index ae15e15..776a47b 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -2301,29 +2301,26 @@ _mcd_account_request_connection (McdAccount *account)
  * @account: the #McdAccount.
  * @callback: a #McdOnlineRequestCb.
  * @userdata: user data to be passed to @callback.
- * @imm_error: pointer to a #GError location, or %NULL.
  *
- * If the account is online, call @callbeck immediately; else, try to put the
+ * If the account is online, call @callback immediately; else, try to put the
  * account online (set its presence to the automatic presence) and eventually
  * invoke @callback.
  *
- * Returns: %TRUE if @callback was/will be invoked, %FALSE otherwise.
+ * @callback is always invoked exactly once.
  */
-gboolean
+void
 _mcd_account_online_request (McdAccount *account,
                              McdOnlineRequestCb callback,
-                             gpointer userdata,
-                             GError **imm_error)
+                             gpointer userdata)
 {
     McdAccountPrivate *priv = account->priv;
-    GError *error = NULL;
 
     DEBUG ("connection status for %s is %d",
            priv->unique_name, priv->conn_status);
     if (priv->conn_status == TP_CONNECTION_STATUS_CONNECTED)
     {
-	/* invoke the callback now */
-	callback (account, userdata, error);
+        /* invoke the callback now */
+        callback (account, userdata, NULL);
     }
     else
     {
@@ -2340,7 +2337,6 @@ _mcd_account_online_request (McdAccount *account,
         data->user_data = userdata;
         priv->online_requests = g_list_append (priv->online_requests, data);
     }
-    return TRUE;
 }
 
 GKeyFile *
-- 
1.5.6.5




More information about the telepathy-commits mailing list