[tracker] libtracker-miner: Drop TrackerSparqlBuilder from TrackerDecorator API



commit 9c4874363b6818208e219ba5e67479a01c43f695
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Jul 10 11:16:05 2017 +0200

    libtracker-miner: Drop TrackerSparqlBuilder from TrackerDecorator API
    
    Just add tracker_decorator_info_complete[_error] functions to let the
    decorator implementation give back the resulting SPARQL. This way the
    TrackerDecorator API is agnostic of the method/API used to build the
    SPARQL.

 .../libtracker-miner/libtracker-miner-sections.txt |    3 +-
 src/libtracker-miner/tracker-decorator.c           |   50 +++++++++++--------
 src/libtracker-miner/tracker-decorator.h           |    6 ++-
 src/tracker-extract/tracker-extract-decorator.c    |   31 +++++-------
 4 files changed, 48 insertions(+), 42 deletions(-)
---
diff --git a/docs/reference/libtracker-miner/libtracker-miner-sections.txt 
b/docs/reference/libtracker-miner/libtracker-miner-sections.txt
index 42ddb73..d88c9a6 100644
--- a/docs/reference/libtracker-miner/libtracker-miner-sections.txt
+++ b/docs/reference/libtracker-miner/libtracker-miner-sections.txt
@@ -35,7 +35,8 @@ tracker_decorator_info_get_urn
 tracker_decorator_info_get_url
 tracker_decorator_info_get_mimetype
 tracker_decorator_info_get_task
-tracker_decorator_info_get_sparql
+tracker_decorator_info_complete
+tracker_decorator_info_complete_error
 <SUBSECTION Standard>
 TRACKER_DECORATOR
 TRACKER_DECORATOR_CLASS
diff --git a/src/libtracker-miner/tracker-decorator.c b/src/libtracker-miner/tracker-decorator.c
index 5fabdf4..318de58 100644
--- a/src/libtracker-miner/tracker-decorator.c
+++ b/src/libtracker-miner/tracker-decorator.c
@@ -534,10 +534,12 @@ decorator_task_done (GObject      *object,
        TrackerDecoratorInfo *info = user_data;
        TrackerDecoratorPrivate *priv;
        GError *error = NULL;
+       gchar *sparql;
 
        priv = decorator->priv;
+       sparql = g_task_propagate_pointer (G_TASK (result), &error);
 
-       if (!g_task_propagate_boolean (G_TASK (result), &error)) {
+       if (!sparql) {
                /* Blacklist item */
                decorator_blacklist_add (decorator, info->id);
 
@@ -547,12 +549,10 @@ decorator_task_done (GObject      *object,
                        g_error_free (error);
                }
        } else {
-               TrackerSparqlBuilder *sparql;
                SparqlUpdate update;
 
                /* Add resulting sparql to buffer and check whether flushing */
-               sparql = g_task_get_task_data (G_TASK (result));
-               update.sparql = g_strdup (tracker_sparql_builder_get_result (sparql));
+               update.sparql = sparql;
                update.id = info->id;
 
                if (!priv->sparql_buffer)
@@ -1655,29 +1655,37 @@ tracker_decorator_info_get_task (TrackerDecoratorInfo *info)
 }
 
 /**
- * tracker_decorator_info_get_sparql:
- * @info: a #TrackerDecoratorInfo.
+ * tracker_decorator_info_complete:
+ * @info: a #TrackerDecoratorInfo
+ * @sparql: SPARQL string
  *
- * A #TrackerSparqlBuilder allows the caller to extract the final
- * SPARQL used to insert the extracted metadata into the database for
- * the resource being processed.
+ * Completes the task associated to this #TrackerDecoratorInfo.
+ * Takes ownership of @sparql.
  *
- * This function calls g_task_get_task_data() on the return value of
- * tracker_decorator_info_get_task().
+ * Since: 2.0
+ **/
+void
+tracker_decorator_info_complete (TrackerDecoratorInfo *info,
+                                 gchar                *sparql)
+{
+       g_task_return_pointer (info->task, sparql, g_free);
+}
+
+/**
+ * tracker_decorator_info_complete_error:
+ * @info: a #TrackerDecoratorInfo
+ * @error: An error occurred during SPARQL generation
  *
- * Returns: (transfer none): a #TrackerSparqlBuilder on success or #NULL on error.
+ * Completes the task associated to this #TrackerDecoratorInfo,
+ * returning the given @error happened during SPARQL generation.
  *
- * Since: 0.18.
+ * Since: 2.0
  **/
-TrackerSparqlBuilder *
-tracker_decorator_info_get_sparql (TrackerDecoratorInfo *info)
+void
+tracker_decorator_info_complete_error (TrackerDecoratorInfo *info,
+                                       GError               *error)
 {
-       g_return_val_if_fail (info != NULL, NULL);
-
-       if (!info->task)
-               return NULL;
-
-       return g_task_get_task_data (info->task);
+       g_task_return_error (info->task, error);
 }
 
 void
diff --git a/src/libtracker-miner/tracker-decorator.h b/src/libtracker-miner/tracker-decorator.h
index ccb076b..af00d56 100644
--- a/src/libtracker-miner/tracker-decorator.h
+++ b/src/libtracker-miner/tracker-decorator.h
@@ -128,8 +128,10 @@ const gchar * tracker_decorator_info_get_urn      (TrackerDecoratorInfo *info);
 const gchar * tracker_decorator_info_get_url      (TrackerDecoratorInfo *info);
 const gchar * tracker_decorator_info_get_mimetype (TrackerDecoratorInfo *info);
 GTask       * tracker_decorator_info_get_task     (TrackerDecoratorInfo *info);
-TrackerSparqlBuilder *
-              tracker_decorator_info_get_sparql   (TrackerDecoratorInfo *info);
+void          tracker_decorator_info_complete     (TrackerDecoratorInfo *info,
+                                                   gchar                *sparql);
+void          tracker_decorator_info_complete_error (TrackerDecoratorInfo *info,
+                                                     GError               *error);
 
 G_END_DECLS
 
diff --git a/src/tracker-extract/tracker-extract-decorator.c b/src/tracker-extract/tracker-extract-decorator.c
index abaf7a9..cfb51d7 100644
--- a/src/tracker-extract/tracker-extract-decorator.c
+++ b/src/tracker-extract/tracker-extract-decorator.c
@@ -140,15 +140,13 @@ tracker_extract_decorator_finalize (GObject *object)
        G_OBJECT_CLASS (tracker_extract_decorator_parent_class)->finalize (object);
 }
 
-static void
-decorator_save_info (TrackerSparqlBuilder    *sparql,
-                     TrackerExtractDecorator *decorator,
+static TrackerResource *
+decorator_save_info (TrackerExtractDecorator *decorator,
                      TrackerDecoratorInfo    *decorator_info,
                      TrackerExtractInfo      *info)
 {
        const gchar *urn;
        TrackerResource *resource = NULL;
-       gchar *sparql_command;
 
        g_set_object (&resource, tracker_extract_info_get_resource (info));
 
@@ -168,12 +166,7 @@ decorator_save_info (TrackerSparqlBuilder    *sparql,
        tracker_resource_set_uri (resource, "nie:dataSource",
                tracker_decorator_get_data_source (TRACKER_DECORATOR (decorator)));
 
-       sparql_command = tracker_resource_print_sparql_update (
-               resource, NULL, TRACKER_OWN_GRAPH_URN);
-       tracker_sparql_builder_append (sparql, sparql_command);
-
-       g_object_unref (resource);
-       g_free (sparql_command);
+       return resource;
 }
 
 static void
@@ -183,11 +176,11 @@ get_metadata_cb (TrackerExtract *extract,
 {
        TrackerExtractDecoratorPrivate *priv;
        TrackerExtractInfo *info;
+       TrackerResource *resource;
        GError *error = NULL;
-       GTask *task;
+       gchar *sparql;
 
        priv = TRACKER_EXTRACT_DECORATOR (data->decorator)->priv;
-       task = tracker_decorator_info_get_task (data->decorator_info);
        info = tracker_extract_file_finish (extract, result, &error);
 
        tracker_extract_persistence_remove_file (priv->persistence, data->file);
@@ -196,17 +189,19 @@ get_metadata_cb (TrackerExtract *extract,
        if (error) {
                if (error->domain == TRACKER_EXTRACT_ERROR) {
                        g_message ("Extraction failed: %s\n", error ? error->message : "no error given");
-                       g_task_return_boolean (task, FALSE);
+                       tracker_decorator_info_complete (data->decorator_info, NULL);
                        g_clear_error (&error);
                } else {
-                       g_task_return_error (task, error);
+                       tracker_decorator_info_complete_error (data->decorator_info, error);
                }
        } else {
-               decorator_save_info (g_task_get_task_data (task),
-                                    TRACKER_EXTRACT_DECORATOR (data->decorator),
-                                    data->decorator_info, info);
-               g_task_return_boolean (task, TRUE);
+               resource = decorator_save_info (TRACKER_EXTRACT_DECORATOR (data->decorator),
+                                               data->decorator_info, info);
+               sparql = tracker_resource_print_sparql_update (resource, NULL,
+                                                              TRACKER_OWN_GRAPH_URN);
+               tracker_decorator_info_complete (data->decorator_info, sparql);
                tracker_extract_info_unref (info);
+               g_object_unref (resource);
        }
 
        priv->n_extracting_files--;


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