[gvfs/wip/oholy/gtask: 39/44] proxy: Port GProxyMount to GTask



commit c954161a85c9ef936ca78f6fe24f2b446cbf8b64
Author: Ondrej Holy <oholy redhat com>
Date:   Tue Jul 26 08:48:24 2016 +0200

    proxy: Port GProxyMount to GTask
    
    GSimpleAsyncResult is deprecated in favour of GTask and should be replaced.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=747412

 monitor/proxy/gproxymount.c |  118 ++++++++++++++++++-------------------------
 1 files changed, 49 insertions(+), 69 deletions(-)
---
diff --git a/monitor/proxy/gproxymount.c b/monitor/proxy/gproxymount.c
index 73af376..4863df7 100644
--- a/monitor/proxy/gproxymount.c
+++ b/monitor/proxy/gproxymount.c
@@ -455,18 +455,24 @@ g_proxy_mount_eject_finish (GMount        *mount,
 }
 
 typedef struct {
-  GProxyMount *mount;
-  GAsyncReadyCallback callback;
-  gpointer user_data;
-
   gchar *cancellation_id;
-  GCancellable *cancellable;
   gulong cancelled_handler_id;
 
   const gchar *mount_op_id;
 } DBusOp;
 
 static void
+dbus_op_free (DBusOp *data)
+{
+  g_free (data->cancellation_id);
+
+  if (data->mount_op_id)
+    g_proxy_mount_operation_destroy (data->mount_op_id);
+
+  g_free (data);
+}
+
+static void
 cancel_operation_reply_cb (GVfsRemoteVolumeMonitor *proxy,
                            GAsyncResult *res,
                            gpointer user_data)
@@ -488,23 +494,15 @@ static void
 operation_cancelled (GCancellable *cancellable,
                      gpointer      user_data)
 {
-  DBusOp *data = user_data;
-  GSimpleAsyncResult *simple;
+  GTask *task = G_TASK (user_data);
+  DBusOp *data = g_task_get_task_data (task);
+  GProxyMount *mount = G_PROXY_MOUNT (g_task_get_source_object (task));
   GVfsRemoteVolumeMonitor *proxy;
 
   G_LOCK (proxy_mount);
 
-  simple = g_simple_async_result_new_error (G_OBJECT (data->mount),
-                                            data->callback,
-                                            data->user_data,
-                                            G_IO_ERROR,
-                                            G_IO_ERROR_CANCELLED,
-                                            _("Operation was cancelled"));
-  g_simple_async_result_complete_in_idle (simple);
-  g_object_unref (simple);
-
   /* Now tell the remote volume monitor that the op has been cancelled */
-  proxy = g_proxy_volume_monitor_get_dbus_proxy (data->mount->volume_monitor);
+  proxy = g_proxy_volume_monitor_get_dbus_proxy (mount->volume_monitor);
   gvfs_remote_volume_monitor_call_cancel_operation (proxy,
                                                     data->cancellation_id,
                                                     NULL,
@@ -513,6 +511,8 @@ operation_cancelled (GCancellable *cancellable,
   g_object_unref (proxy);
 
   G_UNLOCK (proxy_mount);
+
+  g_task_return_error_if_cancelled (task);
 }
 
 static void
@@ -520,7 +520,8 @@ unmount_cb (GVfsRemoteVolumeMonitor *proxy,
             GAsyncResult *res,
             gpointer user_data)
 {
-  DBusOp *data = user_data;
+  GTask *task = G_TASK (user_data);
+  DBusOp *data = g_task_get_task_data (task);
   GError *error = NULL;
 
   gvfs_remote_volume_monitor_call_mount_unmount_finish (proxy, 
@@ -528,36 +529,23 @@ unmount_cb (GVfsRemoteVolumeMonitor *proxy,
                                                         &error);
 
   if (data->cancelled_handler_id > 0)
-    g_signal_handler_disconnect (data->cancellable, data->cancelled_handler_id);
+    g_signal_handler_disconnect (g_task_get_cancellable (task), data->cancelled_handler_id);
 
-  if (!g_cancellable_is_cancelled (data->cancellable))
+  if (!g_cancellable_is_cancelled (g_task_get_cancellable (task)))
     {
-      GSimpleAsyncResult *simple;
       if (error != NULL)
         {
           g_dbus_error_strip_remote_error (error);
-          simple = g_simple_async_result_new_from_error (G_OBJECT (data->mount),
-                                                         data->callback,
-                                                         data->user_data,
-                                                         error);
+          g_task_return_error (task, error);
+          error = NULL;
         }
       else
         {
-          simple = g_simple_async_result_new (G_OBJECT (data->mount),
-                                              data->callback,
-                                              data->user_data,
-                                              NULL);
+          g_task_return_boolean (task, TRUE);
         }
-      g_simple_async_result_complete (simple);
-      g_object_unref (simple);
     }
 
-  g_proxy_mount_operation_destroy (data->mount_op_id);
-  g_object_unref (data->mount);
-  g_free (data->cancellation_id);
-  if (data->cancellable != NULL)
-    g_object_unref (data->cancellable);
-  g_free (data);
+  g_object_unref (task);
   if (error != NULL)
     g_error_free (error);
 }
@@ -573,44 +561,39 @@ g_proxy_mount_unmount_with_operation (GMount              *mount,
   GProxyMount *proxy_mount = G_PROXY_MOUNT (mount);
   DBusOp *data;
   GVfsRemoteVolumeMonitor *proxy;
+  GTask *task;
 
   G_LOCK (proxy_mount);
 
+  task = g_task_new (mount, cancellable, callback, user_data);
+
   if (g_cancellable_is_cancelled (cancellable))
     {
-      GSimpleAsyncResult *simple;
-      simple = g_simple_async_result_new_error (G_OBJECT (mount),
-                                                callback,
-                                                user_data,
-                                                G_IO_ERROR,
-                                                G_IO_ERROR_CANCELLED,
-                                                _("Operation was cancelled"));
-      g_simple_async_result_complete_in_idle (simple);
-      g_object_unref (simple);
       G_UNLOCK (proxy_mount);
-      goto out;
+
+      g_task_return_error_if_cancelled (task);
+      g_object_unref (task);
+      return;
     }
 
   data = g_new0 (DBusOp, 1);
-  data->mount = g_object_ref (mount);
-  data->callback = callback;
-  data->user_data = user_data;
   data->mount_op_id = g_proxy_mount_operation_wrap (mount_operation, proxy_mount->volume_monitor);
 
   if (cancellable != NULL)
     {
       data->cancellation_id = g_strdup_printf ("%p", cancellable);
-      data->cancellable = g_object_ref (cancellable);
-      data->cancelled_handler_id = g_signal_connect (data->cancellable,
+      data->cancelled_handler_id = g_signal_connect (cancellable,
                                                      "cancelled",
                                                      G_CALLBACK (operation_cancelled),
-                                                     data);
+                                                     task);
     }
   else
     {
       data->cancellation_id = g_strdup ("");
     }
-  
+
+  g_task_set_task_data (task, data, (GDestroyNotify)dbus_op_free);
+
   proxy = g_proxy_volume_monitor_get_dbus_proxy (proxy_mount->volume_monitor);
   g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), G_PROXY_VOLUME_MONITOR_DBUS_TIMEOUT);  /* 30 
minute timeout */
 
@@ -621,14 +604,12 @@ g_proxy_mount_unmount_with_operation (GMount              *mount,
                                                  data->mount_op_id,
                                                  NULL,
                                                  (GAsyncReadyCallback) unmount_cb,
-                                                 data);
+                                                 task);
 
   g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), -1);
   g_object_unref (proxy);
 
   G_UNLOCK (proxy_mount);
- out:
-  ;
 }
 
 static gboolean
@@ -636,9 +617,9 @@ g_proxy_mount_unmount_with_operation_finish (GMount        *mount,
                                              GAsyncResult  *result,
                                              GError       **error)
 {
-  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
-    return FALSE;
-  return TRUE;
+  g_return_val_if_fail (g_task_is_valid (result, mount), FALSE);
+
+  return g_task_propagate_boolean (G_TASK (result), error);
 }
 
 static void
@@ -666,15 +647,13 @@ g_proxy_mount_guess_content_type (GMount              *mount,
                                   GAsyncReadyCallback  callback,
                                   gpointer             user_data)
 {
-  GSimpleAsyncResult *simple;
+  GTask *task;
+  GProxyMount *proxy_mount = G_PROXY_MOUNT (mount);
 
   /* TODO: handle force_rescan */
-  simple = g_simple_async_result_new (G_OBJECT (mount),
-                                      callback,
-                                      user_data,
-                                      NULL);
-  g_simple_async_result_complete_in_idle (simple);
-  g_object_unref (simple);
+  task = g_task_new (G_OBJECT (mount), cancellable, callback, user_data);
+  g_task_return_pointer (task, g_strdupv (proxy_mount->x_content_types), (GDestroyNotify)g_strfreev);
+  g_object_unref (task);
 }
 
 static char **
@@ -682,8 +661,9 @@ g_proxy_mount_guess_content_type_finish (GMount              *mount,
                                          GAsyncResult        *result,
                                          GError             **error)
 {
-  GProxyMount *proxy_mount = G_PROXY_MOUNT (mount);
-  return g_strdupv (proxy_mount->x_content_types);
+  g_return_val_if_fail (g_task_is_valid (result, mount), NULL);
+
+  return g_task_propagate_pointer (G_TASK (result), error);
 }
 
 static char **


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]