[tracker/wip/sam/resource-rebase-3: 7/11] libtracker-sparql: Add TRACKER_TYPE_URI



commit 618576a09f80da6b3411d293952311a839a7a47a
Author: Sam Thursfield <sam afuera me uk>
Date:   Fri Apr 8 17:10:32 2016 +0100

    libtracker-sparql: Add TRACKER_TYPE_URI
    
    This is the same as G_TYPE_STRING, but we need to treat strings and URIs
    differently when generating SPARQL from the TrackerResource class, so we
    need a separate GType to keep track of which is which when given a
    GValue.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=767472

 src/libtracker-sparql/Makefile.am      |    2 +
 src/libtracker-sparql/tracker-sparql.h |    1 +
 src/libtracker-sparql/tracker-uri.c    |   23 +++++++++++++++++
 src/libtracker-sparql/tracker-uri.h    |   42 ++++++++++++++++++++++++++++++++
 4 files changed, 68 insertions(+), 0 deletions(-)
---
diff --git a/src/libtracker-sparql/Makefile.am b/src/libtracker-sparql/Makefile.am
index 48ed4ad..b63e4ef 100644
--- a/src/libtracker-sparql/Makefile.am
+++ b/src/libtracker-sparql/Makefile.am
@@ -24,6 +24,7 @@ libtracker_sparql_la_SOURCES =   \
        tracker-cursor.vala                            \
        tracker-utils.vala                             \
        tracker-uri.c                                  \
+       tracker-uri.h                                  \
        tracker-ontologies.h \
        tracker-version.c \
        tracker-version.h
@@ -50,6 +51,7 @@ libtracker_sparqlinclude_HEADERS =                     \
        $(vala_header)                                 \
        tracker-ontologies.h \
        tracker-sparql.h                               \
+       tracker-uri.h                                  \
        tracker-version.h
 
 tracker-sparql-$(TRACKER_API_VERSION).deps: tracker-sparql.deps
diff --git a/src/libtracker-sparql/tracker-sparql.h b/src/libtracker-sparql/tracker-sparql.h
index 8f042d4..ee7eda7 100644
--- a/src/libtracker-sparql/tracker-sparql.h
+++ b/src/libtracker-sparql/tracker-sparql.h
@@ -23,6 +23,7 @@
 #define __LIBTRACKER_SPARQL_INSIDE__
 
 #include <libtracker-sparql/tracker-version.h>
+#include <libtracker-sparql/tracker-uri.h>
 #include <libtracker-sparql/tracker-ontologies.h>
 #include <libtracker-sparql/tracker-generated.h>
 
diff --git a/src/libtracker-sparql/tracker-uri.c b/src/libtracker-sparql/tracker-uri.c
index 53e6078..5e76354 100644
--- a/src/libtracker-sparql/tracker-uri.c
+++ b/src/libtracker-sparql/tracker-uri.c
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2008-2010, Nokia <ivan frade nokia com>
  * Copyright (C) 2010, Codeminded BVBA <abustany gnome org>
+ * 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
@@ -24,6 +25,28 @@
 
 #include <glib.h>
 
+#include "tracker-uri.h"
+
+/* The TrackerUri GType is useful when encapsulating a URI inside a GValue.
+ * When we generate SPARQL we need to treat URIs differently to normal strings
+ * (one goes in "", one goes in <>) so we can't use regular G_TYPE_STRING for
+ * them.
+ */
+GType
+tracker_uri_get_type (void)
+{
+       static volatile gsize g_define_type_id__volatile = 0;
+       if (g_once_init_enter (&g_define_type_id__volatile)) {
+               GTypeInfo info = { 0, NULL, NULL, NULL, NULL, NULL, 0, 0, NULL, NULL, };
+               GType g_define_type_id = g_type_register_static (G_TYPE_STRING,
+                                                                g_intern_static_string ("TrackerUri"),
+                                                                &info,
+                                                                0);
+               g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
+       }
+       return g_define_type_id__volatile;
+}
+
 gchar *
 tracker_sparql_escape_uri_vprintf (const gchar *format,
                                    va_list      args);
diff --git a/src/libtracker-sparql/tracker-uri.h b/src/libtracker-sparql/tracker-uri.h
new file mode 100644
index 0000000..4ffa1e6
--- /dev/null
+++ b/src/libtracker-sparql/tracker-uri.h
@@ -0,0 +1,42 @@
+/*
+ * 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_URI_H__
+#define __LIBTRACKER_SPARQL_URI_H__
+
+G_BEGIN_DECLS
+
+#include <glib-object.h>
+
+#if !defined (__LIBTRACKER_SPARQL_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-sparql/tracker-sparql.h> must be included directly."
+#endif
+
+GType tracker_uri_get_type (void);
+
+#define TRACKER_TYPE_URI tracker_uri_get_type()
+
+/* The public functions in tracker-uri.c are prototyped in the generated Vala
+ * header tracker-generated-no-checks.h, due to being defined in
+ * tracker-sparql.vapi.
+ */
+
+G_END_DECLS
+
+#endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]