[tracker/wip/carlosg/deserializers: 2/4] libtracker-sparql: Add TrackerDeserializerRdf abstract class
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/deserializers: 2/4] libtracker-sparql: Add TrackerDeserializerRdf abstract class
- Date: Sun, 24 Apr 2022 14:52:31 +0000 (UTC)
commit 4e46a6d9770e9eb1e4c587b68b1190aa925232a7
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Apr 24 15:22:52 2022 +0200
libtracker-sparql: Add TrackerDeserializerRdf abstract class
This will be the base class for cursors and formats holding RDF
data. These are have a fixed and known set of columns for
subject/predicate/object, plus optionally graph, so can provide
some helpers to deal with these.
src/libtracker-sparql/meson.build | 1 +
src/libtracker-sparql/tracker-deserializer-rdf.c | 146 +++++++++++++++++++++++
src/libtracker-sparql/tracker-deserializer-rdf.h | 48 ++++++++
3 files changed, 195 insertions(+)
---
diff --git a/src/libtracker-sparql/meson.build b/src/libtracker-sparql/meson.build
index b06898eae..67951f179 100644
--- a/src/libtracker-sparql/meson.build
+++ b/src/libtracker-sparql/meson.build
@@ -23,6 +23,7 @@ libtracker_sparql_c_sources = files(
'tracker-connection.c',
'tracker-cursor.c',
'tracker-deserializer.c',
+ 'tracker-deserializer-rdf.c',
'tracker-endpoint.c',
'tracker-endpoint-dbus.c',
'tracker-error.c',
diff --git a/src/libtracker-sparql/tracker-deserializer-rdf.c
b/src/libtracker-sparql/tracker-deserializer-rdf.c
new file mode 100644
index 000000000..c8764a088
--- /dev/null
+++ b/src/libtracker-sparql/tracker-deserializer-rdf.c
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2022, Red Hat, Inc
+ *
+ * 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 <carlosg gnome org>
+ */
+
+#include "config.h"
+
+#include "tracker-deserializer-rdf.h"
+
+#include "tracker-private.h"
+
+static gchar *col_names[] = {
+ "subject",
+ "predicate",
+ "object",
+ "graph",
+};
+
+G_STATIC_ASSERT (G_N_ELEMENTS (col_names) == TRACKER_RDF_N_COLS);
+
+enum {
+ PROP_0,
+ PROP_HAS_GRAPH,
+ N_PROPS
+};
+
+static GParamSpec *props[N_PROPS];
+
+typedef struct _TrackerDeserializerRdfPrivate TrackerDeserializerRdfPrivate;
+
+struct _TrackerDeserializerRdfPrivate
+{
+ gboolean has_graph;
+};
+
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (TrackerDeserializerRdf, tracker_deserializer_rdf,
+ TRACKER_TYPE_DESERIALIZER)
+
+static void
+tracker_deserializer_rdf_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerDeserializerRdf *serializer_rdf = TRACKER_DESERIALIZER_RDF (object);
+ TrackerDeserializerRdfPrivate *priv =
+ tracker_deserializer_rdf_get_instance_private (serializer_rdf);
+
+ switch (prop_id) {
+ case PROP_HAS_GRAPH:
+ priv->has_graph = g_value_get_boolean (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+tracker_deserializer_rdf_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerDeserializerRdf *serializer_rdf = TRACKER_DESERIALIZER_RDF (object);
+ TrackerDeserializerRdfPrivate *priv =
+ tracker_deserializer_rdf_get_instance_private (serializer_rdf);
+
+ switch (prop_id) {
+ case PROP_HAS_GRAPH:
+ g_value_set_boolean (value, priv->has_graph);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static const gchar *
+tracker_deserializer_rdf_get_variable_name (TrackerSparqlCursor *cursor,
+ gint column)
+{
+ if (column >= tracker_sparql_cursor_get_n_columns (cursor))
+ return NULL;
+
+ g_assert (column < TRACKER_RDF_N_COLS);
+
+ return col_names[column];
+}
+
+static gint
+tracker_deserializer_rdf_get_n_columns (TrackerSparqlCursor *cursor)
+{
+ TrackerDeserializerRdf *deserializer_rdf =
+ TRACKER_DESERIALIZER_RDF (cursor);
+ TrackerDeserializerRdfPrivate *priv =
+ tracker_deserializer_rdf_get_instance_private (deserializer_rdf);
+
+ return (priv->has_graph) ? TRACKER_RDF_N_COLS : TRACKER_RDF_N_COLS - 1;
+}
+
+static void
+tracker_deserializer_rdf_class_init (TrackerDeserializerRdfClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ TrackerSparqlCursorClass *cursor_class = TRACKER_SPARQL_CURSOR_CLASS (klass);
+
+ object_class->set_property = tracker_deserializer_rdf_set_property;
+ object_class->get_property = tracker_deserializer_rdf_get_property;
+
+ cursor_class->get_variable_name = tracker_deserializer_rdf_get_variable_name;
+ cursor_class->get_n_columns = tracker_deserializer_rdf_get_n_columns;
+
+ props[PROP_HAS_GRAPH] =
+ g_param_spec_boolean ("has-graph",
+ "Has graph",
+ "Has graph",
+ FALSE,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_READABLE |
+ G_PARAM_WRITABLE);
+
+ g_object_class_install_properties (object_class, N_PROPS, props);
+}
+
+static void
+tracker_deserializer_rdf_init (TrackerDeserializerRdf *deserializer_rdf)
+{
+}
diff --git a/src/libtracker-sparql/tracker-deserializer-rdf.h
b/src/libtracker-sparql/tracker-deserializer-rdf.h
new file mode 100644
index 000000000..3b62184d9
--- /dev/null
+++ b/src/libtracker-sparql/tracker-deserializer-rdf.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2022, Red Hat, Inc
+ *
+ * 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 <carlosg gnome org>
+ */
+
+#ifndef TRACKER_DESERIALIZER_RDF_H
+#define TRACKER_DESERIALIZER_RDF_H
+
+#include <libtracker-sparql/tracker-deserializer.h>
+
+#include "tracker-private.h"
+
+typedef enum {
+ TRACKER_RDF_COL_SUBJECT,
+ TRACKER_RDF_COL_PREDICATE,
+ TRACKER_RDF_COL_OBJECT,
+ TRACKER_RDF_COL_GRAPH,
+ TRACKER_RDF_N_COLS
+} TrackerRdfColumn;
+
+#define TRACKER_TYPE_DESERIALIZER_RDF (tracker_deserializer_rdf_get_type())
+
+struct _TrackerDeserializerRdfClass {
+ TrackerDeserializerClass parent_class;
+};
+
+G_DECLARE_DERIVABLE_TYPE (TrackerDeserializerRdf,
+ tracker_deserializer_rdf,
+ TRACKER, DESERIALIZER_RDF,
+ TrackerDeserializer)
+
+#endif /* TRACKER_DESERIALIZER_RDF_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]