[gnome-online-miners/wip/rishi/insert-share: 4/10] miner: Port gom_account_miner_job_process() to GTask



commit eb69777377fd1b5f71c28b5924cdc25633c06937
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Sep 2 14:12:57 2016 +0200

    miner: Port gom_account_miner_job_process() to GTask

 src/gom-miner.c |   45 ++++++++++++++++++++-------------------------
 src/gom-miner.h |    2 +-
 2 files changed, 21 insertions(+), 26 deletions(-)
---
diff --git a/src/gom-miner.c b/src/gom-miner.c
index 3fe098d..db6c69e 100644
--- a/src/gom-miner.c
+++ b/src/gom-miner.c
@@ -57,7 +57,7 @@ gom_account_miner_job_free (GomAccountMinerJob *job)
   g_clear_object (&job->miner);
   g_clear_object (&job->account);
   g_clear_object (&job->connection);
-  g_clear_object (&job->async_result);
+  g_clear_object (&job->task);
 
   g_free (job->datasource_urn);
   g_free (job->root_element_urn);
@@ -288,12 +288,13 @@ gom_account_miner_job_query (GomAccountMinerJob *job,
   miner_class->query (job, error);
 }
 
-static gboolean
-gom_account_miner_job (GIOSchedulerJob *sched_job,
-                       GCancellable *cancellable,
-                       gpointer user_data)
+static void
+gom_account_miner_job (GTask *task,
+                       gpointer source_object,
+                       gpointer task_data,
+                       GCancellable *cancellable)
 {
-  GomAccountMinerJob *job = user_data;
+  GomAccountMinerJob *job = task_data;
   GError *error = NULL;
 
   gom_account_miner_job_ensure_datasource (job, &error);
@@ -318,11 +319,9 @@ gom_account_miner_job (GIOSchedulerJob *sched_job,
 
  out:
   if (error != NULL)
-    g_simple_async_result_take_error (job->async_result, error);
-
-  g_simple_async_result_complete_in_idle (job->async_result);
-
-  return FALSE;
+    g_task_return_error (job->task, error);
+  else
+    g_task_return_boolean (job->task, TRUE);
 }
 
 static void
@@ -330,30 +329,26 @@ gom_account_miner_job_process_async (GomAccountMinerJob *job,
                                      GAsyncReadyCallback callback,
                                      gpointer user_data)
 {
-  g_assert (job->async_result == NULL);
+  g_assert (job->task == NULL);
 
-  job->async_result = g_simple_async_result_new (NULL, callback, user_data,
-                                                 gom_account_miner_job_process_async);
-  g_simple_async_result_set_op_res_gpointer (job->async_result, job, NULL);
-
-  g_io_scheduler_push_job (gom_account_miner_job, job, NULL,
-                           G_PRIORITY_DEFAULT,
-                           job->cancellable);
+  job->task = g_task_new (NULL, job->cancellable, callback, user_data);
+  g_task_set_source_tag (job->task, gom_account_miner_job_process_async);
+  g_task_set_task_data (job->task, job, NULL);
+  g_task_run_in_thread (job->task, gom_account_miner_job);
 }
 
 static gboolean
 gom_account_miner_job_process_finish (GAsyncResult *res,
                                       GError **error)
 {
-  GSimpleAsyncResult *simple_res = G_SIMPLE_ASYNC_RESULT (res);
+  GTask *task;
 
-  g_assert (g_simple_async_result_is_valid (res, NULL,
-                                            gom_account_miner_job_process_async));
+  g_assert (g_task_is_valid (res, NULL));
+  task = G_TASK (res);
 
-  if (g_simple_async_result_propagate_error (simple_res, error))
-    return FALSE;
+  g_assert (g_task_get_source_tag (task) == gom_account_miner_job_process_async);
 
-  return TRUE;
+  return g_task_propagate_boolean (task, error);
 }
 
 static void
diff --git a/src/gom-miner.h b/src/gom-miner.h
index 4675f12..8e531ce 100644
--- a/src/gom-miner.h
+++ b/src/gom-miner.h
@@ -65,7 +65,7 @@ typedef struct {
 
   GoaAccount *account;
   GHashTable *services;
-  GSimpleAsyncResult *async_result;
+  GTask *task;
   GCancellable *cancellable;
 
   GHashTable *previous_resources;


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