[tracker/wip/sam/resource: 1/13] libtracker-sparql: Add TrackerNamespaceManager
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/sam/resource: 1/13] libtracker-sparql: Add TrackerNamespaceManager
- Date: Fri, 8 Apr 2016 23:41:02 +0000 (UTC)
commit 2b1bdeb2b33c17f9561283c20395b90e7faf3f0b
Author: Sam Thursfield <sam afuera me uk>
Date: Fri Apr 8 17:57:46 2016 +0100
libtracker-sparql: Add TrackerNamespaceManager
This will keep track of a set of namespaces and their prefixes. Then,
when we are serializing a resource, we can use it.
This is separate from the Namespace and Ontologies classes in
libtracker-data. They may be able to make use of it though.
src/libtracker-sparql/Makefile.am | 3 +
src/libtracker-sparql/tracker-namespace-manager.c | 113 +++++++++++++++++++++
src/libtracker-sparql/tracker-namespace-manager.h | 41 ++++++++
3 files changed, 157 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-sparql/Makefile.am b/src/libtracker-sparql/Makefile.am
index 48ed4ad..3f6925b 100644
--- a/src/libtracker-sparql/Makefile.am
+++ b/src/libtracker-sparql/Makefile.am
@@ -22,6 +22,8 @@ libtracker_sparql_la_SOURCES = \
tracker-builder.vala \
tracker-connection.vala \
tracker-cursor.vala \
+ tracker-namespace-manager.c \
+ tracker-namespace-manager.h \
tracker-utils.vala \
tracker-uri.c \
tracker-ontologies.h \
@@ -48,6 +50,7 @@ tracker-sparql-$(TRACKER_API_VERSION).vapi: tracker-sparql.vapi
libtracker_sparqlinclude_HEADERS = \
$(vala_header) \
+ tracker-namespace-manager.h \
tracker-ontologies.h \
tracker-sparql.h \
tracker-version.h
diff --git a/src/libtracker-sparql/tracker-namespace-manager.c
b/src/libtracker-sparql/tracker-namespace-manager.c
new file mode 100644
index 0000000..4755253
--- /dev/null
+++ b/src/libtracker-sparql/tracker-namespace-manager.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2016, Sam Thursfield <sam afuera me uk>
+ *
+ * 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.
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <glib.h>
+
+#include "tracker-namespace-manager.h"
+
+struct _TrackerNamespaceManager {
+ GObject *parent;
+};
+
+typedef struct {
+ char *foo;
+} TrackerNamespaceManagerPrivate;
+
+G_DEFINE_TYPE_WITH_PRIVATE (TrackerNamespaceManager, tracker_namespace_manager, G_TYPE_OBJECT);
+#define GET_PRIVATE(object) (tracker_namespace_manager_get_instance_private (object))
+
+/**
+ * SECTION: tracker-namespace-manager
+ * @short_description: A set of well-known namespaces, and known abbreviations for them
+ * @title: TrackerNamespaceManager
+ * @stability: Stable
+ * @include: tracker-namespace-manager.h
+ *
+ * <para>
+ * #TrackerNamespaceManager keeps track of namespaces. It allows you to assign
+ * short prefixes for them to avoid typing full URLs all the time.
+ *
+ * Usually you'll want to use the default namespace manager, as returned by
+ * tracker_namespace_manager_get_default(). This knows about all the namespaces
+ * built in to Tracker.
+ * </para>
+ */
+
+static void finalize (GObject *object);
+
+static void
+tracker_namespace_manager_class_init (TrackerNamespaceManagerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = finalize;
+}
+
+static void
+tracker_namespace_manager_init (TrackerNamespaceManager *self)
+{
+ TrackerNamespaceManagerPrivate *priv = GET_PRIVATE (self);
+}
+
+static void
+finalize (GObject *object)
+{
+ TrackerNamespaceManagerPrivate *priv;
+
+ priv = GET_PRIVATE (TRACKER_NAMESPACE_MANAGER (object));
+
+ (G_OBJECT_CLASS (tracker_namespace_manager_parent_class)->finalize) (object);
+}
+
+TrackerNamespaceManager *
+tracker_namespace_manager_new ()
+{
+ TrackerNamespaceManager *namespace_manager;
+
+ namespace_manager = g_object_new (TRACKER_TYPE_NAMESPACE_MANAGER, NULL);
+}
+
+TrackerNamespaceManager *
+tracker_namespace_manager_get_default ()
+{
+ static TrackerNamespaceManager * volatile default_namespace_manager__volatile;
+
+ if (g_once_init_enter (&default_namespace_manager__volatile)) {
+ TrackerNamespaceManager *manager = tracker_namespace_manager_new();
+
+ /* FIXME: populate namespaces from tracker-ontology.h */
+
+ g_once_init_leave (&default_namespace_manager__volatile, manager);
+ }
+
+ return default_namespace_manager__volatile;
+}
+
+char *
+tracker_namespace_manager_expand_uri (TrackerNamespaceManager *self,
+ const char *short_uri)
+{
+ /* FIXME: stub */
+ return g_strdup (short_uri);
+}
diff --git a/src/libtracker-sparql/tracker-namespace-manager.h
b/src/libtracker-sparql/tracker-namespace-manager.h
new file mode 100644
index 0000000..8c97a8b
--- /dev/null
+++ b/src/libtracker-sparql/tracker-namespace-manager.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2016, Sam Thursfield <sam afuera me uk>
+ *
+ * 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.
+ */
+
+#ifndef __LIBTRACKER_SPARQL_NAMESPACE_MANAGER_H__
+#define __LIBTRACKER_SPARQL_NAMESPACE_MANAGER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#if !defined (__LIBTRACKER_SPARQL_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-sparql/tracker-sparql.h> must be included directly."
+#endif
+
+#define TRACKER_TYPE_NAMESPACE_MANAGER (tracker_namespace_manager_get_type())
+G_DECLARE_FINAL_TYPE (TrackerNamespaceManager, tracker_namespace_manager, TRACKER, NAMESPACE_MANAGER,
GObject);
+
+TrackerNamespaceManager *tracker_namespace_manager_get_default ();
+
+char *tracker_namespace_manager_expand_uri (TrackerNamespaceManager *self, const char *short_uri);
+
+G_END_DECLS
+
+#endif /* __LIBTRACKER_SPARQL_NAMESPACE_MANAGER_H__ */
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]