[gcr/wip/nielsdg/initial-gtask: 9/16] gcr-certificate-chain: Port to GTask



commit c31db827da93cbc70edd0ef9f05b2fa1c31824f1
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sun Dec 22 09:52:53 2019 +0100

    gcr-certificate-chain: Port to GTask

 gcr/gcr-certificate-chain.c | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)
---
diff --git a/gcr/gcr-certificate-chain.c b/gcr/gcr-certificate-chain.c
index b0d2d31..85eccae 100644
--- a/gcr/gcr-certificate-chain.c
+++ b/gcr/gcr-certificate-chain.c
@@ -372,19 +372,21 @@ perform_build_chain (GcrCertificateChainPrivate *pv, GCancellable *cancellable,
 }
 
 static void
-thread_build_chain (GSimpleAsyncResult *result, GObject *object,
+thread_build_chain (GTask *task, gpointer src_object, gpointer task_data,
                     GCancellable *cancellable)
 {
        GcrCertificateChainPrivate *pv;
        GError *error = NULL;
 
-       pv = g_object_get_qdata (G_OBJECT (result), Q_OPERATION_DATA);
+       pv = g_object_get_qdata (G_OBJECT (task), Q_OPERATION_DATA);
        g_assert (pv);
 
        g_debug ("building asynchronously in another thread");
 
-       if (!perform_build_chain (pv, cancellable, &error)) {
-               g_simple_async_result_set_from_error (result, error);
+       if (perform_build_chain (pv, cancellable, &error)) {
+               g_task_return_boolean (task, TRUE);
+       } else {
+               g_task_return_error (task, g_steal_pointer (&error));
                g_clear_error (&error);
        }
 }
@@ -782,22 +784,19 @@ gcr_certificate_chain_build_async (GcrCertificateChain *self,
                                    gpointer user_data)
 {
        GcrCertificateChainPrivate *pv;
-       GSimpleAsyncResult *result;
-
-       g_return_if_fail (GCR_IS_CERTIFICATE_CHAIN (self));
+       GTask *task;
 
        g_return_if_fail (GCR_IS_CERTIFICATE_CHAIN (self));
        g_return_if_fail (purpose);
 
        pv = prep_chain_private_thread_safe (self->pv, purpose, peer, flags);
 
-       result = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
-                                           gcr_certificate_chain_build_async);
-       g_object_set_qdata_full (G_OBJECT (result), Q_OPERATION_DATA, pv, free_chain_private);
+       task = g_task_new (self, cancellable, callback, user_data);
+       g_task_set_source_tag (task, gcr_certificate_chain_build_async);
+       g_object_set_qdata_full (G_OBJECT (task), Q_OPERATION_DATA, pv, free_chain_private);
 
-       g_simple_async_result_run_in_thread (result, thread_build_chain,
-                                            G_PRIORITY_DEFAULT, cancellable);
-       g_object_unref (result);
+       g_task_run_in_thread (task, thread_build_chain);
+       g_clear_object (&task);
 }
 
 /**
@@ -818,11 +817,9 @@ gcr_certificate_chain_build_finish (GcrCertificateChain *self, GAsyncResult *res
        GcrCertificateChainPrivate *pv;
 
        g_return_val_if_fail (GCR_IS_CERTIFICATE_CHAIN (self), FALSE);
-       g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE);
-       g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
-                             gcr_certificate_chain_build_async), FALSE);
+       g_return_val_if_fail (g_task_is_valid (result, self), FALSE);
 
-       if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
+       if (!g_task_propagate_boolean (G_TASK (result), error))
                return FALSE;
 
        pv = g_object_steal_qdata (G_OBJECT (result), Q_OPERATION_DATA);


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