[tracker/wip/extract-graphs: 2/30] libtracker-extract: Move TrackerExtractInfo out to its own header



commit f535dcde12a4f9e7d14b28dd80ff792713096ee6
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Aug 25 11:30:10 2011 +0200

    libtracker-extract: Move TrackerExtractInfo out to its own header
    
    The API has changed slightly too, it is a refcounted boxed object, and
    contains TrackerSparqlBuilders for preinsert/metadata contents. This is
    so it may be passed on to extract modules.
    
    Current users of TrackerExtractInfo have been modified to deal with the
    API change.

 .../libtracker-extract-sections.txt                |   19 ++-
 src/libtracker-extract/Makefile.am                 |    3 +
 src/libtracker-extract/tracker-extract-client.c    |  163 +++++---------
 src/libtracker-extract/tracker-extract-client.h    |   13 +-
 src/libtracker-extract/tracker-extract-info.c      |  236 ++++++++++++++++++++
 src/libtracker-extract/tracker-extract-info.h      |   58 +++++
 src/libtracker-extract/tracker-extract.h           |    1 +
 src/miners/fs/tracker-miner-files.c                |   22 ++-
 src/tracker-extract/tracker-controller.c           |   18 ++-
 src/tracker-extract/tracker-extract.c              |   68 +++---
 10 files changed, 440 insertions(+), 161 deletions(-)
---
diff --git a/docs/reference/libtracker-extract/libtracker-extract-sections.txt b/docs/reference/libtracker-extract/libtracker-extract-sections.txt
index bc7aff2..b746599 100644
--- a/docs/reference/libtracker-extract/libtracker-extract-sections.txt
+++ b/docs/reference/libtracker-extract/libtracker-extract-sections.txt
@@ -47,11 +47,22 @@ tracker_exif_read
 
 <SECTION>
 <FILE>tracker-extract-client</FILE>
-TrackerExtractInfo
 tracker_extract_client_get_metadata
 tracker_extract_client_get_metadata_finish
-tracker_extract_info_get_preupdate
-tracker_extract_info_get_update
-tracker_extract_info_get_where_clause
 tracker_extract_client_cancel_for_prefix
 </SECTION>
+
+<SECTION>
+<FILE>tracker-extract-info</FILE>
+TrackerExtractInfo
+tracker_extract_info_new
+tracker_extract_info_ref
+tracker_extract_info_unref
+tracker_extract_info_get_preupdate_builder
+tracker_extract_info_get_metadata_builder
+tracker_extract_info_get_where_clause
+tracker_extract_info_set_where_clause
+tracker_extract_info_get_file
+tracker_extract_info_get_mimetype
+tracker_extract_info_get_graph
+</SECTION>
diff --git a/src/libtracker-extract/Makefile.am b/src/libtracker-extract/Makefile.am
index 79ed232..f3be025 100644
--- a/src/libtracker-extract/Makefile.am
+++ b/src/libtracker-extract/Makefile.am
@@ -19,6 +19,8 @@ libtracker_extract_ TRACKER_API_VERSION@_la_SOURCES =  \
 	tracker-exif.h                                 \
 	tracker-extract-client.c                       \
 	tracker-extract-client.h                       \
+	tracker-extract-info.c                         \
+	tracker-extract-info.h                         \
 	tracker-guarantee.c                            \
 	tracker-guarantee.h                            \
 	tracker-iptc.c                                 \
@@ -36,6 +38,7 @@ libtracker_extractinclude_HEADERS =                    \
 	tracker-encoding.h                             \
 	tracker-exif.h                                 \
 	tracker-extract-client.h                       \
+	tracker-extract-info.h                         \
 	tracker-extract.h                              \
 	tracker-guarantee.h                            \
 	tracker-iptc.h                                 \
diff --git a/src/libtracker-extract/tracker-extract-client.c b/src/libtracker-extract/tracker-extract-client.c
index 56b6eba..e082801 100644
--- a/src/libtracker-extract/tracker-extract-client.c
+++ b/src/libtracker-extract/tracker-extract-client.c
@@ -33,12 +33,6 @@
 
 static GDBusConnection *connection = NULL;
 
-struct TrackerExtractInfo {
-	gchar *preupdate;
-	gchar *update;
-	gchar *where;
-};
-
 typedef void (* SendAndSpliceCallback) (void     *buffer,
                                         gssize    buffer_size,
                                         GError   *error, /* Don't free */
@@ -50,36 +44,16 @@ typedef struct {
 	GOutputStream *output_stream;
 	SendAndSpliceCallback callback;
 	GCancellable *cancellable;
-	GSimpleAsyncResult *res;
+	gpointer data;
 	gboolean splice_finished;
 	gboolean dbus_finished;
 	GError *error;
 } SendAndSpliceData;
 
-TrackerExtractInfo *
-tracker_extract_info_new (const gchar *preupdate,
-                          const gchar *update,
-                          const gchar *where)
-{
+typedef struct {
 	TrackerExtractInfo *info;
-
-	info = g_slice_new0 (TrackerExtractInfo);
-	info->preupdate = g_strdup (preupdate);
-	info->update = g_strdup (update);
-	info->where = g_strdup (where);
-
-	return info;
-}
-
-void
-tracker_extract_info_free (TrackerExtractInfo *info)
-{
-	g_free (info->preupdate);
-	g_free (info->update);
-	g_free (info->where);
-
-	g_slice_free (TrackerExtractInfo, info);
-}
+	GSimpleAsyncResult *res;
+} MetadataCallData;
 
 static SendAndSpliceData *
 send_and_splice_data_new (GInputStream          *unix_input_stream,
@@ -87,7 +61,7 @@ send_and_splice_data_new (GInputStream          *unix_input_stream,
                           GOutputStream         *output_stream,
                           GCancellable          *cancellable,
                           SendAndSpliceCallback  callback,
-                          GSimpleAsyncResult    *res)
+                          gpointer               user_data)
 {
 	SendAndSpliceData *data;
 
@@ -101,7 +75,7 @@ send_and_splice_data_new (GInputStream          *unix_input_stream,
 	}
 
 	data->callback = callback;
-	data->res = g_object_ref (res);
+	data->data = user_data;
 
 	return data;
 }
@@ -121,13 +95,30 @@ send_and_splice_data_free (SendAndSpliceData *data)
 		g_error_free (data->error);
 	}
 
-	if (data->res) {
-		g_object_unref (data->res);
-	}
-
 	g_slice_free (SendAndSpliceData, data);
 }
 
+static MetadataCallData *
+metadata_call_data_new (TrackerExtractInfo *info,
+                        GSimpleAsyncResult *res)
+{
+	MetadataCallData *data;
+
+	data = g_slice_new (MetadataCallData);
+	data->res = g_object_ref (res);
+	data->info = tracker_extract_info_ref (info);
+
+	return data;
+}
+
+static void
+metadata_call_data_free (MetadataCallData *data)
+{
+	tracker_extract_info_unref (data->info);
+	g_object_unref (data->res);
+	g_slice_free (MetadataCallData, data);
+}
+
 static void
 dbus_send_and_splice_async_finish (SendAndSpliceData *data)
 {
@@ -135,9 +126,9 @@ dbus_send_and_splice_async_finish (SendAndSpliceData *data)
 		(* data->callback) (g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (data->output_stream)),
 		                    g_memory_output_stream_get_data_size (G_MEMORY_OUTPUT_STREAM (data->output_stream)),
 		                    NULL,
-		                    data->res);
+		                    data->data);
 	} else {
-		(* data->callback) (NULL, -1, data->error, data->res);
+		(* data->callback) (NULL, -1, data->error, data->data);
 	}
 
 	send_and_splice_data_free (data);
@@ -209,7 +200,7 @@ dbus_send_and_splice_async (GDBusConnection       *connection,
                             int                    fd,
                             GCancellable          *cancellable,
                             SendAndSpliceCallback  callback,
-                            GSimpleAsyncResult    *res)
+                            gpointer               user_data)
 {
 	SendAndSpliceData *data;
 	GInputStream *unix_input_stream;
@@ -226,7 +217,7 @@ dbus_send_and_splice_async (GDBusConnection       *connection,
 	                                 output_stream,
 	                                 cancellable,
 	                                 callback,
-	                                 res);
+	                                 user_data);
 
 	g_dbus_connection_send_message_with_reply (connection,
 	                                           message,
@@ -253,15 +244,15 @@ get_metadata_fast_cb (void     *buffer,
                       GError   *error,
                       gpointer  user_data)
 {
-	GSimpleAsyncResult *res;
+	MetadataCallData *data;
 
-	res = user_data;
+	data = user_data;
 
 	if (G_UNLIKELY (error)) {
-		g_simple_async_result_set_from_error (res, error);
+		g_simple_async_result_set_from_error (data->res, error);
 	} else {
 		const gchar *preupdate, *sparql, *where, *end;
-		TrackerExtractInfo *info;
+		TrackerSparqlBuilder *builder;
 		gsize len;
 
 		preupdate = sparql = where = NULL;
@@ -282,25 +273,36 @@ get_metadata_fast_cb (void     *buffer,
 			}
 		}
 
-		info = tracker_extract_info_new (preupdate, sparql, where);
-		g_simple_async_result_set_op_res_gpointer (res, info,
-		                                           (GDestroyNotify) tracker_extract_info_free);
+		tracker_extract_info_set_where_clause (data->info, where);
+
+		builder = tracker_extract_info_get_preupdate_builder (data->info);
+		tracker_sparql_builder_prepend (builder, preupdate);
+
+		builder = tracker_extract_info_get_metadata_builder (data->info);
+		tracker_sparql_builder_prepend (builder, sparql);
+
+		g_simple_async_result_set_op_res_gpointer (data->res,
+		                                           tracker_extract_info_ref (data->info),
+		                                           (GDestroyNotify) tracker_extract_info_unref);
 	}
 
-	g_simple_async_result_complete_in_idle (res);
-	g_object_unref (res);
+	g_simple_async_result_complete_in_idle (data->res);
+	metadata_call_data_free (data);
 }
 
 static void
 get_metadata_fast_async (GDBusConnection    *connection,
-                         const gchar        *uri,
+                         GFile              *file,
                          const gchar        *mime_type,
                          GCancellable       *cancellable,
                          GSimpleAsyncResult *res)
 {
+	MetadataCallData *data;
+	TrackerExtractInfo *info;
 	GDBusMessage *message;
 	GUnixFDList *fd_list;
 	int pipefd[2];
+	gchar *uri;
 
 	if (pipe (pipefd) < 0) {
 		g_critical ("Coudln't open pipe");
@@ -314,6 +316,7 @@ get_metadata_fast_async (GDBusConnection    *connection,
 	                                          "GetMetadataFast");
 
 	fd_list = g_unix_fd_list_new ();
+	uri = g_file_get_uri (file);
 
 	g_dbus_message_set_body (message,
 	                         g_variant_new ("(ssh)",
@@ -327,16 +330,20 @@ get_metadata_fast_async (GDBusConnection    *connection,
 	/* We need to close the fd as g_unix_fd_list_append duplicates the fd */
 
 	close (pipefd[1]);
-
 	g_object_unref (fd_list);
+	g_free (uri);
+
+	info = tracker_extract_info_new (file, mime_type, NULL);
+	data = metadata_call_data_new (info, res);
 
 	dbus_send_and_splice_async (connection,
 	                            message,
 	                            pipefd[0],
 	                            cancellable,
 	                            get_metadata_fast_cb,
-	                            res);
+	                            data);
 	g_object_unref (message);
+	tracker_extract_info_unref (info);
 }
 
 /**
@@ -363,7 +370,6 @@ tracker_extract_client_get_metadata (GFile               *file,
 {
 	GSimpleAsyncResult *res;
 	GError *error = NULL;
-	gchar *uri;
 
 	g_return_if_fail (G_IS_FILE (file));
 	g_return_if_fail (mime_type != NULL);
@@ -380,13 +386,11 @@ tracker_extract_client_get_metadata (GFile               *file,
 		}
 	}
 
-	uri = g_file_get_uri (file);
-
 	res = g_simple_async_result_new (G_OBJECT (file), callback, user_data, NULL);
 	g_simple_async_result_set_handle_cancellation (res, TRUE);
 
-	get_metadata_fast_async (connection, uri, mime_type, cancellable, res);
-	g_free (uri);
+	get_metadata_fast_async (connection, file, mime_type, cancellable, res);
+	g_object_unref (res);
 }
 
 /**
@@ -416,51 +420,6 @@ tracker_extract_client_get_metadata_finish (GFile         *file,
 }
 
 /**
- * tracker_extract_info_get_preupdate:
- * @info: a #TrackerExtractInfo
- *
- * returns the sparql clauses to be inserted before
- * the sparql insert/update for the file.
- *
- * Returns: (transfer none): the clauses to be inserted
- *          before update.
- **/
-const gchar *
-tracker_extract_info_get_preupdate (TrackerExtractInfo *info)
-{
-	return info->preupdate;
-}
-
-/**
- * tracker_extract_info_get_update:
- * @info: a #TrackerExtractInfo
- *
- * Sparql holding metadata for the file.
- *
- * Returns: (transfer none): Sparql to be inserted into
- *          the file update.
- **/
-const gchar *
-tracker_extract_info_get_update (TrackerExtractInfo *info)
-{
-	return info->update;
-}
-
-/**
- * tracker_extract_info_get_where_clause:
- * @info: 
- *
- * Where clause for the file update.
- *
- * Returns: (transfer none): the where clause.
- **/
-const gchar *
-tracker_extract_info_get_where_clause (TrackerExtractInfo *info)
-{
-	return info->where;
-}
-
-/**
  * tracker_extract_client_cancel_for_prefix:
  * @prefix: a #GFile
  *
diff --git a/src/libtracker-extract/tracker-extract-client.h b/src/libtracker-extract/tracker-extract-client.h
index 6d08487..dd6e058 100644
--- a/src/libtracker-extract/tracker-extract-client.h
+++ b/src/libtracker-extract/tracker-extract-client.h
@@ -25,11 +25,10 @@
 #endif
 
 #include <gio/gio.h>
+#include "tracker-extract-info.h"
 
 G_BEGIN_DECLS
 
-typedef struct TrackerExtractInfo TrackerExtractInfo;
-
 void                 tracker_extract_client_get_metadata        (GFile               *file,
                                                                  const gchar         *mime_type,
                                                                  GCancellable        *cancellable,
@@ -42,16 +41,6 @@ TrackerExtractInfo * tracker_extract_client_get_metadata_finish (GFile
 
 void                 tracker_extract_client_cancel_for_prefix   (GFile               *uri);
 
-TrackerExtractInfo * tracker_extract_info_new  (const gchar *preupdate,
-                                                const gchar *statements,
-                                                const gchar *where_clause);
-void                 tracker_extract_info_free (TrackerExtractInfo *info);
-
-
-const gchar * tracker_extract_info_get_preupdate    (TrackerExtractInfo *info);
-const gchar * tracker_extract_info_get_update       (TrackerExtractInfo *info);
-const gchar * tracker_extract_info_get_where_clause (TrackerExtractInfo *info);
-
 G_END_DECLS
 
 #endif /* __TRACKER_EXTRACT_CLIENT_H__ */
diff --git a/src/libtracker-extract/tracker-extract-info.c b/src/libtracker-extract/tracker-extract-info.c
new file mode 100644
index 0000000..ef3809c
--- /dev/null
+++ b/src/libtracker-extract/tracker-extract-info.c
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2011, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ *
+ * Author: Carlos Garnacho <carlos lanedo com>
+ */
+
+#include "tracker-extract-info.h"
+
+struct _TrackerExtractInfo
+{
+	TrackerSparqlBuilder *preupdate;
+	TrackerSparqlBuilder *metadata;
+	gchar *where_clause;
+
+	GFile *file;
+	gchar *mimetype;
+	gchar *graph;
+
+	gint ref_count;
+};
+
+G_DEFINE_BOXED_TYPE (TrackerExtractInfo, tracker_extract_info,
+                     tracker_extract_info_ref, tracker_extract_info_unref)
+
+/**
+ * tracker_extract_info_new:
+ * @file: a #GFile
+ * @mimetype: mimetype for @file
+ * @graph: SPARQL graph used for inserting data
+ *
+ * Returns a newly created #TrackerExtractInfo
+ *
+ * Returns: (transfer full): (boxed): A newly allocated #TrackerExtractInfo
+ **/
+TrackerExtractInfo *
+tracker_extract_info_new (GFile       *file,
+                          const gchar *mimetype,
+                          const gchar *graph)
+{
+	TrackerExtractInfo *info;
+
+	g_return_val_if_fail (G_IS_FILE (file), NULL);
+
+	info = g_slice_new0 (TrackerExtractInfo);
+	info->file = g_object_ref (file);
+	info->mimetype = g_strdup (mimetype);
+	info->graph = g_strdup (graph);
+
+	info->preupdate = tracker_sparql_builder_new_update ();
+	info->metadata = tracker_sparql_builder_new_embedded_insert ();
+
+	info->ref_count = 1;
+
+	return info;
+}
+
+/**
+ * tracker_extract_info_ref:
+ * @info: a #TrackerExtractInfo
+ *
+ * Increases the reference count of @info
+ *
+ * Returns: A new reference to @info
+ **/
+TrackerExtractInfo *
+tracker_extract_info_ref (TrackerExtractInfo *info)
+{
+	g_return_val_if_fail (info != NULL, NULL);
+
+	g_atomic_int_inc (&info->ref_count);
+
+	return info;
+}
+
+/**
+ * tracker_extract_info_unref:
+ * @info: a #TrackerExtractInfo
+ *
+ * Decreases the reference count of @info, freeing all its associated resources.
+ * if it reaches 0.
+ **/
+void
+tracker_extract_info_unref (TrackerExtractInfo *info)
+{
+	g_return_if_fail (info != NULL);
+
+	if (g_atomic_int_dec_and_test (&info->ref_count)) {
+		g_object_unref (info->file);
+		g_free (info->mimetype);
+		g_free (info->graph);
+
+		g_object_unref (info->preupdate);
+		g_object_unref (info->metadata);
+		g_free (info->where_clause);
+
+		g_slice_free (TrackerExtractInfo, info);
+	}
+}
+
+/**
+ * tracker_extract_info_get_file:
+ * @info: a #TrackerExtractInfo
+ *
+ * Returns a #GFile pointing to the file being affected
+ * by the metadata extraction represented by @info
+ *
+ * Returns: (transfer none): The file being inspected
+ **/
+GFile *
+tracker_extract_info_get_file (TrackerExtractInfo *info)
+{
+	g_return_val_if_fail (info != NULL, NULL);
+
+	return info->file;
+}
+
+/**
+ * tracker_extract_info_get_mimetype:
+ * @info: a #TrackerExtractInfo
+ *
+ * Returns the mimetype being used for the file
+ * metadata extraction.
+ *
+ * Returns: (transfer none): the mimetype being used
+ *          for extraction.
+ **/
+const gchar *
+tracker_extract_info_get_mimetype (TrackerExtractInfo *info)
+{
+	g_return_val_if_fail (info != NULL, NULL);
+
+	return info->mimetype;
+}
+
+/**
+ * tracker_extract_info_get_graph:
+ * @info: a #TrackerExtractInfo
+ *
+ * Returns the SPARQL graph that will be used when
+ * inserting metadata.
+ *
+ * Returns: (transfer none): The SPARQL graph the extract
+ *          operation belongs to.
+ **/
+const gchar *
+tracker_extract_info_get_graph (TrackerExtractInfo *info)
+{
+	g_return_val_if_fail (info != NULL, NULL);
+
+	return info->graph;
+}
+
+/**
+ * tracker_extract_info_get_preupdate_builder:
+ * @info: a #TrackerSparqlBuilder
+ *
+ * Returns a #TrackerSparqlBuilder containing any
+ * separate updates that could apply to the file,
+ * such as author/band information in audio files,
+ * and so on.
+ *
+ * Returns: (transfer none): miscellaneous metadata
+ **/
+TrackerSparqlBuilder *
+tracker_extract_info_get_preupdate_builder (TrackerExtractInfo *info)
+{
+	g_return_val_if_fail (info != NULL, NULL);
+
+	return info->preupdate;
+}
+
+/**
+ * tracker_extract_info_get_metadata_builder:
+ * @info: a #TrackerExtractInfo
+ *
+ * Returns a #TrackerSparqlBuilder containing the
+ * file metadata.
+ *
+ * Returns: (transfer none): the file metadata
+ **/
+TrackerSparqlBuilder *
+tracker_extract_info_get_metadata_builder (TrackerExtractInfo *info)
+{
+	g_return_val_if_fail (info != NULL, NULL);
+
+	return info->metadata;
+}
+
+/**
+ * tracker_extract_info_get_where_clause:
+ * @info: a #TrackerExtractInfo
+ *
+ * Returns the where clause that will apply to the
+ * other metadata contained in @info.
+ *
+ * Returns: (transfer none): The where clause
+ **/
+const gchar *
+tracker_extract_info_get_where_clause (TrackerExtractInfo *info)
+{
+	g_return_val_if_fail (info != NULL, NULL);
+
+	return info->where_clause;
+}
+
+/**
+ * tracker_extract_info_set_where_clause:
+ * @info: a #TrackerExtractInfo
+ * @where: Where clause for the file update.
+ *
+ * Sets the where clause for the returned metadata.
+ **/
+void
+tracker_extract_info_set_where_clause (TrackerExtractInfo *info,
+                                       const gchar        *where)
+{
+	g_return_if_fail (info != NULL);
+
+	g_free (info->where_clause);
+	info->where_clause = g_strdup (where);
+}
diff --git a/src/libtracker-extract/tracker-extract-info.h b/src/libtracker-extract/tracker-extract-info.h
new file mode 100644
index 0000000..f2da427
--- /dev/null
+++ b/src/libtracker-extract/tracker-extract-info.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2011, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ *
+ * Author: Carlos Garnacho <carlos lanedo com>
+ */
+
+#ifndef __TRACKER_EXTRACT_INFO_H__
+#define __TRACKER_EXTRACT_INFO_H__
+
+#if !defined (__LIBTRACKER_EXTRACT_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-extract/tracker-extract.h> must be included directly."
+#endif
+
+#include <libtracker-sparql/tracker-sparql.h>
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+typedef struct _TrackerExtractInfo TrackerExtractInfo;
+
+GType  tracker_extract_info_get_type (void) G_GNUC_CONST;
+
+TrackerExtractInfo * tracker_extract_info_new  (GFile              *file,
+                                                const gchar        *mimetype,
+                                                const gchar        *graph);
+
+TrackerExtractInfo * tracker_extract_info_ref   (TrackerExtractInfo *info);
+void                 tracker_extract_info_unref (TrackerExtractInfo *info);
+
+GFile *       tracker_extract_info_get_file     (TrackerExtractInfo *info);
+const gchar * tracker_extract_info_get_mimetype (TrackerExtractInfo *info);
+const gchar * tracker_extract_info_get_graph    (TrackerExtractInfo *info);
+
+TrackerSparqlBuilder * tracker_extract_info_get_preupdate_builder (TrackerExtractInfo *info);
+TrackerSparqlBuilder * tracker_extract_info_get_metadata_builder  (TrackerExtractInfo *info);
+
+const gchar * tracker_extract_info_get_where_clause (TrackerExtractInfo *info);
+void          tracker_extract_info_set_where_clause (TrackerExtractInfo *info,
+                                                     const gchar        *where);
+
+G_END_DECLS
+
+#endif /* __TRACKER_EXTRACT_INFO_H__ */
diff --git a/src/libtracker-extract/tracker-extract.h b/src/libtracker-extract/tracker-extract.h
index 8463b5d..5b53a4c 100644
--- a/src/libtracker-extract/tracker-extract.h
+++ b/src/libtracker-extract/tracker-extract.h
@@ -28,6 +28,7 @@
 #include "tracker-encoding.h"
 #include "tracker-exif.h"
 #include "tracker-extract-client.h"
+#include "tracker-extract-info.h"
 #include "tracker-module-manager.h"
 #include "tracker-guarantee.h"
 #include "tracker-iptc.h"
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index ba96fe5..eff4d44 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -2027,10 +2027,16 @@ extractor_get_failsafe_metadata_cb (GObject      *object,
 		g_error_free (error);
 		g_free (uri);
 	} else {
+		TrackerSparqlBuilder *builder;
+
 		g_debug ("  Extraction succeeded the second time");
 
-		preupdate = tracker_extract_info_get_preupdate (info);
-		sparql = tracker_extract_info_get_update (info);
+		builder = tracker_extract_info_get_preupdate_builder (info);
+		preupdate = tracker_sparql_builder_get_result (builder);
+
+		builder = tracker_extract_info_get_metadata_builder (info);
+		sparql = tracker_sparql_builder_get_result (builder);
+
 		where = tracker_extract_info_get_where_clause (info);
 	}
 
@@ -2119,7 +2125,8 @@ extractor_get_embedded_metadata_cb (GObject      *object,
 	TrackerMinerFilesPrivate *priv;
 	TrackerMinerFiles *miner;
 	ProcessFileData *data = user_data;
-	const gchar *preupdate, *sparql, *where;
+	TrackerSparqlBuilder *preupdate, *sparql;
+	const gchar *where;
 	TrackerExtractInfo *info;
 	GError *error = NULL;
 
@@ -2157,11 +2164,14 @@ extractor_get_embedded_metadata_cb (GObject      *object,
 
 		g_error_free (error);
 	} else {
-		preupdate = tracker_extract_info_get_preupdate (info);
-		sparql = tracker_extract_info_get_update (info);
+		preupdate = tracker_extract_info_get_preupdate_builder (info);
+		sparql = tracker_extract_info_get_metadata_builder (info);
 		where = tracker_extract_info_get_where_clause (info);
 
-		sparql_builder_finish (data, preupdate, sparql, where);
+		sparql_builder_finish (data,
+		                       tracker_sparql_builder_get_result (preupdate),
+		                       tracker_sparql_builder_get_result (sparql),
+		                       where);
 
 		/* Notify about the success */
 		tracker_miner_fs_file_notify (TRACKER_MINER_FS (data->miner), data->file, NULL);
diff --git a/src/tracker-extract/tracker-controller.c b/src/tracker-extract/tracker-controller.c
index f59e3fc..42aa126 100644
--- a/src/tracker-extract/tracker-controller.c
+++ b/src/tracker-extract/tracker-controller.c
@@ -441,9 +441,14 @@ get_metadata_cb (GObject      *object,
 
 	if (info) {
 		const gchar *preupdate, *statements, *where;
+		TrackerSparqlBuilder *builder;
+
+		builder = tracker_extract_info_get_preupdate_builder (info);
+		preupdate = tracker_sparql_builder_get_result (builder);
+
+		builder = tracker_extract_info_get_metadata_builder (info);
+		statements = tracker_sparql_builder_get_result (builder);
 
-		preupdate = tracker_extract_info_get_preupdate (info);
-		statements = tracker_extract_info_get_update (info);
 		where = tracker_extract_info_get_where_clause (info);
 
 		if (statements && *statements) {
@@ -549,6 +554,7 @@ get_metadata_fast_cb (GObject      *object,
 		GOutputStream *buffered_output_stream;
 		GDataOutputStream *data_output_stream;
 		const gchar *preupdate, *statements, *where;
+		TrackerSparqlBuilder *builder;
 		GError *error = NULL;
 
 #ifdef THREAD_ENABLE_TRACE
@@ -563,8 +569,12 @@ get_metadata_fast_cb (GObject      *object,
 		g_data_output_stream_set_byte_order (G_DATA_OUTPUT_STREAM (data_output_stream),
 		                                     G_DATA_STREAM_BYTE_ORDER_HOST_ENDIAN);
 
-		preupdate = tracker_extract_info_get_preupdate (info);
-		statements = tracker_extract_info_get_update (info);
+		builder = tracker_extract_info_get_preupdate_builder (info);
+		preupdate = tracker_sparql_builder_get_result (builder);
+
+		builder = tracker_extract_info_get_metadata_builder (info);
+		statements = tracker_sparql_builder_get_result (builder);
+
 		where = tracker_extract_info_get_where_clause (info);
 
 		if (statements && *statements) {
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index 9e2c0ef..71b1d1c 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -274,13 +274,13 @@ notify_task_finish (TrackerExtractTask *task,
 }
 
 static gboolean
-get_file_metadata (TrackerExtractTask     *task,
-                   TrackerSparqlBuilder  **preupdate_out,
-                   TrackerSparqlBuilder  **statements_out,
-                   gchar                 **where_out)
+get_file_metadata (TrackerExtractTask  *task,
+                   TrackerExtractInfo **info_out)
 {
+	TrackerExtractInfo *info;
 	TrackerSparqlBuilder *statements, *preupdate;
 	GString *where;
+	GFile *file;
 	gchar *mime_used = NULL;
 #ifdef HAVE_LIBSTREAMANALYZER
 	gchar *content_type = NULL;
@@ -289,13 +289,14 @@ get_file_metadata (TrackerExtractTask     *task,
 
 	g_debug ("Extracting...");
 
-	*preupdate_out = NULL;
-	*statements_out = NULL;
-	*where_out = NULL;
+	*info_out = NULL;
+
+	file = g_file_new_for_uri (task->file);
+	info = tracker_extract_info_new (file, task->mimetype, NULL);
+	g_object_unref (file);
 
-	/* Create sparql builders to send back */
-	preupdate = tracker_sparql_builder_new_update ();
-	statements = tracker_sparql_builder_new_embedded_insert ();
+	preupdate = tracker_extract_info_get_preupdate_builder (info);
+	statements = tracker_extract_info_get_metadata_builder (info);
 	where = g_string_new ("");
 
 #ifdef HAVE_LIBSTREAMANALYZER
@@ -308,9 +309,10 @@ get_file_metadata (TrackerExtractTask     *task,
 			g_free (content_type);
 			tracker_sparql_builder_insert_close (statements);
 
-			*preupdate_out = preupdate;
-			*statements_out = statements;
-			*where_out = g_string_free (where, FALSE);
+			tracker_extract_info_set_where_clause (info,
+			                                       g_string_free (where, FALSE));
+			*info_out = info;
+
 			return TRUE;
 		}
 	} else {
@@ -356,9 +358,9 @@ get_file_metadata (TrackerExtractTask     *task,
 		g_free (mime_used);
 	}
 
-	*preupdate_out = preupdate;
-	*statements_out = statements;
-	*where_out = g_string_free (where, FALSE);
+	tracker_extract_info_set_where_clause (info,
+	                                       g_string_free (where, FALSE));
+	*info_out = info;
 
 	if (items == 0) {
 		g_debug ("No extractor or failed");
@@ -532,14 +534,10 @@ get_metadata (TrackerExtractTask *task)
 	}
 
 	if (!filter_module (task->extract, task->cur_module) &&
-	    get_file_metadata (task, &preupdate, &statements, &where)) {
-		info = tracker_extract_info_new ((preupdate) ? tracker_sparql_builder_get_result (preupdate) : NULL,
-		                                 (statements) ? tracker_sparql_builder_get_result (statements) : NULL,
-		                                 where);
-
+	    get_file_metadata (task, &info)) {
 		g_simple_async_result_set_op_res_gpointer ((GSimpleAsyncResult *) task->res,
 		                                           info,
-		                                           (GDestroyNotify) tracker_extract_info_free);
+		                                           (GDestroyNotify) tracker_extract_info_unref);
 
 		g_simple_async_result_complete_in_idle ((GSimpleAsyncResult *) task->res);
 		extract_task_free (task);
@@ -757,11 +755,10 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
                                          const gchar    *uri,
                                          const gchar    *mime)
 {
-	TrackerSparqlBuilder *statements, *preupdate;
 	GError *error = NULL;
-	gchar *where;
 	TrackerExtractPrivate *priv;
 	TrackerExtractTask *task;
+	TrackerExtractInfo *info;
 	gboolean no_modules = TRUE;
 
 	priv = TRACKER_EXTRACT_GET_PRIVATE (object);
@@ -783,20 +780,27 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
 
 	while (task->cur_module && task->cur_func) {
 		if (!filter_module (object, task->cur_module) &&
-		    get_file_metadata (task, &preupdate, &statements, &where)) {
-			const gchar *preupdate_str, *statements_str;
+		    get_file_metadata (task, &info)) {
+			const gchar *preupdate_str, *statements_str, *where;
+			TrackerSparqlBuilder *builder;
 
 			no_modules = FALSE;
 			preupdate_str = statements_str = NULL;
 
-			if (tracker_sparql_builder_get_length (statements) > 0) {
-				statements_str = tracker_sparql_builder_get_result (statements);
+			builder = tracker_extract_info_get_metadata_builder (info);
+
+			if (tracker_sparql_builder_get_length (builder) > 0) {
+				statements_str = tracker_sparql_builder_get_result (builder);
 			}
 
-			if (tracker_sparql_builder_get_length (preupdate) > 0) {
-				preupdate_str = tracker_sparql_builder_get_result (preupdate);
+			builder = tracker_extract_info_get_preupdate_builder (info);
+
+			if (tracker_sparql_builder_get_length (builder) > 0) {
+				preupdate_str = tracker_sparql_builder_get_result (builder);
 			}
 
+			where = tracker_extract_info_get_where_clause (info);
+
 			g_print ("\n");
 
 			g_print ("SPARQL pre-update:\n--\n%s--\n\n",
@@ -806,9 +810,7 @@ tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
 			g_print ("SPARQL where clause:\n--\n%s--\n\n",
 			         where ? where : "");
 
-			g_object_unref (statements);
-			g_object_unref (preupdate);
-			g_free (where);
+			tracker_extract_info_unref (info);
 			break;
 		} else {
 			if (!tracker_mimetype_info_iter_next (task->mimetype_handlers)) {



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