[tracker] libtracker-miner: Port TrackerSparqlBuffer to GTask



commit 1849feb57864fc6359464aaba3f8aa687f6473c3
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Nov 25 22:55:25 2015 +0100

    libtracker-miner: Port TrackerSparqlBuffer to GTask

 src/libtracker-miner/tracker-miner-fs.c      |    7 ++-
 src/libtracker-miner/tracker-sparql-buffer.c |   54 ++++++++++++++++---------
 src/libtracker-miner/tracker-sparql-buffer.h |    4 ++
 3 files changed, 42 insertions(+), 23 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index faf2586..af15487 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -1272,14 +1272,15 @@ sparql_buffer_task_finished_cb (GObject      *object,
        fs = user_data;
        priv = fs->priv;
 
-       if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),
-                                                  &error)) {
+       task = tracker_sparql_buffer_push_finish (TRACKER_SPARQL_BUFFER (object),
+                                                 result, &error);
+
+       if (error) {
                g_critical ("Could not execute sparql: %s", error->message);
                priv->total_files_notified_error++;
                g_error_free (error);
        }
 
-       task = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
        task_file = tracker_task_get_file (task);
 
        tracker_file_notifier_invalidate_file_iri (priv->file_notifier, task_file);
diff --git a/src/libtracker-miner/tracker-sparql-buffer.c b/src/libtracker-miner/tracker-sparql-buffer.c
index c048313..3562425 100644
--- a/src/libtracker-miner/tracker-sparql-buffer.c
+++ b/src/libtracker-miner/tracker-sparql-buffer.c
@@ -67,7 +67,7 @@ struct _SparqlTaskData
                } bulk;
        } data;
 
-       GSimpleAsyncResult *result;
+       GTask *async_task;
 };
 
 struct _UpdateData {
@@ -355,14 +355,12 @@ tracker_sparql_buffer_update_array_cb (GObject      *object,
                }
 
                /* Call finished handler with the error, if any */
-               g_simple_async_result_set_op_res_gpointer (task_data->result,
-                                                          task, NULL);
                if (error) {
-                       g_simple_async_result_set_from_error (task_data->result, error);
+                       g_task_return_error (task_data->async_task, error);
+               } else {
+                       g_task_return_pointer (task_data->async_task, task, NULL);
                }
 
-               g_simple_async_result_complete (task_data->result);
-
                /* No need to deallocate the task here, it will be done when
                 * unref-ing the UpdateArrayData below */
        }
@@ -645,16 +643,13 @@ tracker_sparql_buffer_update_cb (GObject      *object,
        task_data = tracker_task_get_data (update_data->task);
 
        /* Call finished handler with the error, if any */
-       g_simple_async_result_set_op_res_gpointer (task_data->result,
-                                                  update_data->task,
-                                                  NULL);
        if (error) {
-               g_simple_async_result_set_from_error (task_data->result, error);
-               g_error_free (error);
+               g_task_return_error (task_data->async_task, error);
+       } else {
+               g_task_return_pointer (task_data->async_task,
+                                      update_data->task, NULL);
        }
 
-       g_simple_async_result_complete (task_data->result);
-
        tracker_task_pool_remove (TRACKER_TASK_POOL (update_data->buffer),
                                  update_data->task);
        g_slice_free (UpdateData, update_data);
@@ -740,11 +735,11 @@ tracker_sparql_buffer_push (TrackerSparqlBuffer *buffer,
         */
        data = tracker_task_get_data (task);
 
-       if (!data->result) {
-               data->result = g_simple_async_result_new (G_OBJECT (buffer),
-                                                         cb,
-                                                         user_data,
-                                                         NULL);
+       if (!data->async_task) {
+               data->async_task = g_task_new (buffer, NULL, cb, user_data);
+               g_task_set_task_data (data->async_task,
+                                     tracker_task_ref (task),
+                                     (GDestroyNotify) tracker_task_unref);
        }
 
        if (priority <= G_PRIORITY_HIGH &&
@@ -796,8 +791,8 @@ sparql_task_data_free (SparqlTaskData *data)
                break;
        }
 
-       if (data->result) {
-               g_object_unref (data->result);
+       if (data->async_task) {
+               g_object_unref (data->async_task);
        }
 
        g_slice_free (SparqlTaskData, data);
@@ -850,3 +845,22 @@ tracker_sparql_task_new_bulk (GFile                *file,
        return tracker_task_new (file, data,
                                 (GDestroyNotify) sparql_task_data_free);
 }
+
+TrackerTask *
+tracker_sparql_buffer_push_finish (TrackerSparqlBuffer  *buffer,
+                                   GAsyncResult         *res,
+                                   GError              **error)
+{
+       TrackerTask *task;
+
+       g_return_val_if_fail (TRACKER_IS_SPARQL_BUFFER (buffer), NULL);
+       g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
+       g_return_val_if_fail (!error || !*error, NULL);
+
+       task = g_task_propagate_pointer (G_TASK (res), error);
+
+       if (!task)
+               task = g_task_get_task_data (G_TASK (res));
+
+       return task;
+}
diff --git a/src/libtracker-miner/tracker-sparql-buffer.h b/src/libtracker-miner/tracker-sparql-buffer.h
index 7cb5f0b..f7f34bd 100644
--- a/src/libtracker-miner/tracker-sparql-buffer.h
+++ b/src/libtracker-miner/tracker-sparql-buffer.h
@@ -73,6 +73,10 @@ void                 tracker_sparql_buffer_push  (TrackerSparqlBuffer *buffer,
                                                   GAsyncReadyCallback  cb,
                                                   gpointer             user_data);
 
+TrackerTask *        tracker_sparql_buffer_push_finish (TrackerSparqlBuffer  *buffer,
+                                                        GAsyncResult         *res,
+                                                        GError              **error);
+
 TrackerTask *        tracker_sparql_task_new_take_sparql_str (GFile                *file,
                                                               gchar                *sparql_str);
 TrackerTask *        tracker_sparql_task_new_with_sparql_str (GFile                *file,


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