[tracker/ontology-cope: 3/9] libtracker-common, libtracker-data: Introduce TrackerOntology class
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/ontology-cope: 3/9] libtracker-common, libtracker-data: Introduce TrackerOntology class
- Date: Thu, 18 Feb 2010 21:39:42 +0000 (UTC)
commit e4966a6f8a0912b2b054c506b3dad66de694afed
Author: Philip Van Hoof <philip codeminded be>
Date: Tue Feb 16 14:29:53 2010 +0100
libtracker-common, libtracker-data: Introduce TrackerOntology class
src/libtracker-common/Makefile.am | 2 +
src/libtracker-common/tracker-common.h | 1 +
src/libtracker-common/tracker-ontologies.c | 54 +++++++
src/libtracker-common/tracker-ontologies.h | 4 +
src/libtracker-common/tracker-ontology.c | 228 ++++++++++++++++++++++++++++
src/libtracker-common/tracker-ontology.h | 63 ++++++++
src/libtracker-data/tracker-data-manager.c | 25 +++-
7 files changed, 374 insertions(+), 3 deletions(-)
---
diff --git a/src/libtracker-common/Makefile.am b/src/libtracker-common/Makefile.am
index 64a5a14..7c2f37f 100644
--- a/src/libtracker-common/Makefile.am
+++ b/src/libtracker-common/Makefile.am
@@ -67,6 +67,7 @@ libtracker_common_la_SOURCES = \
tracker-language.c \
tracker-log.c \
tracker-namespace.c \
+ tracker-ontology.c \
tracker-ontologies.c \
tracker-property.c \
tracker-type-utils.c \
@@ -91,6 +92,7 @@ libtracker_commoninclude_HEADERS = \
tracker-keyfile-object.h \
tracker-language.h \
tracker-namespace.h \
+ tracker-ontology.h \
tracker-ontologies.h \
tracker-property.h \
tracker-turtle-writer.h \
diff --git a/src/libtracker-common/tracker-common.h b/src/libtracker-common/tracker-common.h
index 81245a5..b826c30 100644
--- a/src/libtracker-common/tracker-common.h
+++ b/src/libtracker-common/tracker-common.h
@@ -47,6 +47,7 @@ G_BEGIN_DECLS
#include "tracker-keyfile-object.h"
#include "tracker-language.h"
#include "tracker-namespace.h"
+#include "tracker-ontology.h"
#include "tracker-ontologies.h"
#include "tracker-property.h"
#include "tracker-type-utils.h"
diff --git a/src/libtracker-common/tracker-ontologies.c b/src/libtracker-common/tracker-ontologies.c
index 7d1894a..021ba52 100644
--- a/src/libtracker-common/tracker-ontologies.c
+++ b/src/libtracker-common/tracker-ontologies.c
@@ -35,6 +35,12 @@ static GPtrArray *namespaces;
/* Namespace uris */
static GHashTable *namespace_uris;
+/* List of TrackerOntology objects */
+static GPtrArray *ontologies;
+
+/* Ontology uris */
+static GHashTable *ontology_uris;
+
/* List of TrackerClass objects */
static GPtrArray *classes;
@@ -62,11 +68,18 @@ tracker_ontologies_init (void)
namespaces = g_ptr_array_new ();
+ ontologies = g_ptr_array_new ();
+
namespace_uris = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
g_object_unref);
+ ontology_uris = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ g_object_unref);
+
classes = g_ptr_array_new ();
class_uris = g_hash_table_new_full (g_str_hash,
@@ -107,6 +120,12 @@ tracker_ontologies_shutdown (void)
g_hash_table_unref (namespace_uris);
namespace_uris = NULL;
+ g_ptr_array_foreach (ontologies, (GFunc) g_object_unref, NULL);
+ g_ptr_array_free (ontologies, TRUE);
+
+ g_hash_table_unref (ontology_uris);
+ ontology_uris = NULL;
+
g_ptr_array_foreach (classes, (GFunc) g_object_unref, NULL);
g_ptr_array_free (classes, TRUE);
@@ -176,6 +195,18 @@ tracker_ontologies_get_namespaces (guint *length)
return (TrackerNamespace **) namespaces->pdata;
}
+TrackerOntology **
+tracker_ontologies_get_ontologies (guint *length)
+{
+ if (G_UNLIKELY (!ontologies)) {
+ *length = 0;
+ return NULL;
+ }
+
+ *length = ontologies->len;
+ return (TrackerOntology **) ontologies->pdata;
+}
+
TrackerClass **
tracker_ontologies_get_classes (guint *length)
{
@@ -249,6 +280,22 @@ tracker_ontologies_add_namespace (TrackerNamespace *namespace)
g_object_ref (namespace));
}
+void
+tracker_ontologies_add_ontology (TrackerOntology *ontology)
+{
+ const gchar *uri;
+
+ g_return_if_fail (TRACKER_IS_ONTOLOGY (ontology));
+
+ uri = tracker_ontology_get_uri (ontology);
+
+ g_ptr_array_add (ontologies, g_object_ref (ontology));
+
+ g_hash_table_insert (ontology_uris,
+ g_strdup (uri),
+ g_object_ref (ontology));
+}
+
TrackerNamespace *
tracker_ontologies_get_namespace_by_uri (const gchar *uri)
{
@@ -258,4 +305,11 @@ tracker_ontologies_get_namespace_by_uri (const gchar *uri)
}
+TrackerOntology *
+tracker_ontologies_get_ontology_by_uri (const gchar *uri)
+{
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ return g_hash_table_lookup (ontology_uris, uri);
+}
diff --git a/src/libtracker-common/tracker-ontologies.h b/src/libtracker-common/tracker-ontologies.h
index fb66770..4ebeff5 100644
--- a/src/libtracker-common/tracker-ontologies.h
+++ b/src/libtracker-common/tracker-ontologies.h
@@ -25,6 +25,7 @@
#include "tracker-class.h"
#include "tracker-namespace.h"
+#include "tracker-ontology.h"
#include "tracker-property.h"
G_BEGIN_DECLS
@@ -66,6 +67,7 @@ void tracker_ontologies_shutdown (void);
void tracker_ontologies_add_class (TrackerClass *service);
TrackerClass * tracker_ontologies_get_class_by_uri (const gchar *service_uri);
TrackerNamespace **tracker_ontologies_get_namespaces (guint *length);
+TrackerOntology **tracker_ontologies_get_ontologies (guint *length);
TrackerClass ** tracker_ontologies_get_classes (guint *length);
TrackerProperty ** tracker_ontologies_get_properties (guint *length);
@@ -73,7 +75,9 @@ TrackerProperty ** tracker_ontologies_get_properties (guint *length);
void tracker_ontologies_add_property (TrackerProperty *field);
TrackerProperty * tracker_ontologies_get_property_by_uri (const gchar *uri);
void tracker_ontologies_add_namespace (TrackerNamespace *namespace_);
+void tracker_ontologies_add_ontology (TrackerOntology *ontology);
TrackerNamespace * tracker_ontologies_get_namespace_by_uri (const gchar *namespace_uri);
+TrackerOntology * tracker_ontologies_get_ontology_by_uri (const gchar *namespace_uri);
const gchar* tracker_ontologies_get_uri_by_id (gint id);
void tracker_ontologies_add_id_uri_pair (gint id,
const gchar *uri);
diff --git a/src/libtracker-common/tracker-ontology.c b/src/libtracker-common/tracker-ontology.c
new file mode 100644
index 0000000..7111270
--- /dev/null
+++ b/src/libtracker-common/tracker-ontology.c
@@ -0,0 +1,228 @@
+/*
+ * Copyright (C) 2009, Nokia
+ *
+ * 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: Philip Van Hoof <philip codeminded be>
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <glib.h>
+
+#include "tracker-ontology.h"
+
+#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TRACKER_TYPE_ONTOLOGY, TrackerOntologyPriv))
+
+typedef struct _TrackerOntologyPriv TrackerOntologyPriv;
+
+struct _TrackerOntologyPriv {
+ gchar *uri;
+ gchar *last_modified;
+};
+
+static void ontology_finalize (GObject *object);
+static void ontology_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void ontology_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+
+enum {
+ PROP_0,
+ PROP_URI,
+ PROP_LAST_MODIFIED,
+};
+
+G_DEFINE_TYPE (TrackerOntology, tracker_ontology, G_TYPE_OBJECT);
+
+static void
+tracker_ontology_class_init (TrackerOntologyClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = ontology_finalize;
+ object_class->get_property = ontology_get_property;
+ object_class->set_property = ontology_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_URI,
+ g_param_spec_string ("uri",
+ "uri",
+ "URI",
+ NULL,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_LAST_MODIFIED,
+ g_param_spec_string ("last-modified",
+ "last-modified",
+ "Last modified",
+ NULL,
+ G_PARAM_READWRITE));
+
+ g_type_class_add_private (object_class, sizeof (TrackerOntologyPriv));
+}
+
+static void
+tracker_ontology_init (TrackerOntology *service)
+{
+}
+
+static void
+ontology_finalize (GObject *object)
+{
+ TrackerOntologyPriv *priv;
+
+ priv = GET_PRIV (object);
+
+ g_free (priv->uri);
+ g_free (priv->last_modified);
+
+ (G_OBJECT_CLASS (tracker_ontology_parent_class)->finalize) (object);
+}
+
+static void
+ontology_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerOntologyPriv *priv;
+
+ priv = GET_PRIV (object);
+
+ switch (param_id) {
+ case PROP_URI:
+ g_value_set_string (value, priv->uri);
+ break;
+ case PROP_LAST_MODIFIED:
+ g_value_set_string (value, priv->last_modified);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
+
+static void
+ontology_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerOntologyPriv *priv;
+
+ priv = GET_PRIV (object);
+
+ switch (param_id) {
+ case PROP_URI:
+ tracker_ontology_set_uri (TRACKER_ONTOLOGY (object),
+ g_value_get_string (value));
+ break;
+ case PROP_LAST_MODIFIED:
+ tracker_ontology_set_last_modified (TRACKER_ONTOLOGY (object),
+ g_value_get_string (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ };
+}
+
+TrackerOntology *
+tracker_ontology_new (void)
+{
+ TrackerOntology *ontology;
+
+ ontology = g_object_new (TRACKER_TYPE_ONTOLOGY, NULL);
+
+ return ontology;
+}
+
+const gchar *
+tracker_ontology_get_last_modified (TrackerOntology *ontology)
+{
+ TrackerOntologyPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_ONTOLOGY (ontology), NULL);
+
+ priv = GET_PRIV (ontology);
+
+ return priv->last_modified;
+}
+
+
+void
+tracker_ontology_set_last_modified (TrackerOntology *ontology,
+ const gchar *value)
+{
+ TrackerOntologyPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_ONTOLOGY (ontology));
+
+ priv = GET_PRIV (ontology);
+
+ g_free (priv->last_modified);
+
+ if (value) {
+ priv->last_modified = g_strdup (value);
+ } else {
+ priv->last_modified = NULL;
+ }
+
+ g_object_notify (G_OBJECT (ontology), "last-modified");
+}
+
+
+const gchar *
+tracker_ontology_get_uri (TrackerOntology *ontology)
+{
+ TrackerOntologyPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_ONTOLOGY (ontology), NULL);
+
+ priv = GET_PRIV (ontology);
+
+ return priv->uri;
+}
+
+
+void
+tracker_ontology_set_uri (TrackerOntology *ontology,
+ const gchar *value)
+{
+ TrackerOntologyPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_ONTOLOGY (ontology));
+
+ priv = GET_PRIV (ontology);
+
+ g_free (priv->uri);
+
+ if (value) {
+ priv->uri = g_strdup (value);
+ } else {
+ priv->uri = NULL;
+ }
+
+ g_object_notify (G_OBJECT (ontology), "uri");
+}
diff --git a/src/libtracker-common/tracker-ontology.h b/src/libtracker-common/tracker-ontology.h
new file mode 100644
index 0000000..270b590
--- /dev/null
+++ b/src/libtracker-common/tracker-ontology.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2009, Nokia
+ *
+ * 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: Philip Van Hoof <philip codeminded be>
+ */
+
+#ifndef __LIBTRACKER_COMMON_ONTOLOGY_H__
+#define __LIBTRACKER_COMMON_ONTOLOGY_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-common/tracker-common.h> must be included directly."
+#endif
+
+#define TRACKER_TYPE_ONTOLOGY (tracker_ontology_get_type ())
+#define TRACKER_ONTOLOGY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_ONTOLOGY, TrackerOntology))
+#define TRACKER_ONTOLOGY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), TRACKER_TYPE_ONTOLOGY, TrackerOntologyClass))
+#define TRACKER_IS_ONTOLOGY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_ONTOLOGY))
+#define TRACKER_IS_ONTOLOGY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), TRACKER_TYPE_ONTOLOGY))
+#define TRACKER_ONTOLOGY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_ONTOLOGY, TrackerOntologyClass))
+
+typedef struct _TrackerOntology TrackerOntology;
+typedef struct _TrackerOntologyClass TrackerOntologyClass;
+
+struct _TrackerOntology {
+ GObject parent;
+};
+
+struct _TrackerOntologyClass {
+ GObjectClass parent_class;
+};
+
+GType tracker_ontology_get_type (void) G_GNUC_CONST;
+TrackerOntology *tracker_ontology_new (void);
+const gchar * tracker_ontology_get_last_modified (TrackerOntology *ontology);
+void tracker_ontology_set_last_modified (TrackerOntology *ontology,
+ const gchar *value);
+const gchar * tracker_ontology_get_uri (TrackerOntology *ontology);
+void tracker_ontology_set_uri (TrackerOntology *ontology,
+ const gchar *value);
+
+G_END_DECLS
+
+#endif /* __LIBTRACKER_COMMON_ONTOLOGY_H__ */
+
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index be06cca..933eba5 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -136,10 +136,18 @@ load_ontology_statement (const gchar *ontology_file,
tracker_ontologies_add_namespace (namespace);
g_object_unref (namespace);
} else if (g_strcmp0 (object, TRACKER_PREFIX "Ontology") == 0) {
- g_print ("ONTOLOGY: %s\n", subject);
+ TrackerOntology *ontology;
+
+ if (tracker_ontologies_get_ontology_by_uri (subject) != NULL) {
+ g_critical ("%s: Duplicate definition of ontology %s", ontology_file, subject);
+ return;
+ }
+
+ ontology = tracker_ontology_new ();
+ tracker_ontology_set_uri (ontology, subject);
+ tracker_ontologies_add_ontology (ontology);
+ g_object_unref (ontology);
}
- } else if (g_strcmp0 (predicate, NAO_LAST_MODIFIED) == 0) {
- g_print ("\tNAO LAST MODIFIED: %s\n", object);
} else if (g_strcmp0 (predicate, RDFS_SUB_CLASS_OF) == 0) {
TrackerClass *class, *super_class;
@@ -276,7 +284,18 @@ load_ontology_statement (const gchar *ontology_file,
}
tracker_namespace_set_prefix (namespace, object);
+ } else if (g_strcmp0 (predicate, NAO_LAST_MODIFIED) == 0) {
+ TrackerOntology *ontology;
+
+ ontology = tracker_ontologies_get_ontology_by_uri (subject);
+ if (ontology == NULL) {
+ g_critical ("%s: Unknown ontology %s", ontology_file, subject);
+ return;
+ }
+
+ tracker_ontology_set_last_modified (ontology, object);
}
+
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]