telepathy-glib: account-channel-request: factor out going_to_request()

Guillaume Desmottes gdesmott at kemper.freedesktop.org
Wed Feb 26 01:31:20 PST 2014


Module: telepathy-glib
Branch: master
Commit: c3beedcc25d4db5eb8d70581ddf6a06eb05bb951
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=c3beedcc25d4db5eb8d70581ddf6a06eb05bb951

Author: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Date:   Tue Feb 25 14:56:57 2014 +0100

account-channel-request: factor out going_to_request()

---

 telepathy-glib/account-channel-request.c |   77 +++++++++++++-----------------
 1 file changed, 32 insertions(+), 45 deletions(-)

diff --git a/telepathy-glib/account-channel-request.c b/telepathy-glib/account-channel-request.c
index b2908c5..fe9954d 100644
--- a/telepathy-glib/account-channel-request.c
+++ b/telepathy-glib/account-channel-request.c
@@ -1000,34 +1000,49 @@ delegated_channels_cb (TpBaseClient *client,
       self->priv->delegated_channel_data);
 }
 
-static void
-request_and_handle_channel_async (TpAccountChannelRequest *self,
+static gboolean
+going_to_request (TpAccountChannelRequest *self,
+    ActionType action_type,
+    gboolean ensure,
     GCancellable *cancellable,
     GAsyncReadyCallback callback,
-    gpointer user_data,
-    gboolean ensure)
+    gpointer user_data)
 {
-  GError *error = NULL;
-  TpChannelDispatcher *cd;
-
-  g_return_if_fail (!self->priv->requested);
+  g_return_val_if_fail (!self->priv->requested, FALSE);
   self->priv->requested = TRUE;
 
-  self->priv->action_type = ACTION_TYPE_HANDLE;
+  self->priv->action_type = action_type;
 
   if (g_cancellable_is_cancelled (cancellable))
     {
       g_simple_async_report_error_in_idle (G_OBJECT (self), callback,
           user_data, G_IO_ERROR, G_IO_ERROR_CANCELLED,
           "Operation has been cancelled");
-
-      return;
+      return FALSE;
     }
 
   if (cancellable != NULL)
     self->priv->cancellable = g_object_ref (cancellable);
+
   self->priv->ensure = ensure;
 
+  return TRUE;
+}
+
+static void
+request_and_handle_channel_async (TpAccountChannelRequest *self,
+    GCancellable *cancellable,
+    GAsyncReadyCallback callback,
+    gpointer user_data,
+    gboolean ensure)
+{
+  GError *error = NULL;
+  TpChannelDispatcher *cd;
+
+  if (!going_to_request (self, ACTION_TYPE_HANDLE, ensure, cancellable,
+        callback, user_data))
+    return;
+
   /* Create a temp handler */
   self->priv->handler = tp_simple_handler_new_with_factory (
       tp_proxy_get_factory (self->priv->account), TRUE, FALSE,
@@ -1293,23 +1308,9 @@ request_channel_async (TpAccountChannelRequest *self,
 {
   TpChannelDispatcher *cd;
 
-  g_return_if_fail (!self->priv->requested);
-  self->priv->requested = TRUE;
-
-  self->priv->action_type = ACTION_TYPE_FORGET;
-
-  if (g_cancellable_is_cancelled (cancellable))
-    {
-      g_simple_async_report_error_in_idle (G_OBJECT (self), callback,
-          user_data, G_IO_ERROR, G_IO_ERROR_CANCELLED,
-          "Operation has been cancelled");
-
-      return;
-    }
-
-  if (cancellable != NULL)
-    self->priv->cancellable = g_object_ref (cancellable);
-  self->priv->ensure = ensure;
+  if (!going_to_request (self, ACTION_TYPE_FORGET, ensure, cancellable,
+        callback, user_data))
+    return;
 
   cd = tp_channel_dispatcher_new (self->priv->dbus);
 
@@ -1560,23 +1561,9 @@ request_and_observe_channel_async (TpAccountChannelRequest *self,
 {
   TpChannelDispatcher *cd;
 
-  g_return_if_fail (!self->priv->requested);
-  self->priv->requested = TRUE;
-
-  self->priv->action_type = ACTION_TYPE_OBSERVE;
-
-  if (g_cancellable_is_cancelled (cancellable))
-    {
-      g_simple_async_report_error_in_idle (G_OBJECT (self), callback,
-          user_data, G_IO_ERROR, G_IO_ERROR_CANCELLED,
-          "Operation has been cancelled");
-
-      return;
-    }
-
-  if (cancellable != NULL)
-    self->priv->cancellable = g_object_ref (cancellable);
-  self->priv->ensure = ensure;
+  if (!going_to_request (self, ACTION_TYPE_OBSERVE, ensure, cancellable,
+        callback, user_data))
+    return;
 
   cd = tp_channel_dispatcher_new (self->priv->dbus);
 



More information about the telepathy-commits mailing list