tracker r2601 - in branches/turtle: . src/libtracker-data src/trackerd
- From: ifrade svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r2601 - in branches/turtle: . src/libtracker-data src/trackerd
- Date: Thu, 27 Nov 2008 15:23:14 +0000 (UTC)
Author: ifrade
Date: Thu Nov 27 15:23:14 2008
New Revision: 2601
URL: http://svn.gnome.org/viewvc/tracker?rev=2601&view=rev
Log:
Adding processing method in tracker-turtle
Modified:
branches/turtle/ChangeLog
branches/turtle/src/libtracker-data/tracker-turtle.c
branches/turtle/src/libtracker-data/tracker-turtle.h
branches/turtle/src/trackerd/Makefile.am
branches/turtle/src/trackerd/tracker-backup.c
branches/turtle/src/trackerd/tracker-backup.h
Modified: branches/turtle/src/libtracker-data/tracker-turtle.c
==============================================================================
--- branches/turtle/src/libtracker-data/tracker-turtle.c (original)
+++ branches/turtle/src/libtracker-data/tracker-turtle.c Thu Nov 27 15:23:14 2008
@@ -33,25 +33,8 @@
#include <glib/gstdio.h>
#include <gio/gio.h>
-#include <gmodule.h>
-
#include <raptor.h>
-#include <libtracker-common/tracker-file-utils.h>
-#include <libtracker-common/tracker-language.h>
-#include <libtracker-common/tracker-parser.h>
-#include <libtracker-common/tracker-ontology.h>
-#include <libtracker-common/tracker-module-config.h>
-#include <libtracker-common/tracker-utils.h>
-
-#include <libtracker-db/tracker-db-manager.h>
-#include <libtracker-db/tracker-db-index-manager.h>
-#include <libtracker-db/tracker-db-interface-sqlite.h>
-
-#include <libtracker-data/tracker-data-query.h>
-#include <libtracker-data/tracker-data-update.h>
-
-
#endif /* HAVE_RAPTOR */
static gboolean initialized = FALSE;
@@ -224,4 +207,49 @@
#endif
}
+#ifdef HAVE_RAPTOR
+static void
+raptor_error (void *user_data, raptor_locator* locator, const char *message)
+{
+ g_message ("RAPTOR parse error: %s for %s\n",
+ message,
+ (gchar *) user_data);
+}
+#endif
+
+void
+tracker_turtle_process (const gchar *turtle_file,
+ TurtleTripleCallback callback,
+ void *user_data)
+{
+#ifdef HAVE_RAPTOR
+ unsigned char *uri_string;
+ raptor_uri *uri;
+ raptor_parser *parser;
+#endif
+ if (!initialized) {
+ g_critical ("Using tracker_turtle module without initialization");
+ }
+
+#ifdef HAVE_RAPTOR
+
+ parser = raptor_new_parser ("turtle");
+
+ raptor_set_statement_handler (parser, user_data, (raptor_statement_handler) callback);
+ raptor_set_fatal_error_handler (parser, (void *)turtle_file, raptor_error);
+ raptor_set_error_handler (parser, (void *)turtle_file, raptor_error);
+ raptor_set_warning_handler (parser, (void *)turtle_file, raptor_error);
+
+ uri_string = raptor_uri_filename_to_uri_string (turtle_file);
+ uri = raptor_new_uri (uri_string);
+
+ raptor_parse_file (parser, uri, uri);
+
+ raptor_free_uri (uri);
+ raptor_free_memory (uri_string);
+
+ raptor_free_parser (parser);
+
+#endif
+}
Modified: branches/turtle/src/libtracker-data/tracker-turtle.h
==============================================================================
--- branches/turtle/src/libtracker-data/tracker-turtle.h (original)
+++ branches/turtle/src/libtracker-data/tracker-turtle.h Thu Nov 27 15:23:14 2008
@@ -27,8 +27,22 @@
#include <libtracker-data/tracker-data-metadata.h>
#include <stdio.h>
+/*
+ * TODO: Is it possible to do this in the .c file? Dont expose raptor here.
+*/
+#ifdef HAVE_RAPTOR
+#include <raptor.h>
+typedef raptor_statement stmt;
+#else
+typedef void stmt;
+#endif
+
+typedef void (* TurtleTripleCallback) (void *user_data, const stmt *triple);
+
typedef struct TurtleFile TurtleFile;
+
+
typedef struct {
gchar *about_uri;
TrackerDataMetadata *metadata;
@@ -52,5 +66,11 @@
GPtrArray /* <MetadataItem> */ *metadata_items);
void tracker_turtle_close (TurtleFile *turtle);
+/* Reading functions */
+void tracker_turtle_process (const gchar *turtle_file,
+ TurtleTripleCallback callback,
+ void *user_data);
+
+
#endif /* __TRACKER_TURTLE_H__ */
Modified: branches/turtle/src/trackerd/Makefile.am
==============================================================================
--- branches/turtle/src/trackerd/Makefile.am (original)
+++ branches/turtle/src/trackerd/Makefile.am Thu Nov 27 15:23:14 2008
@@ -17,6 +17,7 @@
$(GIO_CFLAGS) \
$(GMODULE_CFLAGS) \
$(GTHREAD_CFLAGS) \
+ $(RAPTOR_CFLAGS) \
$(GLIB2_CFLAGS)
if HAVE_INOTIFY
@@ -85,6 +86,7 @@
$(GMODULE_LIBS) \
$(GTHREAD_LIBS) \
$(GLIB2_LIBS) \
+ $(RAPTOR_LIBS) \
$(trackerd_win_libs) \
-lz \
-lm
Modified: branches/turtle/src/trackerd/tracker-backup.c
==============================================================================
--- branches/turtle/src/trackerd/tracker-backup.c (original)
+++ branches/turtle/src/trackerd/tracker-backup.c Thu Nov 27 15:23:14 2008
@@ -1,47 +1,34 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ */
+#include "config.h"
+
#include "tracker-backup.h"
+
#include <libtracker-data/tracker-data-query.h>
#include <libtracker-data/tracker-turtle.h>
#include <glib.h>
+#include <raptor.h>
-static gchar *
-list_to_str (GList *list) {
-
- GList *tmp;
- GString *str;
-
- str = g_string_new ("");
-
- for (tmp = list; tmp != NULL; tmp = tmp->next) {
- g_string_append (str, g_strdup ((gchar *)tmp->data));
- g_string_append (str, "-");
- }
-
- return g_string_free (str, FALSE);
-}
-
-static void
-debug_tracker_data_metadata (TrackerField *field, gpointer value, gpointer user_data)
-{
- if (tracker_field_get_multiple_values (field)) {
- g_debug (" tracker_backup: %s = %s",
- tracker_field_get_name (field),
- list_to_str ((GList *)value));
- } else {
- g_debug (" tracker_backup: %s = %s",
- tracker_field_get_name (field),
- (gchar *) value);
- }
-}
-
-static void
-debug_sophisticated_metadata (gpointer key, gpointer value, gpointer user_data)
-{
- gchar *uri = (gchar *)key;
- TrackerDataMetadata *metadata = (TrackerDataMetadata *)value;
-
- g_debug (" tracker_backup : %s", uri);
- tracker_data_metadata_foreach (metadata, debug_tracker_data_metadata, NULL);
-}
+/* TODO (obviously) */
+#define TODO_TEMPORARY_LOCATION "/tmp/tracker-saving-things.ttl"
/*
* (uri, metadataid, value)
@@ -58,7 +45,7 @@
tracker_turtle_init ();
/* TODO: temporary location */
- turtle_file = tracker_turtle_open ("/tmp/tracker-saving-things.ttl");
+ turtle_file = tracker_turtle_open (TODO_TEMPORARY_LOCATION);
while (valid) {
GValue transform = {0, };
@@ -69,21 +56,7 @@
g_value_init (&transform, G_TYPE_STRING);
tracker_db_result_set_get (result_set, 0, &uri, -1);
tracker_db_result_set_get (result_set, 1, &metadata_id, -1);
- _tracker_db_result_set_get_value (result_set, 2, &value);
-
- if (g_value_transform (&value, &transform)) {
- str = g_value_dup_string (&transform);
-
- if (!str) {
- str = g_strdup ("");
- } else if (!g_utf8_validate (str, -1, NULL)) {
- g_warning ("Could not add string:'%s' to GStrv, invalid UTF-8", str);
- g_free (str);
- str = g_strdup ("");
- }
- } else {
- str = g_strdup ("");
- }
+ tracker_db_result_set_get (result_set, 2, &str, -1);
field = tracker_ontology_get_field_by_id (metadata_id);
if (!field) {
@@ -93,7 +66,8 @@
return;
}
- g_debug ("Insertion in turtle");
+ g_debug ("Insertion in turtle <%s, %s, %s>",
+ uri, tracker_field_get_name (field), str);
tracker_turtle_add_triple (turtle_file, uri, field, str);
g_free (str);
@@ -122,9 +96,31 @@
}
}
+
+static void
+loading_turtle (void *user_data, const stmt *triple)
+{
+ gchar *subject, *predicate;
+#ifdef HAVE_RAPTOR
+ subject = (gchar *) raptor_uri_as_string ((raptor_uri *) triple->subject);
+ predicate = g_strdup ((const gchar *) raptor_uri_as_string ((raptor_uri *) triple->predicate));
+
+ g_print ("turtle loading <%s, %s, %s>\n",
+ (gchar *)triple->subject,
+ (gchar *)triple->predicate,
+ (gchar *)triple->object);
+#else
+ g_debug ("No raptor support to restore metadata");
+#endif
+}
+
void
tracker_backup_restore ()
{
g_message ("***** Restoring metadata from turtle file *****");
+
+ tracker_turtle_init ();
+
+ tracker_turtle_process (TODO_TEMPORARY_LOCATION, loading_turtle, NULL);
}
Modified: branches/turtle/src/trackerd/tracker-backup.h
==============================================================================
--- branches/turtle/src/trackerd/tracker-backup.h (original)
+++ branches/turtle/src/trackerd/tracker-backup.h Thu Nov 27 15:23:14 2008
@@ -1,3 +1,23 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * Copyright (C) 2006, Mr Jamie McCracken (jamiemcc gnome org)
+ * Copyright (C) 2008, Nokia
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU 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.
+ */
#ifndef __TRACKER_BACKUP_H__
#define __TRACKER_BACKUP_H__
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]