[gvfs/wip/oholy/gtask: 135/142] gdaemonmount: Port to GTask



commit f4c46e45388ac7d5280a8564b7d3ee00232e43f4
Author: Ondrej Holy <oholy redhat com>
Date:   Mon May 18 09:42:41 2015 +0200

    gdaemonmount: Port to GTask
    
    GSimpleAsyncResult is deprecated in favour of GTask and should be replaced.
    
    Based on patch from Dan Winship.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=747412

 client/gdaemonmount.c |  106 +++++++++++++++++++++++++++----------------------
 1 files changed, 58 insertions(+), 48 deletions(-)
---
diff --git a/client/gdaemonmount.c b/client/gdaemonmount.c
index a24a0f5..46c1a92 100644
--- a/client/gdaemonmount.c
+++ b/client/gdaemonmount.c
@@ -183,9 +183,6 @@ g_daemon_mount_can_eject (GMount *mount)
 
 
 typedef struct {
-  GMount *mount;
-  GCancellable *cancellable;
-  GSimpleAsyncResult *result;
   GMountInfo *mount_info;
   GMountOperation *mount_operation;
   GMountUnmountFlags flags;
@@ -197,9 +194,6 @@ typedef struct {
 static void
 async_proxy_create_free (AsyncProxyCreate *data)
 {
-  g_clear_object (&data->mount);
-  g_clear_object (&data->result);
-  g_clear_object (&data->cancellable);
   g_clear_object (&data->mount_operation);
   g_clear_object (&data->connection);
   g_clear_object (&data->proxy);
@@ -212,20 +206,27 @@ unmount_reply (GVfsDBusMount *proxy,
                gpointer user_data)
 {
   GDBusProxy *base_proxy = G_DBUS_PROXY (proxy);
-  AsyncProxyCreate *data = user_data;
+  GTask *task = G_TASK (user_data);
+  AsyncProxyCreate *data;
   GError *error = NULL;
 
+  data = g_task_get_task_data (task);
+
   _g_daemon_vfs_invalidate (g_dbus_proxy_get_name (base_proxy),
                             g_dbus_proxy_get_object_path (base_proxy));
 
   if (! gvfs_dbus_mount_call_unmount_finish (proxy, res, &error))
     {
-      _g_simple_async_result_take_error_stripped (data->result, error);
+      g_dbus_error_strip_remote_error (error);
+      g_task_return_error (task, error);
     }
-  
-  _g_simple_async_result_complete_with_cancellable (data->result, data->cancellable);
-  _g_dbus_async_unsubscribe_cancellable (data->cancellable, data->cancelled_tag);
-  async_proxy_create_free (data);
+  else
+    {
+      g_task_return_boolean (task, TRUE);
+    }
+
+  _g_dbus_async_unsubscribe_cancellable (g_task_get_cancellable (task), data->cancelled_tag);
+  g_object_unref (task);
 }
 
 static void
@@ -233,17 +234,20 @@ async_proxy_new_cb (GObject *source_object,
                     GAsyncResult *res,
                     gpointer user_data)
 {
-  AsyncProxyCreate *data = user_data;
+  GTask *task = G_TASK (user_data);
+  AsyncProxyCreate *data;
   GVfsDBusMount *proxy;
   GError *error = NULL;
   GMountSource *mount_source;
 
+  data = g_task_get_task_data (task);
+
   proxy = gvfs_dbus_mount_proxy_new_finish (res, &error);
   if (proxy == NULL)
     {
-      _g_simple_async_result_take_error_stripped (data->result, error);
-      _g_simple_async_result_complete_with_cancellable (data->result, data->cancellable);
-      async_proxy_create_free (data);
+      g_dbus_error_strip_remote_error (error);
+      g_task_return_error (task, error);
+      g_object_unref (task);
       return;
     }
 
@@ -258,26 +262,30 @@ async_proxy_new_cb (GObject *source_object,
                                 g_mount_source_get_dbus_id (mount_source),
                                 g_mount_source_get_obj_path (mount_source),
                                 data->flags,
-                                data->cancellable,
+                                g_task_get_cancellable (task),
                                 (GAsyncReadyCallback) unmount_reply,
-                                data);
-  data->cancelled_tag = _g_dbus_async_subscribe_cancellable (data->connection, data->cancellable);
+                                task);
+  data->cancelled_tag = _g_dbus_async_subscribe_cancellable (data->connection, g_task_get_cancellable 
(task));
   
   g_object_unref (mount_source);
 }
 
 static void
 async_construct_proxy (GDBusConnection *connection,
-                       AsyncProxyCreate *data)
+                       GTask *task)
 {
+  AsyncProxyCreate *data;
+
+  data = g_task_get_task_data (task);
+
   data->connection = g_object_ref (connection);
   gvfs_dbus_mount_proxy_new (connection,
                              G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | 
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
                              data->mount_info->dbus_id,
                              data->mount_info->object_path,
-                             data->cancellable,
+                             g_task_get_cancellable (task),
                              async_proxy_new_cb,
-                             data);
+                             task);
 }
 
 static void
@@ -285,7 +293,7 @@ bus_get_cb (GObject *source_object,
             GAsyncResult *res,
             gpointer user_data)
 {
-  AsyncProxyCreate *data = user_data;
+  GTask *task = G_TASK (user_data);
   GDBusConnection *connection;
   GError *error = NULL;
   
@@ -293,13 +301,13 @@ bus_get_cb (GObject *source_object,
   
   if (connection == NULL)
     {
-      _g_simple_async_result_take_error_stripped (data->result, error);
-      _g_simple_async_result_complete_with_cancellable (data->result, data->cancellable);
-      async_proxy_create_free (data);
+      g_dbus_error_strip_remote_error (error);
+      g_task_return_error (task, error);
+      g_object_unref (task);
       return;
     }
 
-  async_construct_proxy (connection, data);
+  async_construct_proxy (connection, task);
 }
 
 static void
@@ -307,20 +315,20 @@ async_got_connection_cb (GDBusConnection *connection,
                          GError *io_error,
                          gpointer callback_data)
 {
-  AsyncProxyCreate *data = callback_data;
-  
+  GTask *task = G_TASK (callback_data);
+
   if (connection == NULL)
     {
       /* TODO: we should probably test if we really want a session bus;
        *       for now, this code is on par with the old dbus code */ 
       g_bus_get (G_BUS_TYPE_SESSION,
-                 data->cancellable,
+                 g_task_get_cancellable (task),
                  bus_get_cb,
-                 data);
+                 task);
       return;
     }
   
-  async_construct_proxy (connection, data);
+  async_construct_proxy (connection, task);
 }
 
 static void
@@ -332,25 +340,23 @@ g_daemon_mount_unmount_with_operation (GMount *mount,
                                        gpointer         user_data)
 {
   GDaemonMount *daemon_mount = G_DAEMON_MOUNT (mount);
+  GTask *task;
   AsyncProxyCreate *data;
 
+  task = g_task_new (mount, cancellable, callback, user_data);
+
   data = g_new0 (AsyncProxyCreate, 1);
-  data->mount = g_object_ref (mount);
   data->mount_info = daemon_mount->mount_info;
   data->flags = flags;
   if (mount_operation)
     data->mount_operation = g_object_ref (mount_operation);
-  if (cancellable)
-    data->cancellable = g_object_ref (cancellable);
 
-  data->result = g_simple_async_result_new (G_OBJECT (mount),
-                                            callback, user_data,
-                                            g_daemon_mount_unmount_with_operation);
-  
+  g_task_set_task_data (task, data, (GDestroyNotify)async_proxy_create_free);
+
   _g_dbus_connection_get_for_async (data->mount_info->dbus_id,
                                     async_got_connection_cb,
-                                    data,
-                                    data->cancellable);
+                                    task,
+                                    cancellable);
 }
 
 static gboolean
@@ -358,6 +364,7 @@ g_daemon_mount_unmount_with_operation_finish (GMount *mount,
                                               GAsyncResult *result,
                                               GError **error)
 {
+  /* Errors handled in generic code */
   return TRUE;
 }
 
@@ -406,13 +413,11 @@ g_daemon_mount_guess_content_type (GMount              *mount,
                                    GAsyncReadyCallback  callback,
                                    gpointer             user_data)
 {
-  GSimpleAsyncResult *simple;
-  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);
+  GTask *task;
+
+  task = g_task_new (mount, cancellable, callback, user_data);
+  g_task_return_boolean (task, TRUE);
+  g_object_unref (task);
 }
 
 static char **
@@ -420,6 +425,11 @@ g_daemon_mount_guess_content_type_finish (GMount              *mount,
                                           GAsyncResult        *result,
                                           GError             **error)
 {
+  g_return_val_if_fail (g_task_is_valid (result, mount), NULL);
+
+  if (!g_task_propagate_boolean (G_TASK (result), error))
+    return NULL;
+
   return g_daemon_mount_guess_content_type_sync (mount, FALSE, NULL, error);
 }
 


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