[tracker/tracker-store] tracker-extract: Return metadata as SPARQL Update
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker/tracker-store] tracker-extract: Return metadata as SPARQL Update
- Date: Thu, 25 Jun 2009 11:58:51 +0000 (UTC)
commit 2e44232d01256a0032f83473fd18472e37e271c9
Author: Jürg Billeter <j bitron ch>
Date: Tue Jun 23 14:40:59 2009 +0200
tracker-extract: Return metadata as SPARQL Update
data/dbus/tracker-extract.xml | 2 +-
src/libtracker-common/tracker-sparql-builder.vala | 6 ++
src/tracker-extract/tracker-extract.c | 56 ++++++++++++++++++--
.../tracker-module-metadata-utils.c | 28 ++--------
4 files changed, 64 insertions(+), 28 deletions(-)
---
diff --git a/data/dbus/tracker-extract.xml b/data/dbus/tracker-extract.xml
index 7e6db82..8b2dc9d 100644
--- a/data/dbus/tracker-extract.xml
+++ b/data/dbus/tracker-extract.xml
@@ -19,7 +19,7 @@
<annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
<arg type="s" name="uri" direction="in" />
<arg type="s" name="mime" direction="in" />
- <arg type="a(sss)" name="statements" direction="out" />
+ <arg type="s" name="sparql" direction="out" />
</method>
</interface>
</node>
diff --git a/src/libtracker-common/tracker-sparql-builder.vala b/src/libtracker-common/tracker-sparql-builder.vala
index 635c60b..c350ebc 100644
--- a/src/libtracker-common/tracker-sparql-builder.vala
+++ b/src/libtracker-common/tracker-sparql-builder.vala
@@ -186,5 +186,11 @@ public class Tracker.SparqlBuilder : Object {
states.length -= 3;
states += State.OBJECT;
}
+
+ public void append (string raw)
+ requires (states.length == 1)
+ {
+ str.append (raw);
+ }
}
diff --git a/src/tracker-extract/tracker-extract.c b/src/tracker-extract/tracker-extract.c
index 39cb110..12c6642 100644
--- a/src/tracker-extract/tracker-extract.c
+++ b/src/tracker-extract/tracker-extract.c
@@ -27,6 +27,7 @@
#include <gio/gio.h>
#include <libtracker-common/tracker-dbus.h>
+#include <libtracker-common/tracker-sparql-builder.h>
#include "tracker-main.h"
#include "tracker-dbus.h"
@@ -392,6 +393,51 @@ get_file_metadata (TrackerExtract *extract,
return statements;
}
+static gchar *
+get_file_metadata_as_sparql (TrackerExtract *extract,
+ guint request_id,
+ const gchar *uri,
+ const gchar *mime)
+{
+ TrackerSparqlBuilder *sparql;
+ GPtrArray *statements;
+ gint i;
+ gchar *result;
+
+ statements = get_file_metadata (extract, request_id, uri, mime);
+
+ sparql = tracker_sparql_builder_new_update ();
+ tracker_sparql_builder_insert_open (sparql);
+
+ if (statements) {
+ for (i = 0; i < statements->len; i++) {
+ GValueArray *statement;
+ const gchar *subject;
+ const gchar *predicate;
+ const gchar *object;
+
+ statement = statements->pdata[i];
+
+ subject = g_value_get_string (&statement->values[0]);
+ predicate = g_value_get_string (&statement->values[1]);
+ object = g_value_get_string (&statement->values[2]);
+
+ tracker_sparql_builder_subject_iri (sparql, subject);
+ tracker_sparql_builder_predicate_iri (sparql, predicate);
+ tracker_sparql_builder_object_string (sparql, object);
+ }
+ statements_free (statements);
+ }
+
+ tracker_sparql_builder_insert_close (sparql);
+
+ result = g_strdup (tracker_sparql_builder_get_result (sparql));
+
+ g_object_unref (sparql);
+
+ return result;
+}
+
void
tracker_extract_get_metadata_by_cmdline (TrackerExtract *object,
const gchar *uri,
@@ -465,7 +511,7 @@ tracker_extract_get_metadata (TrackerExtract *object,
GError **error)
{
guint request_id;
- GPtrArray *statements = NULL;
+ gchar *sparql = NULL;
request_id = tracker_dbus_get_next_request_id ();
@@ -485,11 +531,11 @@ tracker_extract_get_metadata (TrackerExtract *object,
alarm (MAX_EXTRACT_TIME);
}
- statements = get_file_metadata (object, request_id, uri, mime);
+ sparql = get_file_metadata_as_sparql (object, request_id, uri, mime);
- if (statements) {
- dbus_g_method_return (context, statements);
- statements_free (statements);
+ if (sparql) {
+ dbus_g_method_return (context, sparql);
+ g_free (sparql);
tracker_dbus_request_success (request_id);
} else {
GError *actual_error = NULL;
diff --git a/src/tracker-indexer/tracker-module-metadata-utils.c b/src/tracker-indexer/tracker-module-metadata-utils.c
index 7510f5c..0c60ec6 100644
--- a/src/tracker-indexer/tracker-module-metadata-utils.c
+++ b/src/tracker-indexer/tracker-module-metadata-utils.c
@@ -316,12 +316,11 @@ extractor_context_kill (ExtractorContext *context)
static void
get_metadata_async_cb (DBusGProxy *proxy,
- GPtrArray *statements,
+ gchar *sparql,
GError *error,
gpointer user_data)
{
ExtractorContext *context;
- gint i;
gboolean should_kill = TRUE;
@@ -353,26 +352,11 @@ get_metadata_async_cb (DBusGProxy *proxy,
if (should_kill) {
extractor_context_kill (context);
}
- } else if (statements) {
- for (i = 0; i < statements->len; i++) {
- GValueArray *statement;
- const gchar *subject;
- const gchar *predicate;
- const gchar *object;
-
- statement = statements->pdata[i];
- subject = g_value_get_string (&statement->values[0]);
- predicate = g_value_get_string (&statement->values[1]);
- object = g_value_get_string (&statement->values[2]);
-
- tracker_sparql_builder_subject_iri (context->metadata, subject);
- tracker_sparql_builder_predicate_iri (context->metadata, predicate);
- tracker_sparql_builder_object_string (context->metadata, object);
-
- g_value_array_free (statement);
- }
-
- g_ptr_array_free (statements, TRUE);
+ } else if (sparql) {
+ tracker_sparql_builder_insert_close (context->metadata);
+ tracker_sparql_builder_append (context->metadata, sparql);
+ tracker_sparql_builder_insert_open (context->metadata);
+ g_free (sparql);
}
g_main_loop_quit (context->main_loop);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]