[Spice-devel] [PATCH 05/14] smartcard-manager: Use GTask instead of GSimpleAsyncResult

Fabiano FidĂȘncio fidencio at redhat.com
Mon Jan 18 01:05:41 PST 2016


Instead of using GSimpleAsyncResult, use the new GTask API, which is
much more straightforward.
---
 src/smartcard-manager.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/src/smartcard-manager.c b/src/smartcard-manager.c
index 6578328..2310ab6 100644
--- a/src/smartcard-manager.c
+++ b/src/smartcard-manager.c
@@ -476,8 +476,9 @@ end:
     return retval;
 }
 
-static void smartcard_manager_init_helper(GSimpleAsyncResult *res,
-                                          GObject *object,
+static void smartcard_manager_init_helper(GTask *task,
+                                          gpointer object,
+                                          gpointer task_data,
                                           GCancellable *cancellable)
 {
     static GOnce smartcard_manager_once = G_ONCE_INIT;
@@ -492,8 +493,10 @@ static void smartcard_manager_init_helper(GSimpleAsyncResult *res,
            (GThreadFunc)smartcard_manager_init,
            &args);
     if (args.err != NULL) {
-        g_simple_async_result_set_from_error(res, args.err);
+        g_task_return_error(task, args.err);
         g_error_free(args.err);
+    } else {
+        g_task_return_boolean(task, TRUE);
     }
 }
 
@@ -504,17 +507,10 @@ void spice_smartcard_manager_init_async(SpiceSession *session,
                                         GAsyncReadyCallback callback,
                                         gpointer opaque)
 {
-    GSimpleAsyncResult *res;
+    GTask *task = g_task_new(session, cancellable, callback, opaque);
 
-    res = g_simple_async_result_new(G_OBJECT(session),
-                                    callback,
-                                    opaque,
-                                    spice_smartcard_manager_init);
-    g_simple_async_result_run_in_thread(res,
-                                        smartcard_manager_init_helper,
-                                        G_PRIORITY_DEFAULT,
-                                        cancellable);
-    g_object_unref(res);
+    g_task_run_in_thread(task, smartcard_manager_init_helper);
+    g_object_unref(task);
 }
 
 G_GNUC_INTERNAL
@@ -522,21 +518,18 @@ gboolean spice_smartcard_manager_init_finish(SpiceSession *session,
                                              GAsyncResult *result,
                                              GError **err)
 {
-    GSimpleAsyncResult *simple;
+    GTask *task = G_TASK(result);
 
     g_return_val_if_fail(SPICE_IS_SESSION(session), FALSE);
-    g_return_val_if_fail(G_IS_SIMPLE_ASYNC_RESULT(result), FALSE);
+    g_return_val_if_fail(G_IS_TASK(task), FALSE);
 
     SPICE_DEBUG("smartcard_manager_finish");
 
-    simple = G_SIMPLE_ASYNC_RESULT(result);
-    g_return_val_if_fail(g_simple_async_result_get_source_tag(simple) == spice_smartcard_manager_init, FALSE);
-    if (g_simple_async_result_propagate_error(simple, err))
-        return FALSE;
+    g_return_val_if_fail(g_task_get_source_tag(task) == spice_smartcard_manager_init, FALSE);
 
     spice_smartcard_manager_update_monitor();
 
-    return TRUE;
+    return g_task_propagate_boolean(task, err);
 }
 
 /**
-- 
2.5.0



More information about the Spice-devel mailing list