[tracker/wip/carlosg/http-endpoint: 1/10] libtracker-sparql: Add private/abstract TrackerSerializer object
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/http-endpoint: 1/10] libtracker-sparql: Add private/abstract TrackerSerializer object
- Date: Sat, 12 Dec 2020 20:24:28 +0000 (UTC)
commit 5da90a68c16ab4204d11c8eeef55a347c3b14e3d
Author: Carlos Garnacho <carlosg gnome org>
Date: Sat Dec 12 15:49:59 2020 +0100
libtracker-sparql: Add private/abstract TrackerSerializer object
This object is a subclass of GInputStream that takes a SPARQL
cursor on construction. It is meant to handle serialization of
SPARQL results into text formats.
docs/reference/libtracker-sparql/meson.build | 1 +
src/libtracker-sparql/meson.build | 1 +
src/libtracker-sparql/tracker-private.h | 6 ++
src/libtracker-sparql/tracker-serializer.c | 140 +++++++++++++++++++++++++++
src/libtracker-sparql/tracker-serializer.h | 45 +++++++++
5 files changed, 193 insertions(+)
---
diff --git a/docs/reference/libtracker-sparql/meson.build b/docs/reference/libtracker-sparql/meson.build
index 994cb3c31..7b7ce25d5 100644
--- a/docs/reference/libtracker-sparql/meson.build
+++ b/docs/reference/libtracker-sparql/meson.build
@@ -37,6 +37,7 @@ image_files = [
private_headers = [
'tracker-notifier-private.h',
'tracker-private.h',
+ 'tracker-serializer.h',
'direct',
'bus',
'remote',
diff --git a/src/libtracker-sparql/meson.build b/src/libtracker-sparql/meson.build
index 7b7191a56..a9f505065 100644
--- a/src/libtracker-sparql/meson.build
+++ b/src/libtracker-sparql/meson.build
@@ -25,6 +25,7 @@ libtracker_sparql_c_sources = files(
'tracker-notifier.c',
'tracker-resource.c',
'tracker-statement.c',
+ 'tracker-serializer.c',
'tracker-uri.c',
'tracker-utils.c',
'tracker-version.c',
diff --git a/src/libtracker-sparql/tracker-private.h b/src/libtracker-sparql/tracker-private.h
index 6c696d4a7..40d9828ca 100644
--- a/src/libtracker-sparql/tracker-private.h
+++ b/src/libtracker-sparql/tracker-private.h
@@ -250,6 +250,12 @@ struct _TrackerBatchClass {
GError **error);
};
+typedef struct _TrackerSerializerClass TrackerSerializerClass;
+
+struct _TrackerSerializerClass {
+ GInputStreamClass parent_class;
+};
+
void tracker_sparql_cursor_set_connection (TrackerSparqlCursor *cursor,
TrackerSparqlConnection *connection);
GError * _translate_internal_error (GError *error);
diff --git a/src/libtracker-sparql/tracker-serializer.c b/src/libtracker-sparql/tracker-serializer.c
new file mode 100644
index 000000000..f96b439ab
--- /dev/null
+++ b/src/libtracker-sparql/tracker-serializer.c
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2020, 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-serializer.h"
+
+#include "tracker-private.h"
+
+enum {
+ PROP_0,
+ PROP_CURSOR,
+ N_PROPS
+};
+
+static GParamSpec *props[N_PROPS];
+
+typedef struct _TrackerSerializerPrivate TrackerSerializerPrivate;
+
+struct _TrackerSerializerPrivate
+{
+ TrackerSparqlCursor *cursor;
+};
+
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (TrackerSerializer, tracker_serializer,
+ G_TYPE_INPUT_STREAM)
+
+static void
+tracker_serializer_finalize (GObject *object)
+{
+ TrackerSerializer *serializer = TRACKER_SERIALIZER (object);
+ TrackerSerializerPrivate *priv =
+ tracker_serializer_get_instance_private (serializer);
+
+ g_object_unref (priv->cursor);
+
+ G_OBJECT_CLASS (tracker_serializer_parent_class)->finalize (object);
+}
+static void
+tracker_serializer_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerSerializer *serializer = TRACKER_SERIALIZER (object);
+ TrackerSerializerPrivate *priv =
+ tracker_serializer_get_instance_private (serializer);
+
+ switch (prop_id) {
+ case PROP_CURSOR:
+ priv->cursor = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+tracker_serializer_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerSerializer *serializer = TRACKER_SERIALIZER (object);
+ TrackerSerializerPrivate *priv =
+ tracker_serializer_get_instance_private (serializer);
+
+ switch (prop_id) {
+ case PROP_CURSOR:
+ g_value_set_object (value, priv->cursor);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+tracker_serializer_class_init (TrackerSerializerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = tracker_serializer_finalize;
+ object_class->set_property = tracker_serializer_set_property;
+ object_class->get_property = tracker_serializer_get_property;
+
+ props[PROP_CURSOR] =
+ g_param_spec_object ("cursor",
+ "cursor",
+ "cursor",
+ TRACKER_TYPE_SPARQL_CURSOR,
+ 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_serializer_init (TrackerSerializer *serializer)
+{
+}
+
+GInputStream *
+tracker_serializer_new (TrackerSparqlCursor *cursor,
+ TrackerSerializerFormat format)
+{
+ return NULL;
+}
+
+TrackerSparqlCursor *
+tracker_serializer_get_cursor (TrackerSerializer *serializer)
+{
+ TrackerSerializerPrivate *priv =
+ tracker_serializer_get_instance_private (serializer);
+
+ g_return_val_if_fail (TRACKER_IS_SERIALIZER (serializer), NULL);
+
+ return priv->cursor;
+}
diff --git a/src/libtracker-sparql/tracker-serializer.h b/src/libtracker-sparql/tracker-serializer.h
new file mode 100644
index 000000000..f948858bb
--- /dev/null
+++ b/src/libtracker-sparql/tracker-serializer.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2020, 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_SERIALIZER_H
+#define TRACKER_SERIALIZER_H
+
+#include <libtracker-sparql/tracker-sparql.h>
+
+#define TRACKER_TYPE_SERIALIZER (tracker_serializer_get_type())
+
+G_DECLARE_DERIVABLE_TYPE (TrackerSerializer,
+ tracker_serializer,
+ TRACKER, SERIALIZER,
+ GInputStream);
+
+typedef enum
+{
+ TRACKER_SERIALIZER_FORMAT_JSON, /* application/sparql-results+json */
+ TRACKER_SERIALIZER_FORMAT_XML, /* application/sparql-results+xml */
+} TrackerSerializerFormat;
+
+GInputStream * tracker_serializer_new (TrackerSparqlCursor *cursor,
+ TrackerSerializerFormat format);
+
+TrackerSparqlCursor * tracker_serializer_get_cursor (TrackerSerializer *serializer);
+
+#endif /* TRACKER_SERIALIZER_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]