[gvfs/wip/oholy/gtask: 9/10] gmountsource: Port to GTask



commit 746a2a664365ee96666502ffe39356baa46a535a
Author: Ondrej Holy <oholy redhat com>
Date:   Thu Jun 16 20:17:08 2016 +0200

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

 common/gmountsource.c |  148 +++++++++++++++++++++----------------------------
 1 files changed, 63 insertions(+), 85 deletions(-)
---
diff --git a/common/gmountsource.c b/common/gmountsource.c
index 1f2014d..b491f18 100644
--- a/common/gmountsource.c
+++ b/common/gmountsource.c
@@ -175,11 +175,8 @@ create_mount_operation_proxy_sync (GMountSource        *source,
   if (source->dbus_id[0] == 0)
     { 
       if (callback != NULL)
-        g_simple_async_report_error_in_idle (G_OBJECT (source),
-                                             callback,
-                                             user_data,
-                                             G_IO_ERROR, G_IO_ERROR_FAILED, 
-                                             "Internal Error"); 
+        g_task_report_new_error (source, callback, user_data, NULL,
+                                 G_IO_ERROR, G_IO_ERROR_FAILED, "Internal Error");
       return NULL;
     }
 
@@ -193,11 +190,11 @@ create_mount_operation_proxy_sync (GMountSource        *source,
                                                             &error);
   if (proxy == NULL)
     if (callback != NULL)
-      g_simple_async_report_take_gerror_in_idle (G_OBJECT (source),
-                                                 callback,
-                                                 user_data,
-                                                 error);
-  
+      {
+        g_dbus_error_strip_remote_error (error);
+        g_task_report_error (source, callback, user_data, NULL, error);
+      }
+
   return proxy;
 }
 
@@ -207,19 +204,16 @@ ask_password_reply (GVfsDBusMountOperation *proxy,
                     GAsyncResult *res,
                     gpointer user_data)
 {
-  GSimpleAsyncResult *result;
+  GTask *task;
   AskPasswordData *data;
   gboolean handled, aborted, anonymous;
   guint32 password_save;
   gchar *password, *username, *domain;
   GError *error;
 
-  result = G_SIMPLE_ASYNC_RESULT (user_data);
+  task = G_TASK (user_data);
   handled = TRUE;
 
-  data = g_new0 (AskPasswordData, 1);
-  g_simple_async_result_set_op_res_gpointer (result, data, ask_password_data_free);
-
   error = NULL;
   if (!gvfs_dbus_mount_operation_call_ask_password_finish (proxy,
                                                            &handled,
@@ -232,12 +226,16 @@ ask_password_reply (GVfsDBusMountOperation *proxy,
                                                            res,
                                                            &error))
     {
-      data->aborted = TRUE;
       g_dbus_error_strip_remote_error (error);
-      g_simple_async_result_take_error (result, error);
+      g_task_return_error (task, error);
+    }
+  else if (handled == FALSE)
+    {
+      g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, "Internal Error");
     }
   else
     {
+      data = g_new0 (AskPasswordData, 1);
       data->aborted = aborted;
 
       if (!anonymous)
@@ -249,19 +247,15 @@ ask_password_reply (GVfsDBusMountOperation *proxy,
       data->password_save = (GPasswordSave)password_save;
       data->anonymous = anonymous;
 
+      g_task_return_pointer (task, data, ask_password_data_free);
+
       /* TODO: handle more args */
       g_free (password);
       g_free (username);
       g_free (domain);
     }
 
-  if (handled == FALSE)
-    {
-      g_simple_async_result_set_error (result, G_IO_ERROR, G_IO_ERROR_FAILED, "Internal Error");
-    }
-  
-  g_simple_async_result_complete (result);
-  g_object_unref (result);
+  g_object_unref (task);
 }
 
 void
@@ -273,7 +267,7 @@ g_mount_source_ask_password_async (GMountSource              *source,
                                    GAsyncReadyCallback        callback,
                                    gpointer                   user_data)
 {
-  GSimpleAsyncResult *result;
+  GTask *task;
   GVfsDBusMountOperation *proxy;
   
   proxy = create_mount_operation_proxy_sync (source, callback, user_data);
@@ -283,9 +277,8 @@ g_mount_source_ask_password_async (GMountSource              *source,
   /* 30 minute timeout */
   g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), G_VFS_DBUS_MOUNT_TIMEOUT_MSECS);
 
-  result = g_simple_async_result_new (G_OBJECT (source), callback, user_data, 
-                                      g_mount_source_ask_password_async);
-  
+  task = g_task_new (source, NULL, callback, user_data);
+
   gvfs_dbus_mount_operation_call_ask_password (proxy,
                                                message_string ? message_string : "",
                                                default_user ? default_user : "",
@@ -293,7 +286,7 @@ g_mount_source_ask_password_async (GMountSource              *source,
                                                flags,
                                                NULL,
                                                (GAsyncReadyCallback) ask_password_reply,
-                                               result);
+                                               task);
   g_object_unref (proxy);
 }
 
@@ -330,14 +323,12 @@ g_mount_source_ask_password_finish (GMountSource  *source,
                                    GPasswordSave *password_save_out)
 {
   AskPasswordData *data, def = { TRUE, };
-  GSimpleAsyncResult *simple;
 
-  simple = G_SIMPLE_ASYNC_RESULT (result);
+  g_return_val_if_fail (g_task_is_valid (result, source), FALSE);
 
-  if (g_simple_async_result_propagate_error (simple, NULL))
+  data = g_task_propagate_pointer (G_TASK (result), NULL);
+  if (data == NULL)
     data = &def;
-  else
-    data = (AskPasswordData *) g_simple_async_result_get_op_res_gpointer (simple);
 
   if (aborted)
     *aborted = data->aborted;
@@ -521,17 +512,14 @@ ask_question_reply (GVfsDBusMountOperation *proxy,
                     GAsyncResult *res,
                     gpointer user_data)
 {
-  GSimpleAsyncResult *result;
+  GTask *task;
   AskQuestionData *data;
   gboolean handled, aborted;
   guint32 choice;
   GError *error;
-  
-  result = G_SIMPLE_ASYNC_RESULT (user_data);
-  handled = TRUE;
 
-  data = g_new0 (AskQuestionData, 1);
-  g_simple_async_result_set_op_res_gpointer (result, data, g_free);
+  task = G_TASK (user_data);
+  handled = TRUE;
 
   error = NULL;
   if (!gvfs_dbus_mount_operation_call_ask_question_finish (proxy,
@@ -541,23 +529,23 @@ ask_question_reply (GVfsDBusMountOperation *proxy,
                                                            res,
                                                            &error))
     {
-      data->aborted = TRUE;
       g_dbus_error_strip_remote_error (error);
-      g_simple_async_result_take_error (result, error);
+      g_task_return_error (task, error);
+    }
+  else if (handled == FALSE)
+    {
+      g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, "Internal Error");
     }
   else
     {
+      data = g_new0 (AskQuestionData, 1);
       data->aborted = aborted;
       data->choice = choice;
-    }
 
-  if (handled == FALSE)
-    {
-      g_simple_async_result_set_error (result, G_IO_ERROR, G_IO_ERROR_FAILED, "Internal Error");
+      g_task_return_pointer (task, data, g_free);
     }
 
-  g_simple_async_result_complete (result);
-  g_object_unref (result);
+  g_object_unref (task);
 }
 
 gboolean
@@ -611,7 +599,7 @@ g_mount_source_ask_question_async (GMountSource       *source,
                                   GAsyncReadyCallback callback,
                                   gpointer            user_data)
 {
-  GSimpleAsyncResult *result;
+  GTask *task;
   GVfsDBusMountOperation *proxy;
   
   proxy = create_mount_operation_proxy_sync (source, callback, user_data);
@@ -621,15 +609,14 @@ g_mount_source_ask_question_async (GMountSource       *source,
   /* 30 minute timeout */
   g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), G_VFS_DBUS_MOUNT_TIMEOUT_MSECS);
 
-  result = g_simple_async_result_new (G_OBJECT (source), callback, user_data, 
-                                      g_mount_source_ask_question_async);
-  
+  task = g_task_new (source, NULL, callback, user_data);
+
   gvfs_dbus_mount_operation_call_ask_question (proxy,
                                                message_string ? message_string : "",
                                                choices,   
                                                NULL,
                                                (GAsyncReadyCallback) ask_question_reply,
-                                               result);
+                                               task);
   g_object_unref (proxy);
 }
 
@@ -639,15 +626,13 @@ g_mount_source_ask_question_finish (GMountSource *source,
                                    gboolean     *aborted,
                                    gint         *choice_out)
 {
-  AskQuestionData *data, def= { FALSE, };
-  GSimpleAsyncResult *simple;
+  AskQuestionData *data, def = { TRUE, };
 
-  simple = G_SIMPLE_ASYNC_RESULT (result);
+  g_return_val_if_fail (g_task_is_valid (result, source), FALSE);
 
-  if (g_simple_async_result_propagate_error (simple, NULL))
+  data = g_task_propagate_pointer (G_TASK (result), NULL);
+  if (data == NULL)
     data = &def;
-  else
-    data = (AskQuestionData *) g_simple_async_result_get_op_res_gpointer (simple);
 
   if (aborted)
     *aborted = data->aborted;
@@ -721,19 +706,15 @@ show_processes_reply (GVfsDBusMountOperation *proxy,
                       GAsyncResult *res,
                       gpointer user_data)
 {
-  GSimpleAsyncResult *result;
+  GTask *task;
   ShowProcessesData *data;
   gboolean handled, aborted;
   guint32 choice;
   GError *error;
-  
-  result = G_SIMPLE_ASYNC_RESULT (user_data);
-  handled = TRUE;
 
-  data = g_new0 (ShowProcessesData, 1);
-  g_simple_async_result_set_op_res_gpointer (result, data, g_free);
+  task = G_TASK (user_data);
+  handled = TRUE;
 
-  
   error = NULL;
   if (!gvfs_dbus_mount_operation_call_show_processes_finish (proxy,
                                                              &handled,
@@ -742,23 +723,23 @@ show_processes_reply (GVfsDBusMountOperation *proxy,
                                                              res,
                                                              &error))
     {
-      data->aborted = TRUE;
       g_dbus_error_strip_remote_error (error);
-      g_simple_async_result_take_error (result, error);
+      g_task_return_error (task, error);
+    }
+  else if (handled == FALSE)
+    {
+      g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_FAILED, "Internal Error");
     }
   else
     {
+      data = g_new0 (ShowProcessesData, 1);
       data->aborted = aborted;
       data->choice = choice;
-    }
 
-  if (handled == FALSE)
-    {
-      g_simple_async_result_set_error (result, G_IO_ERROR, G_IO_ERROR_FAILED, "Internal Error");
+      g_task_return_pointer (task, data, g_free);
     }
 
-  g_simple_async_result_complete (result);
-  g_object_unref (result);
+  g_object_unref (task);
 }
 
 void
@@ -769,7 +750,7 @@ g_mount_source_show_processes_async (GMountSource        *source,
                                      GAsyncReadyCallback  callback,
                                      gpointer             user_data)
 {
-  GSimpleAsyncResult *result;
+  GTask *task;
   GVfsDBusMountOperation *proxy;
   GVariantBuilder builder;
   guint i;
@@ -781,9 +762,8 @@ g_mount_source_show_processes_async (GMountSource        *source,
   /* 30 minute timeout */
   g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (proxy), G_VFS_DBUS_MOUNT_TIMEOUT_MSECS);
 
-  result = g_simple_async_result_new (G_OBJECT (source), callback, user_data,
-                                      g_mount_source_show_processes_async);
-  
+  task = g_task_new (source, NULL, callback, user_data);
+
   g_variant_builder_init (&builder, G_VARIANT_TYPE ("ai"));
   for (i = 0; i < processes->len; i++)
     g_variant_builder_add (&builder, "i", 
@@ -795,7 +775,7 @@ g_mount_source_show_processes_async (GMountSource        *source,
                                                  g_variant_builder_end (&builder),
                                                  NULL,
                                                  (GAsyncReadyCallback) show_processes_reply,
-                                                 result);
+                                                 task);
   g_object_unref (proxy);
 }
 
@@ -805,15 +785,13 @@ g_mount_source_show_processes_finish (GMountSource *source,
                                       gboolean     *aborted,
                                       gint         *choice_out)
 {
-  ShowProcessesData *data, def= { FALSE, };
-  GSimpleAsyncResult *simple;
+  ShowProcessesData *data, def = { TRUE, };
 
-  simple = G_SIMPLE_ASYNC_RESULT (result);
+  g_return_val_if_fail (g_task_is_valid (result, source), FALSE);
 
-  if (g_simple_async_result_propagate_error (simple, NULL))
+  data = g_task_propagate_pointer (G_TASK (result), NULL);
+  if (data == NULL)
     data = &def;
-  else
-    data = (ShowProcessesData *) g_simple_async_result_get_op_res_gpointer (simple);
 
   if (aborted)
     *aborted = data->aborted;


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