summaryrefslogtreecommitdiff
path: root/src/libtracker-sparql
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2019-08-18 18:48:01 +0200
committerCarlos Garnacho <carlosg@gnome.org>2020-02-17 18:57:46 +0100
commit1e4cd3dc83a68cd547e83ed0673367d4e6404e7e (patch)
tree5a6256ba3e2309558698d1d4e92b7fd3d9ab98b3 /src/libtracker-sparql
parent5b0a77537be1ffd7b6485b54767a6e5fd5f17267 (diff)
downloadtracker-1e4cd3dc83a68cd547e83ed0673367d4e6404e7e.tar.gz
libtracker-sparql: Reimplement public API in C
It is risky and clunky to have API/ABI in control of a transpiler like Vala is. Examples are: - Defining the abstract classes in vala necessarily exports these *_construct() functions, which are 100% useless as public API since no subclassing of Tracker objects is whatsoever allowed outside of Tracker. - While on the *_construct() functions topic, adding a constructor like tracker_sparql_connetion_new() somehow made valac stop exporting one for TrackerSparqlConnection. The warnings are somehow eaten when compiling the resulting C code, but hell breaks loose when the C compiler assumes an int return value (because it can't know better) but the constructor has a pointer-sized return value. Since those functions are exported, this change sneakily involves an ABI break too. - Even though we want some properties to be construct-only, vala will automatically export setter functions for those. This adds API like tracker_sparql_statement_set_connection() that can only break things if ever called. - The --abi-stability valac toggle was added too late for Tracker to use it. We could use 3.0 as an excuse to turn it on, but that doesn't magically fix the other points. - Vala doesn't allow us to be explicit wrt the exported functions (eg. through extern). We do resort to a .map file, but that's prone to errors and hairy to maintain. We still use vala at places for internal code, but I can't bring myself to think it's a good idea to keep vala in charge of our public API and ABI.
Diffstat (limited to 'src/libtracker-sparql')
-rw-r--r--src/libtracker-sparql/.gitignore4
-rw-r--r--src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi115
-rw-r--r--src/libtracker-sparql/meson.build68
-rw-r--r--src/libtracker-sparql/tracker-connection.c478
-rw-r--r--src/libtracker-sparql/tracker-connection.h235
-rw-r--r--src/libtracker-sparql/tracker-connection.vala433
-rw-r--r--src/libtracker-sparql/tracker-cursor.c489
-rw-r--r--src/libtracker-sparql/tracker-cursor.h135
-rw-r--r--src/libtracker-sparql/tracker-cursor.vala294
-rw-r--r--src/libtracker-sparql/tracker-endpoint-dbus.c3
-rw-r--r--src/libtracker-sparql/tracker-endpoint.h2
-rw-r--r--src/libtracker-sparql/tracker-notifier.c4
-rw-r--r--src/libtracker-sparql/tracker-private.h (renamed from src/libtracker-sparql/tracker-namespace.vala)19
-rw-r--r--src/libtracker-sparql/tracker-resource.c2
-rwxr-xr-xsrc/libtracker-sparql/tracker-sparql-add-include-guards.sh17
-rw-r--r--src/libtracker-sparql/tracker-sparql.h6
-rw-r--r--src/libtracker-sparql/tracker-statement.c357
-rw-r--r--src/libtracker-sparql/tracker-statement.h103
-rw-r--r--src/libtracker-sparql/tracker-statement.vala133
-rw-r--r--src/libtracker-sparql/tracker-uri.c10
-rw-r--r--src/libtracker-sparql/tracker-utils.c80
-rw-r--r--src/libtracker-sparql/tracker-utils.h33
-rw-r--r--src/libtracker-sparql/tracker-utils.vala115
23 files changed, 2062 insertions, 1073 deletions
diff --git a/src/libtracker-sparql/.gitignore b/src/libtracker-sparql/.gitignore
index e16d34f8d..79eb0f739 100644
--- a/src/libtracker-sparql/.gitignore
+++ b/src/libtracker-sparql/.gitignore
@@ -1,12 +1,8 @@
tracker-namespace.c
-tracker-builder.c
-tracker-connection.c
-tracker-cursor.c
tracker-backend.c
tracker-plugin-loader.c
tracker-query.c
tracker-sparql-*.deps
tracker-sparql*.vapi
tracker-generated*.h
-tracker-utils.c
*.pc
diff --git a/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi b/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi
index 79cdf310d..bebd6f82b 100644
--- a/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi
+++ b/src/libtracker-sparql/libtracker-sparql-intermediate-c.vapi
@@ -18,6 +18,121 @@
*/
namespace Tracker {
+ [CCode (cheader_filename = "libtracker-sparql/tracker-connection.h")]
+ public errordomain Sparql.Error {
+ PARSE,
+ UNKNOWN_CLASS,
+ UNKNOWN_PROPERTY,
+ TYPE,
+ CONSTRAINT,
+ NO_SPACE,
+ INTERNAL,
+ UNSUPPORTED,
+ UNKNOWN_GRAPH
+ }
+
+ [CCode (cheader_filename = "libtracker-sparql/tracker-connection.h")]
+ public enum Sparql.ConnectionFlags {
+ NONE = 0,
+ READONLY = 1 << 0,
+ }
+
+ [CCode (cheader_filename = "libtracker-sparql/tracker-cursor.h")]
+ public enum Sparql.ValueType {
+ UNBOUND,
+ URI,
+ STRING,
+ INTEGER,
+ DOUBLE,
+ DATETIME,
+ BLANK_NODE,
+ BOOLEAN
+ }
+
+ namespace Sparql {
+ [CCode (cheader_filename = "libtracker-sparql/tracker-sparql.h")]
+ public static string escape_string (string literal);
+ [CCode (cheader_filename = "libtracker-sparql/tracker-sparql.h")]
+ public static string escape_uri (string uri);
+ [CCode (cheader_filename = "libtracker-sparql/tracker-sparql.h")]
+ public static string escape_uri_printf (string format, ...);
+ [CCode (cheader_filename = "libtracker-sparql/tracker-sparql.h")]
+ public static string escape_uri_vprintf (string format, va_list args);
+ [CCode (cheader_filename = "libtracker-sparql/tracker-sparql.h")]
+ public static string get_uuid_urn ();
+ }
+
+ [CCode (cheader_filename = "libtracker-sparql/tracker-connection.h")]
+ public abstract class Sparql.Connection : GLib.Object {
+ public extern static new Connection remote_new (string uri_base);
+ public extern static new Connection new (Sparql.ConnectionFlags flags, GLib.File store, GLib.File? ontology, GLib.Cancellable? cancellable = null) throws Sparql.Error, GLib.IOError;
+ public extern async static new Connection new_async (Sparql.ConnectionFlags flags, GLib.File store, GLib.File? ontology, GLib.Cancellable? cancellable = null) throws Sparql.Error, GLib.IOError;
+ public extern static new Connection bus_new (string service_name, string? object_path, GLib.DBusConnection? dbus_connection = null) throws Sparql.Error, GLib.IOError, GLib.DBusError, GLib.Error;
+
+ public abstract Cursor query (string sparql, GLib.Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, GLib.DBusError;
+ public async abstract Cursor query_async (string sparql, GLib.Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, GLib.DBusError;
+
+ public virtual void update (string sparql, int priority = GLib.Priority.DEFAULT, GLib.Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, GLib.DBusError;
+ public async virtual void update_async (string sparql, int priority = GLib.Priority.DEFAULT, GLib.Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, GLib.DBusError;
+ public async virtual bool update_array_async (string[] sparql, int priority = GLib.Priority.DEFAULT, GLib.Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, GLib.DBusError;
+ public virtual GLib.Variant? update_blank (string sparql, int priority = GLib.Priority.DEFAULT, GLib.Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, GLib.DBusError;
+ public async virtual GLib.Variant? update_blank_async (string sparql, int priority = GLib.Priority.DEFAULT, GLib.Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, GLib.DBusError;
+
+ public virtual NamespaceManager? get_namespace_manager ();
+
+ public extern static void set_domain (string? domain);
+ public extern static string? get_domain ();
+
+ public extern static void set_dbus_connection (GLib.DBusConnection dbus_connection);
+ public extern static GLib.DBusConnection? get_dbus_connection ();
+
+ public virtual Statement? query_statement (string sparql, GLib.Cancellable? cancellable = null) throws Sparql.Error;
+
+ public virtual Notifier? create_notifier (NotifierFlags flags);
+ public virtual void close ();
+ }
+
+ [CCode (cheader_filename = "libtracker-sparql/tracker-statement.h")]
+ public abstract class Sparql.Statement : GLib.Object {
+ public string sparql { get; construct set; }
+ public Connection connection { get; construct set; }
+
+ public abstract void bind_int (string name, int64 value);
+ public abstract void bind_boolean (string name, bool value);
+ public abstract void bind_string (string name, string value);
+ public abstract void bind_double (string name, double value);
+
+ public abstract Cursor execute (GLib.Cancellable? cancellable) throws Sparql.Error, GLib.Error, GLib.IOError, GLib.DBusError;
+ public async abstract Cursor execute_async (GLib.Cancellable? cancellable) throws Sparql.Error, GLib.Error, GLib.IOError, GLib.DBusError;
+ }
+
+ [CCode (cheader_filename = "libtracker-sparql/tracker-cursor.h")]
+ public abstract class Sparql.Cursor : GLib.Object {
+ public Connection connection {
+ get;
+ set;
+ }
+
+ public abstract int n_columns {
+ get;
+ }
+
+ public abstract Sparql.ValueType get_value_type (int column);
+
+ public abstract unowned string? get_variable_name (int column);
+ public abstract unowned string? get_string (int column, out long length = null);
+
+ public abstract bool next (GLib.Cancellable? cancellable = null) throws GLib.Error;
+ public async abstract bool next_async (GLib.Cancellable? cancellable = null) throws GLib.Error;
+ public abstract void rewind ();
+ public virtual void close ();
+
+ public virtual int64 get_integer (int column);
+ public virtual double get_double (int column);
+ public virtual bool get_boolean (int column);
+ public virtual bool is_bound (int column);
+ }
+
[CCode (cheader_filename = "libtracker-sparql/tracker-namespace-manager.h")]
public class NamespaceManager : GLib.Object {
public NamespaceManager ();
diff --git a/src/libtracker-sparql/meson.build b/src/libtracker-sparql/meson.build
index 51d89d196..3fb684f2f 100644
--- a/src/libtracker-sparql/meson.build
+++ b/src/libtracker-sparql/meson.build
@@ -1,87 +1,51 @@
-enums_c = gnome.mkenums('tracker-sparql-enum-types',
- sources: 'tracker-notifier.h',
+enum_types = gnome.mkenums('tracker-sparql-enum-types',
+ sources: ['tracker-notifier.h', 'tracker-connection.h'],
c_template: 'tracker-sparql-enum-types.c.template',
-)
-enums_h = gnome.mkenums('tracker-sparql-enum-types',
- sources: 'tracker-notifier.h',
h_template: 'tracker-sparql-enum-types.h.template',
+ install_dir: join_paths(get_option('prefix'), get_option('includedir'), 'tracker-@0@'.format(tracker_api_version), 'libtracker-sparql'),
+ install_header: true,
)
-# First build the Vala parts ...
libtracker_sparql_c_vapi = files('libtracker-sparql-intermediate-c.vapi')
libtracker_sparql_c_vapi_dep = meson.get_compiler('vala').find_library('libtracker-sparql-intermediate-c', dirs: meson.current_source_dir())
-libtracker_sparql_intermediate_vala = static_library('tracker-sparql-intermediate-vala',
- 'tracker-namespace.vala',
- 'tracker-connection.vala',
- 'tracker-cursor.vala',
- 'tracker-statement.vala',
- 'tracker-utils.vala',
- vala_header: 'tracker-generated-no-checks.h',
- c_args: tracker_c_args,
- vala_gir: 'Tracker_Vala-' + tracker_api_version + '.gir',
- vala_args: [
- '--debug',
- '--includedir', 'libtracker-sparql',
- '--pkg', 'gio-2.0', '--pkg', 'posix',
- # FIXME: Meson has code to add --target-glib automatically, but it
- # doesn't seem to work here.
- '--target-glib', glib_required,
- libtracker_sparql_c_vapi
- ],
- dependencies: [tracker_common_dep],
- include_directories: [commoninc, configinc, srcinc],
-)
-
-# We must postprocess the generated Vala header to have only-include-once guards
-tracker_sparql_generated_header = custom_target('tracker-sparql-generated-header',
- # FIXME: can't list tracker-generated-no-checks as an input, even though it
- # is, because you'll see this:
- #
- # ninja: error:
- # '../src/libtracker-sparql/tracker-generated-no-checks.h', needed by
- # 'src/libtracker-sparql/tracker-generated.h', missing and no known
- # rule to make it
- #
- output: 'tracker-generated.h',
- command: [join_paths(meson.current_source_dir(), 'tracker-sparql-add-include-guards.sh'), join_paths(meson.current_build_dir(), 'tracker-generated-no-checks.h'), '@OUTPUT@'],
- depends: libtracker_sparql_intermediate_vala,
- install: true,
- install_dir: join_paths(get_option('prefix'), get_option('includedir'), 'tracker-@0@'.format(tracker_api_version), 'libtracker-sparql'))
-
-# Now build the C parts ...
-
libtracker_sparql_c_sources = files(
+ 'tracker-connection.c',
+ 'tracker-cursor.c',
'tracker-endpoint.c',
'tracker-endpoint-dbus.c',
'tracker-namespace-manager.c',
'tracker-notifier.c',
'tracker-resource.c',
+ 'tracker-statement.c',
'tracker-uri.c',
+ 'tracker-utils.c',
'tracker-version.c',
)
libtracker_sparql_c_public_headers = files(
+ 'tracker-connection.h',
+ 'tracker-cursor.h',
'tracker-endpoint.h',
'tracker-endpoint-dbus.h',
'tracker-namespace-manager.h',
'tracker-notifier.h',
'tracker-resource.h',
+ 'tracker-statement.h',
+ 'tracker-utils.h',
'tracker-version.h',
)
-libtracker_sparql_intermediate_c = static_library('tracker-sparql-intermediate-c',
- enums_c, enums_h, tracker_sparql_generated_header[0],
+libtracker_sparql_intermediate = static_library('tracker-sparql-intermediate',
+ enum_types,
libtracker_sparql_c_sources,
dependencies: [tracker_common_dep, json_glib],
- link_with: libtracker_sparql_intermediate_vala,
)
sparqlinc = [include_directories('.'), meson.current_build_dir()]
tracker_sparql_intermediate_dep = declare_dependency(
- link_with: [libtracker_sparql_intermediate_c, libtracker_sparql_intermediate_vala],
- sources: tracker_sparql_generated_header,
+ link_with: [libtracker_sparql_intermediate],
include_directories: [srcinc, include_directories('.')],
dependencies: [ libtracker_sparql_c_vapi_dep ],
)
@@ -99,9 +63,7 @@ tracker_sparql_vapi = custom_target('tracker-sparql-' + tracker_api_version + '.
command: [
'sed', '-e', 's#libtracker-sparql/.*[.]h#libtracker-sparql/tracker-sparql.h#',
libtracker_sparql_c_vapi,
- join_paths(meson.current_build_dir(), 'tracker-sparql-intermediate-vala.vapi')
],
- depends: libtracker_sparql_intermediate_vala,
capture: true,
install: true,
install_dir: vapi_dir)
diff --git a/src/libtracker-sparql/tracker-connection.c b/src/libtracker-sparql/tracker-connection.c
new file mode 100644
index 000000000..be578f4de
--- /dev/null
+++ b/src/libtracker-sparql/tracker-connection.c
@@ -0,0 +1,478 @@
+/*
+ * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
+ *
+ * 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 "tracker-connection.h"
+
+G_DEFINE_ABSTRACT_TYPE (TrackerSparqlConnection, tracker_sparql_connection,
+ G_TYPE_OBJECT)
+
+G_DEFINE_QUARK (tracker-sparql-error-quark, tracker_sparql_error)
+
+static void
+tracker_sparql_connection_init (TrackerSparqlConnection *connection)
+{
+}
+
+static void
+tracker_sparql_connection_class_init (TrackerSparqlConnectionClass *klass)
+{
+}
+
+/**
+ * tracker_sparql_connection_query:
+ * @connection: a #TrackerSparqlConnection
+ * @sparql: string containing the SPARQL query
+ * @cancellable: a #GCancellable used to cancel the operation
+ * @error: #GError for error reporting.
+ *
+ * Executes a SPARQL query on. The API call is completely synchronous, so
+ * it may block.
+ *
+ * The @sparql query should be built with #TrackerResource, or
+ * its parts correctly escaped using tracker_sparql_escape_string(),
+ * otherwise SPARQL injection is possible.
+ *
+ * Returns: (transfer full): a #TrackerSparqlCursor if results were found.
+ * On error, #NULL is returned and the @error is set accordingly.
+ * Call g_object_unref() on the returned cursor when no longer needed.
+ */
+TrackerSparqlCursor *
+tracker_sparql_connection_query (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection), NULL);
+ g_return_val_if_fail (sparql != NULL, NULL);
+ g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (!error || !*error, NULL);
+
+ return TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->query (connection,
+ sparql,
+ cancellable,
+ error);
+}
+
+/**
+ * tracker_sparql_connection_query_async:
+ * @connection: a #TrackerSparqlConnection
+ * @sparql: string containing the SPARQL query
+ * @cancellable: a #GCancellable used to cancel the operation
+ * @callback: user-defined #GAsyncReadyCallback to be called when
+ * asynchronous operation is finished.
+ * @user_data: user-defined data to be passed to @callback
+ *
+ * Executes asynchronously a SPARQL query.
+ */
+void
+tracker_sparql_connection_query_async (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection));
+ g_return_if_fail (sparql != NULL);
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->query_async (connection,
+ sparql,
+ cancellable,
+ callback,
+ user_data);
+}
+
+/**
+ * tracker_sparql_connection_query_finish:
+ * @connection: a #TrackerSparqlConnection
+ * @res: a #GAsyncResult with the result of the operation
+ * @error: #GError for error reporting.
+ *
+ * Finishes the asynchronous SPARQL query operation.
+ *
+ * Returns: (transfer full): a #TrackerSparqlCursor if results were found.
+ * On error, #NULL is returned and the @error is set accordingly.
+ * Call g_object_unref() on the returned cursor when no longer needed.
+ */
+TrackerSparqlCursor *
+tracker_sparql_connection_query_finish (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection), NULL);
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
+ g_return_val_if_fail (!error || !*error, NULL);
+
+ return TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->query_finish (connection,
+ res,
+ error);
+}
+
+/**
+ * tracker_sparql_connection_update:
+ * @connection: a #TrackerSparqlConnection
+ * @sparql: string containing the SPARQL update query
+ * @priority: the priority for the operation
+ * @cancellable: a #GCancellable used to cancel the operation
+ * @error: #GError for error reporting.
+ *
+ * Executes a SPARQL update. The API call is completely
+ * synchronous, so it may block.
+ *
+ * The @sparql query should be built with #TrackerResource, or
+ * its parts correctly escaped using tracker_sparql_escape_string(),
+ * otherwise SPARQL injection is possible.
+ */
+void
+tracker_sparql_connection_update (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ gint priority,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection));
+ g_return_if_fail (sparql != NULL);
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+ g_return_if_fail (!error || !*error);
+
+ return TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->update (connection,
+ sparql,
+ priority,
+ cancellable,
+ error);
+}
+
+/**
+ * tracker_sparql_connection_update_async:
+ * @connection: a #TrackerSparqlConnection
+ * @sparql: string containing the SPARQL update query
+ * @priority: the priority for the asynchronous operation
+ * @cancellable: a #GCancellable used to cancel the operation
+ * @callback: user-defined #GAsyncReadyCallback to be called when
+ * asynchronous operation is finished.
+ * @user_data: user-defined data to be passed to @callback
+ *
+ * Executes asynchronously a SPARQL update.
+ */
+void
+tracker_sparql_connection_update_async (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ gint priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection));
+ g_return_if_fail (sparql != NULL);
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->update_async (connection,
+ sparql,
+ priority,
+ cancellable,
+ callback,
+ user_data);
+}
+
+/**
+ * tracker_sparql_connection_update_finish:
+ * @connection: a #TrackerSparqlConnection
+ * @res: a #GAsyncResult with the result of the operation
+ * @error: #GError for error reporting.
+ *
+ * Finishes the asynchronous SPARQL update operation.
+ */
+void
+tracker_sparql_connection_update_finish (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection));
+ g_return_if_fail (G_IS_ASYNC_RESULT (res));
+ g_return_if_fail (!error || !*error);
+
+ return TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->update_finish (connection,
+ res,
+ error);
+}
+
+/**
+ * tracker_sparql_connection_update_array_async:
+ * @connection: a #TrackerSparqlConnection
+ * @sparql: an array of strings containing the SPARQL update queries
+ * @sparql_length: the amount of strings you pass as @sparql
+ * @priority: the priority for the asynchronous operation
+ * @cancellable: a #GCancellable used to cancel the operation
+ * @callback: user-defined #GAsyncReadyCallback to be called when
+ * asynchronous operation is finished.
+ * @user_data: user-defined data to be passed to @callback
+ *
+ * Executes asynchronously an array of SPARQL updates. Each update in the
+ * array is its own transaction. This means that update n+1 is not halted
+ * due to an error in update n.
+ */
+void
+tracker_sparql_connection_update_array_async (TrackerSparqlConnection *connection,
+ gchar **sparql,
+ gint sparql_length,
+ gint priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection));
+ g_return_if_fail (sparql != NULL);
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->update_array_async (connection,
+ sparql,
+ sparql_length,
+ priority,
+ cancellable,
+ callback,
+ user_data);
+}
+
+/**
+ * tracker_sparql_connection_update_array_finish:
+ * @connection: a #TrackerSparqlConnection
+ * @res: a #GAsyncResult with the result of the operation
+ * @error: #GError for error reporting.
+ *
+ * Finishes the asynchronous SPARQL update_array operation.
+ *
+ * <example>
+ * <programlisting>
+ * static void
+ * async_update_array_callback (GObject *source_object,
+ * GAsyncResult *result,
+ * gpointer user_data)
+ * {
+ * GError *error = NULL;
+ * GPtrArray *errors;
+ * guint i;
+ *
+ * errors = tracker_sparql_connection_update_array_finish (connection, result, &error);
+ * g_assert_no_error (error);
+ *
+ * for (i = 0; i < errors->len; i++) {
+ * const GError *e = g_ptr_array_index (errors, i);
+ *
+ * ...
+ * }
+ *
+ * g_ptr_array_unref (errors);
+ * }
+ * </programlisting>
+ * </example>
+ *
+ * Returns: a #GPtrArray of size @sparql_length with elements that are
+ * either NULL or a GError instance. The returned array should be freed with
+ * g_ptr_array_unref when no longer used, not with g_ptr_array_free. When
+ * you use errors of the array, you must g_error_copy them. Errors inside of
+ * the array must be considered as const data and not freed. The index of
+ * the error corresponds to the index of the update query in the array that
+ * you passed to tracker_sparql_connection_update_array_async.
+ */
+gboolean
+tracker_sparql_connection_update_array_finish (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection), FALSE);
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
+ g_return_val_if_fail (!error || !*error, FALSE);
+
+ return TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->update_array_finish (connection,
+ res,
+ error);
+
+}
+
+/**
+ * tracker_sparql_connection_update_blank:
+ * @connection: a #TrackerSparqlConnection
+ * @sparql: string containing the SPARQL update query
+ * @priority: the priority for the operation
+ * @cancellable: a #GCancellable used to cancel the operation
+ * @error: #GError for error reporting.
+ *
+ * Executes a SPARQL update and returns the URNs of the generated nodes,
+ * if any. The API call is completely synchronous, so it may block.
+ *
+ * The @sparql query should be built with #TrackerResource, or
+ * its parts correctly escaped using tracker_sparql_escape_string(),
+ * otherwise SPARQL injection is possible.
+ *
+ * Returns: a #GVariant with the generated URNs, which should be freed with
+ * g_variant_unref() when no longer used.
+ */
+GVariant *
+tracker_sparql_connection_update_blank (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ gint priority,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection), NULL);
+ g_return_val_if_fail (sparql != NULL, NULL);
+ g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (!error || !*error, NULL);
+
+ return TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->update_blank (connection,
+ sparql,
+ priority,
+ cancellable,
+ error);
+}
+
+/**
+ * tracker_sparql_connection_update_blank_async:
+ * @connection: a #TrackerSparqlConnection
+ * @sparql: string containing the SPARQL update query
+ * @priority: the priority for the asynchronous operation
+ * @cancellable: a #GCancellable used to cancel the operation
+ * @callback: user-defined #GAsyncReadyCallback to be called when
+ * asynchronous operation is finished.
+ * @user_data: user-defined data to be passed to @callback
+ *
+ * Executes asynchronously a SPARQL update.
+ */
+void
+tracker_sparql_connection_update_blank_async (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ gint priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection));
+ g_return_if_fail (sparql != NULL);
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->update_blank_async (connection,
+ sparql,
+ priority,
+ cancellable,
+ callback,
+ user_data);
+}
+
+/**
+ * tracker_sparql_connection_update_blank_finish:
+ * @connection: a #TrackerSparqlConnection
+ * @res: a #GAsyncResult with the result of the operation
+ * @error: #GError for error reporting.
+ *
+ * Finishes the asynchronous SPARQL update operation, and returns
+ * the URNs of the generated nodes, if any.
+ *
+ * Returns: a #GVariant with the generated URNs, which should be freed with
+ * g_variant_unref() when no longer used.
+ */
+GVariant *
+tracker_sparql_connection_update_blank_finish (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection), NULL);
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
+ g_return_val_if_fail (!error || !*error, NULL);
+
+ return TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->update_blank_finish (connection,
+ res,
+ error);
+}
+
+/**
+ * tracker_sparql_connection_get_namespace_manager:
+ * @connection: a #TrackerSparqlConnection
+ *
+ * Retrieves a #TrackerNamespaceManager that contains all
+ * prefixes in the ontology of @connection.
+ *
+ * Returns: (transfer none): a #TrackerNamespaceManager for this
+ * connection. This object is owned by @connection and must not be freed.
+ */
+TrackerNamespaceManager *
+tracker_sparql_connection_get_namespace_manager (TrackerSparqlConnection *connection)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection), NULL);
+
+ return TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->get_namespace_manager (connection);
+}
+
+/**
+ * tracker_sparql_connection_query_statement:
+ * @connection: a #TrackerSparqlConnection
+ * @sparql: the SPARQL query
+ * @cancellable: a #GCancellable used to cancel the operation, or %NULL
+ * @error: a #TrackerSparqlError or %NULL if no error occured
+ *
+ * Prepares the given @sparql as a #TrackerSparqlStatement.
+ *
+ * Returns: (transfer full) (nullable): a prepared statement
+ */
+TrackerSparqlStatement *
+tracker_sparql_connection_query_statement (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection), NULL);
+ g_return_val_if_fail (sparql != NULL, NULL);
+ g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (!error || !*error, NULL);
+
+ return TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->query_statement (connection,
+ sparql,
+ cancellable,
+ error);
+}
+
+TrackerNotifier *
+tracker_sparql_connection_create_notifier (TrackerSparqlConnection *connection,
+ TrackerNotifierFlags flags)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection), NULL);
+
+ return TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->create_notifier (connection, flags);
+}
+
+/**
+ * tracker_sparql_connection_close:
+ * @self: a #TrackerSparqlConnection
+ *
+ * Closes a SPARQL connection. No other API calls than g_object_unref()
+ * should happen after this call.
+ *
+ * This call is blocking. All pending updates will be flushed, and the
+ * store databases will be closed orderly. All ongoing SELECT queries
+ * will be cancelled.
+ *
+ * Since: 3.0
+ */
+void
+tracker_sparql_connection_close (TrackerSparqlConnection *connection)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection));
+
+ TRACKER_SPARQL_CONNECTION_GET_CLASS (connection)->close (connection);
+}
diff --git a/src/libtracker-sparql/tracker-connection.h b/src/libtracker-sparql/tracker-connection.h
new file mode 100644
index 000000000..6540d9c57
--- /dev/null
+++ b/src/libtracker-sparql/tracker-connection.h
@@ -0,0 +1,235 @@
+/*
+ * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
+ *
+ * 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 __TRACKER_SPARQL_CONNECTION_H__
+#define __TRACKER_SPARQL_CONNECTION_H__
+
+#if !defined (__LIBTRACKER_SPARQL_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-sparql/tracker-sparql.h> must be included directly."
+#endif
+
+#include "tracker-notifier.h"
+
+#include <gio/gio.h>
+
+typedef enum {
+ TRACKER_SPARQL_CONNECTION_FLAGS_NONE = 0,
+ TRACKER_SPARQL_CONNECTION_FLAGS_READONLY = 1 << 0,
+} TrackerSparqlConnectionFlags;
+
+/**
+ * TrackerSparqlConnection:
+ *
+ * The <structname>TrackerSparqlConnection</structname> object represents a
+ * SPARQL connection.
+ */
+#define TRACKER_TYPE_SPARQL_CONNECTION tracker_sparql_connection_get_type ()
+#define TRACKER_SPARQL_TYPE_CONNECTION TRACKER_TYPE_SPARQL_CONNECTION
+G_DECLARE_DERIVABLE_TYPE (TrackerSparqlConnection,
+ tracker_sparql_connection,
+ TRACKER, SPARQL_CONNECTION,
+ GObject)
+
+#include "tracker-cursor.h"
+#include "tracker-statement.h"
+#include "tracker-namespace-manager.h"
+
+/**
+ * TrackerSparqlError:
+ * @TRACKER_SPARQL_ERROR_PARSE: Error parsing the SPARQL string.
+ * @TRACKER_SPARQL_ERROR_UNKNOWN_CLASS: Unknown class.
+ * @TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY: Unknown property.
+ * @TRACKER_SPARQL_ERROR_TYPE: Wrong type.
+ * @TRACKER_SPARQL_ERROR_CONSTRAINT: Subject is not in the domain of a property or
+ * trying to set multiple values for a single valued
+ * property.
+ * @TRACKER_SPARQL_ERROR_NO_SPACE: There was no disk space available to perform the request.
+ * @TRACKER_SPARQL_ERROR_INTERNAL: Internal error.
+ * @TRACKER_SPARQL_ERROR_UNSUPPORTED: Unsupported feature or method.
+ * @TRACKER_SPARQL_ERROR_UNKNOWN_GRAPH: Unknown graph.
+ *
+ * Error domain for Tracker Sparql. Errors in this domain will be from the
+ * #TrackerSparqlError enumeration. See #GError for more information on error
+ * domains.
+ */
+typedef enum {
+ TRACKER_SPARQL_ERROR_PARSE,
+ TRACKER_SPARQL_ERROR_UNKNOWN_CLASS,
+ TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
+ TRACKER_SPARQL_ERROR_TYPE,
+ TRACKER_SPARQL_ERROR_CONSTRAINT,
+ TRACKER_SPARQL_ERROR_NO_SPACE,
+ TRACKER_SPARQL_ERROR_INTERNAL,
+ TRACKER_SPARQL_ERROR_UNSUPPORTED,
+ TRACKER_SPARQL_ERROR_UNKNOWN_GRAPH
+} TrackerSparqlError;
+
+#define TRACKER_SPARQL_ERROR tracker_sparql_error_quark ()
+
+struct _TrackerSparqlConnectionClass
+{
+ GObjectClass parent_class;
+
+ TrackerSparqlCursor * (* query) (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ GCancellable *cancellable,
+ GError **error);
+ void (* query_async) (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ TrackerSparqlCursor * (* query_finish) (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error);
+ void (* update) (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ gint priority,
+ GCancellable *cancellable,
+ GError **error);
+ void (* update_async) (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ gint priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ void (* update_finish) (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error);
+ void (* update_array_async) (TrackerSparqlConnection *connection,
+ gchar **sparql,
+ gint sparql_length,
+ gint priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ gboolean (* update_array_finish) (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error);
+ GVariant* (* update_blank) (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ gint priority,
+ GCancellable *cancellable,
+ GError **error);
+ void (* update_blank_async) (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ gint priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ GVariant* (* update_blank_finish) (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error);
+ TrackerNamespaceManager * (* get_namespace_manager) (TrackerSparqlConnection *connection);
+ TrackerSparqlStatement * (* query_statement) (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ GCancellable *cancellable,
+ GError **error);
+ TrackerNotifier * (* create_notifier) (TrackerSparqlConnection *connection,
+ TrackerNotifierFlags flags);
+
+ void (* close) (TrackerSparqlConnection *connection);
+};
+
+GQuark tracker_sparql_error_quark (void);
+
+TrackerSparqlConnection * tracker_sparql_connection_new (TrackerSparqlConnectionFlags flags,
+ GFile *store,
+ GFile *ontology,
+ GCancellable *cancellable,
+ GError **error);
+void tracker_sparql_connection_new_async (TrackerSparqlConnectionFlags flags,
+ GFile *store,
+ GFile *ontology,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+TrackerSparqlConnection * tracker_sparql_connection_new_finish (GAsyncResult *result,
+ GError **error);
+
+TrackerSparqlConnection * tracker_sparql_connection_bus_new (const gchar *service_name,
+ const gchar *object_path,
+ GDBusConnection *dbus_connection,
+ GError **error);
+TrackerSparqlConnection * tracker_sparql_connection_remote_new (const gchar *uri_base);
+
+TrackerSparqlCursor * tracker_sparql_connection_query (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ GCancellable *cancellable,
+ GError **error);
+
+void tracker_sparql_connection_query_async (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+TrackerSparqlCursor * tracker_sparql_connection_query_finish (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error);
+
+void tracker_sparql_connection_update (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ gint priority,
+ GCancellable *cancellable,
+ GError **error);
+void tracker_sparql_connection_update_async (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ gint priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+void tracker_sparql_connection_update_finish (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error);
+void tracker_sparql_connection_update_array_async (TrackerSparqlConnection *connection,
+ gchar **sparql,
+ gint sparql_length,
+ gint priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean tracker_sparql_connection_update_array_finish (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error);
+GVariant * tracker_sparql_connection_update_blank (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ gint priority,
+ GCancellable *cancellable,
+ GError **error);
+void tracker_sparql_connection_update_blank_async (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ gint priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+GVariant * tracker_sparql_connection_update_blank_finish (TrackerSparqlConnection *connection,
+ GAsyncResult *res,
+ GError **error);
+
+TrackerNamespaceManager * tracker_sparql_connection_get_namespace_manager (TrackerSparqlConnection *connection);
+
+TrackerSparqlStatement * tracker_sparql_connection_query_statement (TrackerSparqlConnection *connection,
+ const gchar *sparql,
+ GCancellable *cancellable,
+ GError **error);
+TrackerNotifier * tracker_sparql_connection_create_notifier (TrackerSparqlConnection *connection,
+ TrackerNotifierFlags flags);
+
+void tracker_sparql_connection_close (TrackerSparqlConnection *connection);
+
+#endif /* __TRACKER_SPARQL_CONNECTION_H__ */
diff --git a/src/libtracker-sparql/tracker-connection.vala b/src/libtracker-sparql/tracker-connection.vala
deleted file mode 100644
index e55506b28..000000000
--- a/src/libtracker-sparql/tracker-connection.vala
+++ /dev/null
@@ -1,433 +0,0 @@
-/*
- * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
- *
- * 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.
- */
-
-/**
- * SECTION: tracker-sparql-connection
- * @short_description: Connecting to the Store
- * @title: TrackerSparqlConnection
- * @stability: Stable
- * @include: tracker-sparql.h
- *
- * <para>
- * #TrackerSparqlConnection is an object which sets up connections to the
- * Tracker Store.
- * </para>
- */
-
-/**
- * TrackerSparqlError:
- * @TRACKER_SPARQL_ERROR_PARSE: Error parsing the SPARQL string.
- * @TRACKER_SPARQL_UNKNOWN_CLASS: Unknown class.
- * @TRACKER_SPARQL_UNKNOWN_PROPERTY: Unknown property.
- * @TRACKER_SPARQL_TYPE: Wrong type.
- * @TRACKER_SPARQL_CONSTRAINT: Subject is not in the domain of a property or
- * trying to set multiple values for a single valued
- * property.
- * @TRACKER_SPARQL_NO_SPACE: There was no disk space available to perform the request.
- * @TRACKER_SPARQL_INTERNAL: Internal error.
- * @TRACKER_SPARQL_UNSUPPORTED: Unsupported feature or method.
- * @TRACKER_SPARQL_UNKNOWN_GRAPH: Unknown graph.
- *
- * Error domain for Tracker Sparql. Errors in this domain will be from the
- * #TrackerSparqlError enumeration. See #GError for more information on error
- * domains.
- *
- * Since: 0.10
- */
-[DBus (name = "org.freedesktop.Tracker1.SparqlError")]
-public errordomain Tracker.Sparql.Error {
- PARSE,
- UNKNOWN_CLASS,
- UNKNOWN_PROPERTY,
- TYPE,
- CONSTRAINT,
- NO_SPACE,
- INTERNAL,
- UNSUPPORTED,
- UNKNOWN_GRAPH
-}
-
-public enum Tracker.Sparql.ConnectionFlags {
- NONE = 0,
- READONLY = 1 << 0,
-}
-
-/**
- * TrackerSparqlConnection:
- *
- * The <structname>TrackerSparqlConnection</structname> object represents a
- * connection with the Tracker store or databases depending on direct or
- * non-direct requests.
- */
-public abstract class Tracker.Sparql.Connection : Object {
- /**
- * tracker_sparql_connection_remote_new:
- * @uri_base: Base URI of the remote connection
- *
- * Returns: a new remote #TrackerSparqlConnection. Call g_object_unref() on the
- * object when no longer used.
- *
- * Since: 1.12
- */
- public extern static new Connection remote_new (string uri_base);
-
- /**
- * tracker_sparql_connection_new:
- * @flags: Flags to define connection behavior
- * @store: Location for the database
- * @ontology: Location of the ontology used for this connection, or %NULL
- * @cancellable: A #GCancellable
- * @error: The error which occurred or %NULL
- *
- * Returns: a new #TrackerSparqlConnection using the specified
- * @cache location, and the ontology specified in the @ontology
- * directory. Call g_object_unref() on the object when no longer used.
- *
- * This database connection is considered entirely private to the calling
- * process, if multiple processes use the same cache location,
- * the results are unpredictable.
- *
- * The caller is entirely free to define an ontology or reuse Nepomuk for
- * its purposes. For the former see the "Defining ontologies" section in
- * this library documentation. For the latter pass a %NULL @ontology.
- *
- * If the connection is readonly the @ontology argument will be ignored,
- * and the ontology reconstructed from the database itself.
- *
- * The @ontology argument may be a resource:/// URI, a directory location
- * must be provided, all children .ontology and .description files will
- * be read.
- *
- * The @store argument expects a directory, and it is
- * assumed to be entirely private to Tracker.
- *
- * Since: 3.0
- */
- public extern static new Connection new (Tracker.Sparql.ConnectionFlags flags, File store, File? ontology, Cancellable? cancellable = null) throws Sparql.Error, IOError;
-
- /**
- * tracker_sparql_connection_new_async:
- * @flags: Flags to define connection behavior
- * @store: Location for the database
- * @ontology: Location of the ontology used for this connection, or %NULL
- * @cancellable: A #GCancellable
- * @_callback_: user-defined #GAsyncReadyCallback to be called when
- * asynchronous operation is finished.
- * @_user_data_: user-defined data to be passed to @_callback_
- *
- * Returns: a new #TrackerSparqlConnection using the specified
- * @cache location, and the ontology specified in the @ontology
- * directory. Call g_object_unref() on the object when no longer used.
- *
- * See tracker_sparql_connection_new() for more details.
- *
- * Since: 3.0
- */
-
- /**
- * tracker_sparql_connection_new_finish:
- * @_res_: a #GAsyncResult with the result of the operation
- * @error: #GError for error reporting.
- *
- * Finishes the asynchronous local database creation/loading.
- *
- * Returns: The #TrackerSparqlConnection for the local endpoint.
- * On error, #NULL is returned and the @error is set accordingly.
- * Call g_object_unref() on the returned connection when no longer needed.
- *
- * Since: 3.0
- */
- public extern async static new Connection new_async (Tracker.Sparql.ConnectionFlags flags, File store, File? ontology, Cancellable? cancellable = null) throws Sparql.Error, IOError;
-
- public extern static new Connection bus_new (string service_name, string? object_path, DBusConnection? dbus_connection = null) throws Sparql.Error, IOError, DBusError, GLib.Error;
-
- /**
- * tracker_sparql_connection_query:
- * @self: a #TrackerSparqlConnection
- * @sparql: string containing the SPARQL query
- * @cancellable: a #GCancellable used to cancel the operation
- * @error: #GError for error reporting.
- *
- * Executes a SPARQL query on. The API call is completely synchronous, so
- * it may block.
- *
- * The @sparql query should be built with #TrackerResource, or
- * its parts correctly escaped using tracker_sparql_escape_string(),
- * otherwise SPARQL injection is possible.
- *
- * Returns: a #TrackerSparqlCursor if results were found, #NULL otherwise.
- * On error, #NULL is returned and the @error is set accordingly.
- * Call g_object_unref() on the returned cursor when no longer needed.
- *
- * Since: 0.10
- */
- public abstract Cursor query (string sparql, Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, DBusError;
-
- /**
- * tracker_sparql_connection_query_finish:
- * @self: a #TrackerSparqlConnection
- * @_res_: a #GAsyncResult with the result of the operation
- * @error: #GError for error reporting.
- *
- * Finishes the asynchronous SPARQL query operation.
- *
- * Returns: a #TrackerSparqlCursor if results were found, #NULL otherwise.
- * On error, #NULL is returned and the @error is set accordingly.
- * Call g_object_unref() on the returned cursor when no longer needed.
- *
- * Since: 0.10
- */
-
- /**
- * tracker_sparql_connection_query_async:
- * @self: a #TrackerSparqlConnection
- * @sparql: string containing the SPARQL query
- * @cancellable: a #GCancellable used to cancel the operation
- * @_callback_: user-defined #GAsyncReadyCallback to be called when
- * asynchronous operation is finished.
- * @_user_data_: user-defined data to be passed to @_callback_
- *
- * Executes asynchronously a SPARQL query.
- *
- * Since: 0.10
- */
- public async abstract Cursor query_async (string sparql, Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, DBusError;
-
- /**
- * tracker_sparql_connection_update:
- * @self: a #TrackerSparqlConnection
- * @sparql: string containing the SPARQL update query
- * @priority: the priority for the operation
- * @cancellable: a #GCancellable used to cancel the operation
- * @error: #GError for error reporting.
- *
- * Executes a SPARQL update. The API call is completely
- * synchronous, so it may block.
- *
- * The @sparql query should be built with #TrackerResource, or
- * its parts correctly escaped using tracker_sparql_escape_string(),
- * otherwise SPARQL injection is possible.
- *
- * Since: 0.10
- */
- public virtual void update (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, DBusError {
- warning ("Interface 'update' not implemented");
- }
-
- /**
- * tracker_sparql_connection_update_async:
- * @self: a #TrackerSparqlConnection
- * @sparql: string containing the SPARQL update query
- * @priority: the priority for the asynchronous operation
- * @cancellable: a #GCancellable used to cancel the operation
- * @_callback_: user-defined #GAsyncReadyCallback to be called when
- * asynchronous operation is finished.
- * @_user_data_: user-defined data to be passed to @_callback_
- *
- * Executes asynchronously a SPARQL update.
- *
- * Since: 0.10
- */
-
- /**
- * tracker_sparql_connection_update_finish:
- * @self: a #TrackerSparqlConnection
- * @_res_: a #GAsyncResult with the result of the operation
- * @error: #GError for error reporting.
- *
- * Finishes the asynchronous SPARQL update operation.
- *
- * Since: 0.10
- */
- public async virtual void update_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, DBusError {
- warning ("Interface 'update_async' not implemented");
- }
-
- /**
- * tracker_sparql_connection_update_array_async:
- * @self: a #TrackerSparqlConnection
- * @sparql: an array of strings containing the SPARQL update queries
- * @sparql_length1: the amount of strings you pass as @sparql
- * @priority: the priority for the asynchronous operation
- * @cancellable: a #GCancellable used to cancel the operation
- * @_callback_: user-defined #GAsyncReadyCallback to be called when
- * asynchronous operation is finished.
- * @_user_data_: user-defined data to be passed to @_callback_
- *
- * Executes asynchronously an array of SPARQL updates.
- *
- * Since: 0.10
- */
-
- /**
- * tracker_sparql_connection_update_array_finish:
- * @self: a #TrackerSparqlConnection
- * @_res_: a #GAsyncResult with the result of the operation
- * @error: #GError for error reporting.
- *
- * Finishes the asynchronous SPARQL update_array operation.
- *
- * <example>
- * <programlisting>
- * static void
- * async_update_array_callback (GObject *source_object,
- * GAsyncResult *result,
- * gpointer user_data)
- * {
- * GError *error = NULL;
- * GPtrArray *errors;
- * guint i;
- *
- * errors = tracker_sparql_connection_update_array_finish (connection, result, &error);
- * g_assert_no_error (error);
- *
- * for (i = 0; i < errors->len; i++) {
- * const GError *e = g_ptr_array_index (errors, i);
- *
- * ...
- * }
- *
- * g_ptr_array_unref (errors);
- * }
- * </programlisting>
- * </example>
- *
- * Returns: %TRUE if the update was successful, %FALSE otherwise.
- *
- * Since: 0.10
- */
- public async virtual bool update_array_async (string[] sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, DBusError {
- warning ("Interface 'update_array_async' not implemented");
- return false;
- }
-
- /**
- * tracker_sparql_connection_update_blank:
- * @self: a #TrackerSparqlConnection
- * @sparql: string containing the SPARQL update query
- * @priority: the priority for the operation
- * @cancellable: a #GCancellable used to cancel the operation
- * @error: #GError for error reporting.
- *
- * Executes a SPARQL update and returns the URNs of the generated nodes,
- * if any. The API call is completely synchronous, so it may block.
- *
- * The @sparql query should be built with #TrackerResource, or
- * its parts correctly escaped using tracker_sparql_escape_string(),
- * otherwise SPARQL injection is possible.
- *
- * Returns: a #GVariant with the generated URNs, which should be freed with
- * g_variant_unref() when no longer used.
- *
- * Since: 0.10
- */
- public virtual GLib.Variant? update_blank (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, DBusError {
- warning ("Interface 'update_blank' not implemented");
- return null;
- }
-
- /**
- * tracker_sparql_connection_update_blank_async:
- * @self: a #TrackerSparqlConnection
- * @sparql: string containing the SPARQL update query
- * @priority: the priority for the asynchronous operation
- * @cancellable: a #GCancellable used to cancel the operation
- * @_callback_: user-defined #GAsyncReadyCallback to be called when
- * asynchronous operation is finished.
- * @_user_data_: user-defined data to be passed to @_callback_
- *
- * Executes asynchronously a SPARQL update.
- *
- * Since: 0.10
- */
-
- /**
- * tracker_sparql_connection_update_blank_finish:
- * @self: a #TrackerSparqlConnection
- * @_res_: a #GAsyncResult with the result of the operation
- * @error: #GError for error reporting.
- *
- * Finishes the asynchronous SPARQL update operation, and returns
- * the URNs of the generated nodes, if any.
- *
- * Returns: a #GVariant with the generated URNs, which should be freed with
- * g_variant_unref() when no longer used.
- *
- * Since: 0.10
- */
- public async virtual GLib.Variant? update_blank_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, DBusError {
- warning ("Interface 'update_blank_async' not implemented");
- return null;
- }
-
- /**
- * tracker_sparql_connection_get_namespace_manager:
- * @self: a #TrackerSparqlConnection
- *
- * Retrieves a #TrackerNamespaceManager that contains all
- * prefixes in the ontology of @self.
- *
- * Returns: (transfer none): a #TrackerNamespaceManager for this
- * connection. This object is owned by @self and must not be freed.
- *
- * Since: 2.0
- */
- public virtual NamespaceManager? get_namespace_manager () {
- warning ("Not implemented");
- return null;
- }
-
- /**
- * tracker_sparql_connection_query_statement:
- * @self: a #TrackerSparqlConnection
- * @sparql: the SPARQL query
- * @cancellable: a #GCancellable used to cancel the operation, or %NULL
- * @error: a #TrackerSparqlError or %NULL if no error occured
- *
- * Prepares the given @sparql as a #TrackerSparqlStatement.
- *
- * Since: 2.2
- */
- public virtual Statement? query_statement (string sparql, Cancellable? cancellable = null) throws Sparql.Error {
- warning ("Interface 'query_statement' not implemented");
- return null;
- }
-
- public virtual Tracker.Notifier? create_notifier (Tracker.NotifierFlags flags) {
- warning ("Interface 'create_notifier' not implemented");
- return null;
- }
-
- /**
- * tracker_sparql_connection_close:
- * @self: a #TrackerSparqlConnection
- *
- * Closes a SPARQL connection. No other API calls than g_object_unref()
- * should happen after this call.
- *
- * This call is blocking. All pending updates will be flushed, and the
- * store databases will be closed orderly. All ongoing SELECT queries
- * will be cancelled.
- *
- * Since: 3.0
- */
- public virtual void close () {
- warning ("Not implemented");
- }
-}
diff --git a/src/libtracker-sparql/tracker-cursor.c b/src/libtracker-sparql/tracker-cursor.c
new file mode 100644
index 000000000..2bc8efa73
--- /dev/null
+++ b/src/libtracker-sparql/tracker-cursor.c
@@ -0,0 +1,489 @@
+/*
+ * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
+ *
+ * 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.
+ */
+/**
+ * SECTION: tracker-sparql-cursor
+ * @short_description: Iteration of the query results
+ * @title: TrackerSparqlCursor
+ * @stability: Stable
+ * @include: tracker-sparql.h
+ *
+ * <para>
+ * #TrackerSparqlCursor is an object which provides methods to iterate the
+ * results of a query to the Tracker Store.
+ * </para>
+ */
+#include "config.h"
+
+#include "tracker-cursor.h"
+
+enum {
+ PROP_0,
+ PROP_CONNECTION,
+ PROP_N_COLUMNS,
+ N_PROPS
+};
+
+static GParamSpec *props[N_PROPS];
+
+typedef struct {
+ TrackerSparqlConnection *connection;
+ gint n_columns;
+} TrackerSparqlCursorPrivate;
+
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (TrackerSparqlCursor, tracker_sparql_cursor,
+ G_TYPE_OBJECT)
+
+static void
+tracker_sparql_cursor_init (TrackerSparqlCursor *cursor)
+{
+}
+
+static gint64
+tracker_sparql_cursor_real_get_integer (TrackerSparqlCursor *cursor,
+ gint column)
+{
+ if (tracker_sparql_cursor_get_value_type (cursor, column) == TRACKER_SPARQL_VALUE_TYPE_INTEGER) {
+ const gchar *text;
+
+ text = tracker_sparql_cursor_get_string (cursor, column, NULL);
+ return g_ascii_strtoll (text, NULL, 10);
+ }
+
+ return 0;
+}
+
+static gdouble
+tracker_sparql_cursor_real_get_double (TrackerSparqlCursor *cursor,
+ gint column)
+{
+ if (tracker_sparql_cursor_get_value_type (cursor, column) == TRACKER_SPARQL_VALUE_TYPE_DOUBLE) {
+ const gchar *text;
+
+ text = tracker_sparql_cursor_get_string (cursor, column, NULL);
+ return g_ascii_strtod (text, NULL);
+ }
+
+ return 0.0;
+}
+
+static gboolean
+tracker_sparql_cursor_real_get_boolean (TrackerSparqlCursor *cursor,
+ gint column)
+{
+ if (tracker_sparql_cursor_get_value_type (cursor, column) == TRACKER_SPARQL_VALUE_TYPE_BOOLEAN) {
+ const gchar *text;
+
+ text = tracker_sparql_cursor_get_string (cursor, column, NULL);
+ return g_ascii_strcasecmp (text, "true") == 0;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+tracker_sparql_cursor_real_is_bound (TrackerSparqlCursor *cursor,
+ gint column)
+{
+ return tracker_sparql_cursor_get_value_type (cursor, column) != TRACKER_SPARQL_VALUE_TYPE_UNBOUND;
+}
+
+static void
+tracker_sparql_cursor_finalize (GObject *object)
+{
+ TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (object);
+ TrackerSparqlCursorPrivate *priv = tracker_sparql_cursor_get_instance_private (cursor);
+
+ g_clear_object (&priv->connection);
+ G_OBJECT_CLASS (tracker_sparql_cursor_parent_class)->finalize (object);
+}
+
+static void
+tracker_sparql_cursor_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (object);
+ TrackerSparqlCursorPrivate *priv = tracker_sparql_cursor_get_instance_private (cursor);
+
+ switch (prop_id) {
+ case PROP_CONNECTION:
+ priv->connection = g_value_dup_object (value);
+ break;
+ case PROP_N_COLUMNS:
+ priv->n_columns = g_value_get_int (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+tracker_sparql_cursor_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerSparqlCursor *cursor = TRACKER_SPARQL_CURSOR (object);
+ TrackerSparqlCursorPrivate *priv = tracker_sparql_cursor_get_instance_private (cursor);
+
+ switch (prop_id) {
+ case PROP_CONNECTION:
+ g_value_set_object (value, priv->connection);
+ break;
+ case PROP_N_COLUMNS:
+ g_value_set_int (value, priv->n_columns);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+tracker_sparql_cursor_class_init (TrackerSparqlCursorClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = tracker_sparql_cursor_finalize;
+ object_class->set_property = tracker_sparql_cursor_set_property;
+ object_class->get_property = tracker_sparql_cursor_get_property;
+
+ klass->get_integer = tracker_sparql_cursor_real_get_integer;
+ klass->get_double = tracker_sparql_cursor_real_get_double;
+ klass->get_boolean = tracker_sparql_cursor_real_get_boolean;
+ klass->is_bound = tracker_sparql_cursor_real_is_bound;
+
+ /**
+ * TrackerSparqlCursor:connection:
+ *
+ * The #TrackerSparqlConnection used to retrieve the results.
+ */
+ props[PROP_CONNECTION] =
+ g_param_spec_object ("connection",
+ "connection",
+ "connection",
+ TRACKER_SPARQL_TYPE_CONNECTION,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_READABLE |
+ G_PARAM_WRITABLE);
+ /**
+ * TrackerSparqlCursor:n_columns:
+ *
+ * Number of columns available in the results to iterate.
+ */
+ props[PROP_N_COLUMNS] =
+ g_param_spec_int ("n-columns",
+ "n-columns",
+ "n-columns",
+ G_MININT, G_MAXINT, 0,
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_READABLE);
+
+ g_object_class_install_properties (object_class, N_PROPS, props);
+}
+
+/**
+ * tracker_sparql_cursor_get_connection:
+ * @cursor: a #TrackerSparqlCursor
+ *
+ * Returns: (transfer none): the #TrackerSparqlConnection associated with this
+ * #TrackerSparqlCursor. The returned object must not be unreferenced
+ * by the caller.
+ */
+TrackerSparqlConnection *
+tracker_sparql_cursor_get_connection (TrackerSparqlCursor *cursor)
+{
+ TrackerSparqlCursorPrivate *priv = tracker_sparql_cursor_get_instance_private (cursor);
+
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor), NULL);
+
+ return priv->connection;
+}
+
+void
+tracker_sparql_cursor_set_connection (TrackerSparqlCursor *cursor,
+ TrackerSparqlConnection *connection)
+{
+ TrackerSparqlCursorPrivate *priv = tracker_sparql_cursor_get_instance_private (cursor);
+
+ g_return_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor));
+ g_return_if_fail (TRACKER_IS_SPARQL_CONNECTION (connection));
+
+ g_set_object (&priv->connection, connection);
+}
+
+/**
+ * tracker_sparql_cursor_get_n_columns:
+ * @cursor: a #TrackerSparqlCursor
+ *
+ * This method should only be called after a successful
+ * tracker_sparql_cursor_next(); otherwise its return value
+ * will be undefined.
+ *
+ * Returns: a #gint representing the number of columns available in the
+ * results to iterate.
+ */
+gint
+tracker_sparql_cursor_get_n_columns (TrackerSparqlCursor *cursor)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor), 0);
+
+ return TRACKER_SPARQL_CURSOR_GET_CLASS (cursor)->get_n_columns (cursor);
+}
+
+/**
+ * tracker_sparql_cursor_get_string:
+ * @cursor: a #TrackerSparqlCursor
+ * @column: column number to retrieve (first one is 0)
+ * @length: length of the returned string
+ *
+ * Retrieves a string representation of the data in the current
+ * row in @column.
+ *
+ * Returns: a string which must not be freed. %NULL is returned if
+ * the column is not in the [0,#n_columns] range.
+ */
+const gchar *
+tracker_sparql_cursor_get_string (TrackerSparqlCursor *cursor,
+ gint column,
+ glong *length)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor), NULL);
+
+ return TRACKER_SPARQL_CURSOR_GET_CLASS (cursor)->get_string (cursor,
+ column,
+ length);
+}
+
+/**
+ * tracker_sparql_cursor_get_boolean:
+ * @cursor: a #TrackerSparqlCursor
+ * @column: column number to retrieve (first one is 0)
+ *
+ * Retrieve a boolean for the current row in @column.
+ *
+ * Returns: a #gboolean.
+ */
+gboolean
+tracker_sparql_cursor_get_boolean (TrackerSparqlCursor *cursor,
+ gint column)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor), FALSE);
+
+ return TRACKER_SPARQL_CURSOR_GET_CLASS (cursor)->get_boolean (cursor,
+ column);
+}
+
+/**
+ * tracker_sparql_cursor_get_double:
+ * @cursor: a #TrackerSparqlCursor
+ * @column: column number to retrieve (first one is 0)
+ *
+ * Retrieve a double for the current row in @column.
+ *
+ * Returns: a double.
+ */
+gdouble
+tracker_sparql_cursor_get_double (TrackerSparqlCursor *cursor,
+ gint column)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor), -1);
+
+ return TRACKER_SPARQL_CURSOR_GET_CLASS (cursor)->get_double (cursor,
+ column);
+}
+
+/**
+ * tracker_sparql_cursor_get_integer:
+ * @cursor: a #TrackerSparqlCursor
+ * @column: column number to retrieve (first one is 0)
+ *
+ * Retrieve an integer for the current row in @column.
+ *
+ * Returns: a #gint64.
+ */
+gint64
+tracker_sparql_cursor_get_integer (TrackerSparqlCursor *cursor,
+ gint column)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor), -1);
+
+ return TRACKER_SPARQL_CURSOR_GET_CLASS (cursor)->get_integer (cursor,
+ column);
+}
+
+/**
+ * tracker_sparql_cursor_get_value_type:
+ * @cursor: a #TrackerSparqlCursor
+ * @column: column number to retrieve (first one is 0)
+ *
+ * The data type bound to the current row in @column is returned.
+ *
+ * Returns: a #TrackerSparqlValueType.
+ */
+TrackerSparqlValueType
+tracker_sparql_cursor_get_value_type (TrackerSparqlCursor *cursor,
+ gint column)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor),
+ TRACKER_SPARQL_VALUE_TYPE_UNBOUND);
+
+ return TRACKER_SPARQL_CURSOR_GET_CLASS (cursor)->get_value_type (cursor,
+ column);
+}
+
+/**
+ * tracker_sparql_cursor_get_variable_name:
+ * @cursor: a #TrackerSparqlCursor
+ * @column: column number to retrieve (first one is 0)
+ *
+ * Retrieves the variable name for the current row in @column.
+ *
+ * Returns: a string which must not be freed.
+ */
+const gchar *
+tracker_sparql_cursor_get_variable_name (TrackerSparqlCursor *cursor,
+ gint column)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor), NULL);
+
+ return TRACKER_SPARQL_CURSOR_GET_CLASS (cursor)->get_variable_name (cursor,
+ column);
+}
+
+/**
+ * tracker_sparql_cursor_close:
+ * @cursor: a #TrackerSparqlCursor
+ *
+ * Closes the iterator, making it invalid.
+ */
+void
+tracker_sparql_cursor_close (TrackerSparqlCursor *cursor)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor));
+
+ return TRACKER_SPARQL_CURSOR_GET_CLASS (cursor)->close (cursor);
+}
+
+/**
+ * tracker_sparql_cursor_is_bound:
+ * @cursor: a #TrackerSparqlCursor
+ * @column: column number to retrieve (first one is 0)
+ *
+ * If the current row and @column are bound to a value, %TRUE is returned.
+ *
+ * Returns: a %TRUE or %FALSE.
+ */
+gboolean
+tracker_sparql_cursor_is_bound (TrackerSparqlCursor *cursor,
+ gint column)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor), FALSE);
+
+ return TRACKER_SPARQL_CURSOR_GET_CLASS (cursor)->is_bound (cursor, column);
+}
+
+/**
+ * tracker_sparql_cursor_next:
+ * @cursor: a #TrackerSparqlCursor
+ * @cancellable: a #GCancellable used to cancel the operation
+ * @error: #GError for error reporting.
+ *
+ * Iterates to the next result. This is completely synchronous and
+ * it may block.
+ *
+ * Returns: %FALSE if no more results found, otherwise %TRUE.
+ */
+gboolean
+tracker_sparql_cursor_next (TrackerSparqlCursor *cursor,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor), FALSE);
+ g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
+ g_return_val_if_fail (!error || !*error, FALSE);
+
+ return TRACKER_SPARQL_CURSOR_GET_CLASS (cursor)->next (cursor,
+ cancellable,
+ error);
+}
+
+/**
+ * tracker_sparql_cursor_next_async:
+ * @cursor: a #TrackerSparqlCursor
+ * @cancellable: a #GCancellable used to cancel the operation
+ * @callback: user-defined #GAsyncReadyCallback to be called when
+ * asynchronous operation is finished.
+ * @user_data: user-defined data to be passed to @callback
+ *
+ * Iterates, asynchronously, to the next result.
+ */
+void
+tracker_sparql_cursor_next_async (TrackerSparqlCursor *cursor,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor));
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ return TRACKER_SPARQL_CURSOR_GET_CLASS (cursor)->next_async (cursor,
+ cancellable,
+ callback,
+ user_data);
+}
+
+/**
+ * tracker_sparql_cursor_next_finish:
+ * @cursor: a #TrackerSparqlCursor
+ * @res: a #GAsyncResult with the result of the operation
+ * @error: #GError for error reporting.
+ *
+ * Finishes the asynchronous iteration to the next result.
+ *
+ * Returns: %FALSE if no more results found, otherwise %TRUE.
+ */
+gboolean
+tracker_sparql_cursor_next_finish (TrackerSparqlCursor *cursor,
+ GAsyncResult *res,
+ GError **error)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor), FALSE);
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (res), FALSE);
+ g_return_val_if_fail (!error || !*error, FALSE);
+
+ return TRACKER_SPARQL_CURSOR_GET_CLASS (cursor)->next_finish (cursor,
+ res,
+ error);
+}
+
+/**
+ * tracker_sparql_cursor_rewind:
+ * @cursor: a #TrackerSparqlCursor
+ *
+ * Resets the iterator to point back to the first result.
+ */
+void
+tracker_sparql_cursor_rewind (TrackerSparqlCursor *cursor)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_CURSOR (cursor));
+
+ return TRACKER_SPARQL_CURSOR_GET_CLASS (cursor)->rewind (cursor);
+}
diff --git a/src/libtracker-sparql/tracker-cursor.h b/src/libtracker-sparql/tracker-cursor.h
new file mode 100644
index 000000000..7016b01f2
--- /dev/null
+++ b/src/libtracker-sparql/tracker-cursor.h
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
+ *
+ * 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 __TRACKER_SPARQL_CURSOR_H__
+#define __TRACKER_SPARQL_CURSOR_H__
+
+#if !defined (__LIBTRACKER_SPARQL_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-sparql/tracker-sparql.h> must be included directly."
+#endif
+
+#include <gio/gio.h>
+
+/**
+ * TrackerSparqlCursor:
+ *
+ * The <structname>TrackerSparqlCursor</structname> object represents an
+ * iterator of results.
+ */
+#define TRACKER_TYPE_SPARQL_CURSOR tracker_sparql_cursor_get_type ()
+#define TRACKER_SPARQL_TYPE_CURSOR TRACKER_TYPE_SPARQL_CURSOR
+G_DECLARE_DERIVABLE_TYPE (TrackerSparqlCursor, tracker_sparql_cursor,
+ TRACKER, SPARQL_CURSOR, GObject)
+
+#include "tracker-connection.h"
+
+/**
+ * TrackerSparqlValueType:
+ * @TRACKER_SPARQL_VALUE_TYPE_UNBOUND: Unbound value type
+ * @TRACKER_SPARQL_VALUE_TYPE_URI: Uri value type, rdfs:Resource
+ * @TRACKER_SPARQL_VALUE_TYPE_STRING: String value type, xsd:string
+ * @TRACKER_SPARQL_VALUE_TYPE_INTEGER: Integer value type, xsd:integer
+ * @TRACKER_SPARQL_VALUE_TYPE_DOUBLE: Double value type, xsd:double
+ * @TRACKER_SPARQL_VALUE_TYPE_DATETIME: Datetime value type, xsd:dateTime
+ * @TRACKER_SPARQL_VALUE_TYPE_BLANK_NODE: Blank node value type
+ * @TRACKER_SPARQL_VALUE_TYPE_BOOLEAN: Boolean value type, xsd:boolean
+ *
+ * Enumeration with the possible types of the cursor's cells
+ */
+typedef enum {
+ TRACKER_SPARQL_VALUE_TYPE_UNBOUND,
+ TRACKER_SPARQL_VALUE_TYPE_URI,
+ TRACKER_SPARQL_VALUE_TYPE_STRING,
+ TRACKER_SPARQL_VALUE_TYPE_INTEGER,
+ TRACKER_SPARQL_VALUE_TYPE_DOUBLE,
+ TRACKER_SPARQL_VALUE_TYPE_DATETIME,
+ TRACKER_SPARQL_VALUE_TYPE_BLANK_NODE,
+ TRACKER_SPARQL_VALUE_TYPE_BOOLEAN,
+} TrackerSparqlValueType;
+
+struct _TrackerSparqlCursorClass
+{
+ GObjectClass parent_class;
+
+ TrackerSparqlValueType (* get_value_type) (TrackerSparqlCursor *cursor,
+ gint column);
+ const gchar* (* get_variable_name) (TrackerSparqlCursor *cursor,
+ gint column);
+ const gchar* (* get_string) (TrackerSparqlCursor *cursor,
+ gint column,
+ glong *length);
+ gboolean (* next) (TrackerSparqlCursor *cursor,
+ GCancellable *cancellable,
+ GError **error);
+ void (* next_async) (TrackerSparqlCursor *cursor,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ gboolean (* next_finish) (TrackerSparqlCursor *cursor,
+ GAsyncResult *res,
+ GError **error);
+ void (* rewind) (TrackerSparqlCursor* cursor);
+ void (* close) (TrackerSparqlCursor* cursor);
+ gint64 (* get_integer) (TrackerSparqlCursor *cursor,
+ gint column);
+ gdouble (* get_double) (TrackerSparqlCursor *cursor,
+ gint column);
+ gboolean (* get_boolean) (TrackerSparqlCursor *cursor,
+ gint column);
+ gboolean (* is_bound) (TrackerSparqlCursor *cursor,
+ gint column);
+ gint (* get_n_columns) (TrackerSparqlCursor *cursor);
+};
+
+TrackerSparqlConnection * tracker_sparql_cursor_get_connection (TrackerSparqlCursor *cursor);
+gint tracker_sparql_cursor_get_n_columns (TrackerSparqlCursor *cursor);
+
+const gchar * tracker_sparql_cursor_get_string (TrackerSparqlCursor *cursor,
+ gint column,
+ glong *length);
+gboolean tracker_sparql_cursor_get_boolean (TrackerSparqlCursor *cursor,
+ gint column);
+gdouble tracker_sparql_cursor_get_double (TrackerSparqlCursor *cursor,
+ gint column);
+gint64 tracker_sparql_cursor_get_integer (TrackerSparqlCursor *cursor,
+ gint column);
+TrackerSparqlValueType tracker_sparql_cursor_get_value_type (TrackerSparqlCursor *cursor,
+ gint column);
+const gchar * tracker_sparql_cursor_get_variable_name (TrackerSparqlCursor *cursor,
+ gint column);
+void tracker_sparql_cursor_close (TrackerSparqlCursor *cursor);
+
+gboolean tracker_sparql_cursor_is_bound (TrackerSparqlCursor *cursor,
+ gint column);
+
+gboolean tracker_sparql_cursor_next (TrackerSparqlCursor *cursor,
+ GCancellable *cancellable,
+ GError **error);
+
+void tracker_sparql_cursor_next_async (TrackerSparqlCursor *cursor,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean tracker_sparql_cursor_next_finish (TrackerSparqlCursor *cursor,
+ GAsyncResult *res,
+ GError **error);
+
+void tracker_sparql_cursor_rewind (TrackerSparqlCursor *cursor);
+
+#endif /* __TRACKER_SPARQL_CURSOR_H__ */
diff --git a/src/libtracker-sparql/tracker-cursor.vala b/src/libtracker-sparql/tracker-cursor.vala
deleted file mode 100644
index 42c1a6afb..000000000
--- a/src/libtracker-sparql/tracker-cursor.vala
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
- *
- * 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.
- */
-
-/**
- * SECTION: tracker-sparql-cursor
- * @short_description: Iteration of the query results
- * @title: TrackerSparqlCursor
- * @stability: Stable
- * @include: tracker-sparql.h
- *
- * <para>
- * #TrackerSparqlCursor is an object which provides methods to iterate the
- * results of a query to the Tracker Store.
- * </para>
- */
-
-/**
- * TrackerSparqlValueType:
- * @TRACKER_SPARQL_VALUE_TYPE_UNBOUND: Unbound value type
- * @TRACKER_SPARQL_VALUE_TYPE_URI: Uri value type, rdfs:Resource
- * @TRACKER_SPARQL_VALUE_TYPE_STRING: String value type, xsd:string
- * @TRACKER_SPARQL_VALUE_TYPE_INTEGER: Integer value type, xsd:integer
- * @TRACKER_SPARQL_VALUE_TYPE_DOUBLE: Double value type, xsd:double
- * @TRACKER_SPARQL_VALUE_TYPE_DATETIME: Datetime value type, xsd:dateTime
- * @TRACKER_SPARQL_VALUE_TYPE_BLANK_NODE: Blank node value type
- * @TRACKER_SPARQL_VALUE_TYPE_BOOLEAN: Boolean value type, xsd:boolean
- *
- * Enumeration with the possible types of the cursor's cells
- *
- * Since: 0.10
- */
-public enum Tracker.Sparql.ValueType {
- UNBOUND,
- URI,
- STRING,
- INTEGER,
- DOUBLE,
- DATETIME,
- BLANK_NODE,
- BOOLEAN
-}
-
-/**
- * TrackerSparqlCursor:
- *
- * The <structname>TrackerSparqlCursor</structname> object represents an
- * iterator of results.
- */
-public abstract class Tracker.Sparql.Cursor : Object {
-
- /**
- * TrackerSparqlCursor:connection:
- *
- * The #TrackerSparqlConnection used to retrieve the results.
- *
- * Since: 0.10
- */
- public Connection connection {
- /**
- * tracker_sparql_cursor_get_connection:
- * @self: a #TrackerSparqlCursor
- *
- * Returns: the #TrackerSparqlConnection associated with this
- * #TrackerSparqlCursor. The returned object must not be unreferenced
- * by the caller.
- *
- * Since: 0.10
- */
- get;
- // Note: set method hidden in the documentation as the user of the
- // library should never use it.
- set;
- }
-
- /**
- * TrackerSparqlCursor:n_columns:
- *
- * Number of columns available in the results to iterate.
- *
- * Since: 0.10
- */
- public abstract int n_columns {
- /**
- * tracker_sparql_cursor_get_n_columns:
- * @self: a #TrackerSparqlCursor
- *
- * This method should only be called after a successful
- * tracker_sparql_cursor_next(); otherwise its return value
- * will be undefined.
- *
- * Returns: a #gint representing the number of columns available in the
- * results to iterate.
- *
- * Since: 0.10
- */
- get;
- }
-
- /**
- * tracker_sparql_cursor_get_value_type:
- * @self: a #TrackerSparqlCursor
- * @column: column number to retrieve (first one is 0)
- *
- * The data type bound to the current row in @column is returned.
- *
- * Returns: a #TrackerSparqlValueType.
- *
- * Since: 0.10
- */
- public abstract ValueType get_value_type (int column);
-
- /**
- * tracker_sparql_cursor_get_variable_name:
- * @self: a #TrackerSparqlCursor
- * @column: column number to retrieve (first one is 0)
- *
- * Retrieves the variable name for the current row in @column.
- *
- * Returns: a string which must not be freed.
- *
- * Since: 0.10
- */
- public abstract unowned string? get_variable_name (int column);
-
- /**
- * tracker_sparql_cursor_get_string:
- * @self: a #TrackerSparqlCursor
- * @column: column number to retrieve (first one is 0)
- * @length: length of the returned string
- *
- * Retrieves a string representation of the data in the current
- * row in @column.
- *
- * Returns: a string which must not be freed. %NULL is returned if
- * the column is not in the [0,#n_columns] range.
- *
- * Since: 0.10
- */
- public abstract unowned string? get_string (int column, out long length = null);
-
- /**
- * tracker_sparql_cursor_next:
- * @self: a #TrackerSparqlCursor
- * @cancellable: a #GCancellable used to cancel the operation
- * @error: #GError for error reporting.
- *
- * Iterates to the next result. This is completely synchronous and
- * it may block.
- *
- * Returns: %FALSE if no more results found, otherwise %TRUE.
- *
- * Since: 0.10
- */
- public abstract bool next (Cancellable? cancellable = null) throws GLib.Error;
-
- /**
- * tracker_sparql_cursor_next_finish:
- * @self: a #TrackerSparqlCursor
- * @_res_: a #GAsyncResult with the result of the operation
- * @error: #GError for error reporting.
- *
- * Finishes the asynchronous iteration to the next result.
- *
- * Returns: %FALSE if no more results found, otherwise %TRUE.
- *
- * Since: 0.10
- */
-
- /**
- * tracker_sparql_cursor_next_async:
- * @self: a #TrackerSparqlCursor
- * @cancellable: a #GCancellable used to cancel the operation
- * @_callback_: user-defined #GAsyncReadyCallback to be called when
- * asynchronous operation is finished.
- * @_user_data_: user-defined data to be passed to @_callback_
- *
- * Iterates, asynchronously, to the next result.
- *
- * Since: 0.10
- */
- public async abstract bool next_async (Cancellable? cancellable = null) throws GLib.Error;
-
- /**
- * tracker_sparql_cursor_rewind:
- * @self: a #TrackerSparqlCursor
- *
- * Resets the iterator to point back to the first result.
- *
- * Since: 0.10
- */
- public abstract void rewind ();
-
- /**
- * tracker_sparql_cursor_close:
- * @self: a #TrackerSparqlCursor
- *
- * Closes the iterator, making it invalid.
- *
- * Since: 0.12
- */
- public virtual void close () {
- }
-
- /**
- * tracker_sparql_cursor_get_integer:
- * @self: a #TrackerSparqlCursor
- * @column: column number to retrieve (first one is 0)
- *
- * Retrieve an integer for the current row in @column.
- *
- * Returns: a #gint64.
- *
- * Since: 0.10
- */
- public virtual int64 get_integer (int column) {
- return_val_if_fail (get_value_type (column) == ValueType.INTEGER, 0);
- unowned string as_str = get_string (column);
- return int64.parse (as_str);
- }
-
- /**
- * tracker_sparql_cursor_get_double:
- * @self: a #TrackerSparqlCursor
- * @column: column number to retrieve (first one is 0)
- *
- * Retrieve a double for the current row in @column.
- *
- * Returns: a double.
- *
- * Since: 0.10
- */
- public virtual double get_double (int column) {
- return_val_if_fail (get_value_type (column) == ValueType.DOUBLE, 0);
- unowned string as_str = get_string (column);
- return double.parse (as_str);
- }
-
- /**
- * tracker_sparql_cursor_get_boolean:
- * @self: a #TrackerSparqlCursor
- * @column: column number to retrieve (first one is 0)
- *
- * Retrieve a boolean for the current row in @column.
- *
- * Returns: a #gboolean.
- *
- * Since: 0.10
- */
- public virtual bool get_boolean (int column) {
- ValueType type = get_value_type (column);
- return_val_if_fail (type == ValueType.BOOLEAN, 0);
- unowned string as_str = get_string (column);
-
- if (as_str != null && as_str.ascii_casecmp ("true") == 0) {
- return true;
- }
-
- return false;
- }
-
- /**
- * tracker_sparql_cursor_is_bound:
- * @self: a #TrackerSparqlCursor
- * @column: column number to retrieve (first one is 0)
- *
- * If the current row and @column are bound to a value, %TRUE is returned.
- *
- * Returns: a %TRUE or %FALSE.
- *
- * Since: 0.10
- */
- public virtual bool is_bound (int column) {
- if (get_value_type (column) != ValueType.UNBOUND) {
- return true;
- }
- return false;
- }
-}
diff --git a/src/libtracker-sparql/tracker-endpoint-dbus.c b/src/libtracker-sparql/tracker-endpoint-dbus.c
index d4471f7e1..53f08b431 100644
--- a/src/libtracker-sparql/tracker-endpoint-dbus.c
+++ b/src/libtracker-sparql/tracker-endpoint-dbus.c
@@ -22,6 +22,7 @@
#include "config.h"
#include "tracker-endpoint-dbus.h"
+#include "tracker-notifier.h"
#include <gio/gio.h>
#include <gio/gunixinputstream.h>
@@ -642,7 +643,7 @@ tracker_endpoint_dbus_new (TrackerSparqlConnection *sparql_connection,
GCancellable *cancellable,
GError **error)
{
- g_return_val_if_fail (TRACKER_SPARQL_IS_CONNECTION (sparql_connection), NULL);
+ g_return_val_if_fail (TRACKER_IS_SPARQL_CONNECTION (sparql_connection), NULL);
g_return_val_if_fail (G_IS_DBUS_CONNECTION (dbus_connection), NULL);
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
g_return_val_if_fail (!error || !*error, NULL);
diff --git a/src/libtracker-sparql/tracker-endpoint.h b/src/libtracker-sparql/tracker-endpoint.h
index d665b74da..580e9f7e8 100644
--- a/src/libtracker-sparql/tracker-endpoint.h
+++ b/src/libtracker-sparql/tracker-endpoint.h
@@ -27,7 +27,7 @@
#endif
#include <glib-object.h>
-#include <libtracker-sparql/tracker-generated.h>
+#include <libtracker-sparql/tracker-connection.h>
#define TRACKER_TYPE_ENDPOINT tracker_endpoint_get_type()
G_DECLARE_DERIVABLE_TYPE (TrackerEndpoint, tracker_endpoint, TRACKER, ENDPOINT, GObject)
diff --git a/src/libtracker-sparql/tracker-notifier.c b/src/libtracker-sparql/tracker-notifier.c
index e7f5f8b01..c0c90db95 100644
--- a/src/libtracker-sparql/tracker-notifier.c
+++ b/src/libtracker-sparql/tracker-notifier.c
@@ -65,10 +65,10 @@
#include "config.h"
+#include "tracker-connection.h"
#include "tracker-notifier.h"
#include "tracker-notifier-private.h"
#include "tracker-sparql-enum-types.h"
-#include "tracker-generated-no-checks.h"
#include <libtracker-common/tracker-common.h>
typedef struct _TrackerNotifierPrivate TrackerNotifierPrivate;
@@ -509,6 +509,8 @@ tracker_notifier_class_init (TrackerNotifierClass *klass)
/**
* TrackerNotifier::events:
* @self: The #TrackerNotifier
+ * @service: The SPARQL service that originated the events, %NULL for the local store
+ * @graph: The graph where the events happened on, %NULL for the default anonymous graph
* @events: (element-type TrackerNotifierEvent): A #GPtrArray of #TrackerNotifierEvent
*
* Notifies of changes in the Tracker database.
diff --git a/src/libtracker-sparql/tracker-namespace.vala b/src/libtracker-sparql/tracker-private.h
index a587a47fa..9aa2d109c 100644
--- a/src/libtracker-sparql/tracker-namespace.vala
+++ b/src/libtracker-sparql/tracker-private.h
@@ -1,5 +1,6 @@
/*
- * Copyright © 2015 Collabora Ltd.
+ * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
+ * Copyright (C) 2019, 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
@@ -16,14 +17,12 @@
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
+#ifndef __TRACKER_PRIVATE_H__
+#define __TRACKER_PRIVATE_H__
-/*
- * This file serves as the representation for the Tracker namespace, mostly
- * so that we can set its namespace and version attributes for GIR.
- */
+#include "tracker-cursor.h"
+
+void tracker_sparql_cursor_set_connection (TrackerSparqlCursor *cursor,
+ TrackerSparqlConnection *connection);
-[CCode (cprefix = "Tracker", gir_namespace = "Tracker",
- gir_version = "2.0", lower_case_cprefix = "tracker_")]
-namespace Tracker
-{
-}
+#endif /* __TRACKER_PRIVATE_H__ */
diff --git a/src/libtracker-sparql/tracker-resource.c b/src/libtracker-sparql/tracker-resource.c
index 03b45991e..c0a4aa3fe 100644
--- a/src/libtracker-sparql/tracker-resource.c
+++ b/src/libtracker-sparql/tracker-resource.c
@@ -29,7 +29,7 @@
#include <tracker-ontologies.h>
/* For tracker_sparql_escape_string */
-#include "tracker-generated-no-checks.h"
+#include "tracker-utils.h"
typedef struct {
char *identifier;
diff --git a/src/libtracker-sparql/tracker-sparql-add-include-guards.sh b/src/libtracker-sparql/tracker-sparql-add-include-guards.sh
deleted file mode 100755
index b0d68ea61..000000000
--- a/src/libtracker-sparql/tracker-sparql-add-include-guards.sh
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/bin/sh
-
-# Wrap the generated Vala header for libtracker-sparql with a #include guard.
-#
-# It's important that this only writes the header when necessary; if it gets
-# written every time then builds will run more or less from scratch whenever
-# Meson needs to reconfigure the project.
-
-set -eu
-
-in="$1"
-out="$2"
-
-(echo "#if !defined (__LIBTRACKER_SPARQL_INSIDE__) && !defined (TRACKER_COMPILATION)";
- echo "#error \"only <libtracker-sparql/tracker-sparql.h> must be included directly.\"";
- echo "#endif") > $out
-cat $in >> $out
diff --git a/src/libtracker-sparql/tracker-sparql.h b/src/libtracker-sparql/tracker-sparql.h
index a87122e4d..8555fb891 100644
--- a/src/libtracker-sparql/tracker-sparql.h
+++ b/src/libtracker-sparql/tracker-sparql.h
@@ -22,13 +22,17 @@
#define __LIBTRACKER_SPARQL_INSIDE__
+#include <libtracker-sparql/tracker-connection.h>
+#include <libtracker-sparql/tracker-cursor.h>
#include <libtracker-sparql/tracker-endpoint.h>
#include <libtracker-sparql/tracker-endpoint-dbus.h>
#include <libtracker-sparql/tracker-version.h>
#include <libtracker-sparql/tracker-ontologies.h>
#include <libtracker-sparql/tracker-resource.h>
+#include <libtracker-sparql/tracker-statement.h>
#include <libtracker-sparql/tracker-notifier.h>
-#include <libtracker-sparql/tracker-generated.h>
+#include <libtracker-sparql/tracker-sparql-enum-types.h>
+#include <libtracker-sparql/tracker-utils.h>
#undef __LIBTRACKER_SPARQL_INSIDE__
diff --git a/src/libtracker-sparql/tracker-statement.c b/src/libtracker-sparql/tracker-statement.c
new file mode 100644
index 000000000..e46e0825e
--- /dev/null
+++ b/src/libtracker-sparql/tracker-statement.c
@@ -0,0 +1,357 @@
+/*
+ * Copyright (C) 2018, Red Hat Ltd.
+ *
+ * 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.
+ */
+/**
+ * SECTION: tracker-sparql-statement
+ * @short_description: Prepared statements
+ * @title: TrackerSparqlStatement
+ * @stability: Stable
+ * @include: tracker-sparql.h
+ *
+ * The <structname>TrackerSparqlStatement</structname> object represents
+ * a SPARQL query. This query may contain parameterized variables
+ * (expressed as ~var in the syntax), which may be mapped to arbitrary
+ * values prior to execution. This statement may be reused for future
+ * queries with different values.
+ *
+ * The argument bindings may be changed through tracker_sparql_statement_bind_int(),
+ * tracker_sparql_statement_bind_boolean(), tracker_sparql_statement_bind_double()
+ * and tracker_sparql_statement_bind_string(). Those functions receive
+ * a @name argument corresponding for the variable name in the SPARQL query
+ * (eg. "var" for ~var) and a @value to map the variable to.
+ *
+ * Once all arguments have a value, the query may be executed through
+ * tracker_sparql_statement_execute() or tracker_sparql_statement_execute_async().
+ *
+ * This object was added in Tracker 2.2.
+ */
+#include "config.h"
+
+#include "tracker-statement.h"
+
+enum {
+ PROP_0,
+ PROP_CONNECTION,
+ PROP_SPARQL,
+ N_PROPS
+};
+
+static GParamSpec *props[N_PROPS];
+
+typedef struct {
+ TrackerSparqlConnection *connection;
+ gchar *sparql;
+} TrackerSparqlStatementPrivate;
+
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (TrackerSparqlStatement,
+ tracker_sparql_statement,
+ G_TYPE_OBJECT)
+
+static void
+tracker_sparql_statement_init (TrackerSparqlStatement *stmt)
+{
+}
+
+static void
+tracker_sparql_statement_finalize (GObject *object)
+{
+ TrackerSparqlStatement *stmt = TRACKER_SPARQL_STATEMENT (object);
+ TrackerSparqlStatementPrivate *priv = tracker_sparql_statement_get_instance_private (stmt);
+
+ g_clear_object (&priv->connection);
+ g_free (priv->sparql);
+ G_OBJECT_CLASS (tracker_sparql_statement_parent_class)->finalize (object);
+}
+
+static void
+tracker_sparql_statement_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerSparqlStatement *stmt = TRACKER_SPARQL_STATEMENT (object);
+ TrackerSparqlStatementPrivate *priv = tracker_sparql_statement_get_instance_private (stmt);
+
+ switch (prop_id) {
+ case PROP_CONNECTION:
+ priv->connection = g_value_dup_object (value);
+ break;
+ case PROP_SPARQL:
+ priv->sparql = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+tracker_sparql_statement_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TrackerSparqlStatement *stmt = TRACKER_SPARQL_STATEMENT (object);
+ TrackerSparqlStatementPrivate *priv = tracker_sparql_statement_get_instance_private (stmt);
+
+ switch (prop_id) {
+ case PROP_CONNECTION:
+ g_value_set_object (value, priv->connection);
+ break;
+ case PROP_SPARQL:
+ g_value_set_string (value, priv->sparql);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+tracker_sparql_statement_class_init (TrackerSparqlStatementClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = tracker_sparql_statement_finalize;
+ object_class->set_property = tracker_sparql_statement_set_property;
+ object_class->get_property = tracker_sparql_statement_get_property;
+
+ /**
+ * TrackerSparqlStatement:connection:
+ *
+ * The #TrackerSparqlConnection used to perform the query.
+ */
+ props[PROP_CONNECTION] =
+ g_param_spec_object ("connection",
+ "connection",
+ "connection",
+ TRACKER_TYPE_SPARQL_CONNECTION,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_READABLE |
+ G_PARAM_WRITABLE);
+ /**
+ * TrackerSparqlStatement:sparql:
+ *
+ * SPARQL query stored in this statement.
+ */
+ props[PROP_SPARQL] =
+ g_param_spec_string ("sparql",
+ "sparql",
+ "sparql",
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS |
+ G_PARAM_READABLE |
+ G_PARAM_WRITABLE);
+
+ g_object_class_install_properties (object_class, N_PROPS, props);
+}
+
+TrackerSparqlConnection *
+tracker_sparql_statement_get_connection (TrackerSparqlStatement *stmt)
+{
+ TrackerSparqlStatementPrivate *priv = tracker_sparql_statement_get_instance_private (stmt);
+
+ g_return_val_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt), NULL);
+
+ return priv->connection;
+}
+
+const gchar *
+tracker_sparql_statement_get_sparql (TrackerSparqlStatement *stmt)
+{
+ TrackerSparqlStatementPrivate *priv = tracker_sparql_statement_get_instance_private (stmt);
+
+ g_return_val_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt), NULL);
+
+ return priv->sparql;
+}
+
+/**
+ * tracker_sparql_statement_bind_boolean:
+ * @stmt: a #TrackerSparqlStatement
+ * @name: variable name
+ * @value: value
+ *
+ * Binds the boolean @value to variable @name.
+ */
+void
+tracker_sparql_statement_bind_boolean (TrackerSparqlStatement *stmt,
+ const gchar *name,
+ gboolean value)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
+ g_return_if_fail (name != NULL);
+
+ return TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->bind_boolean (stmt,
+ name,
+ value);
+}
+
+/**
+ * tracker_sparql_statement_bind_int:
+ * @stmt: a #TrackerSparqlStatement
+ * @name: variable name
+ * @value: value
+ *
+ * Binds the integer @value to variable @name.
+ */
+void
+tracker_sparql_statement_bind_int (TrackerSparqlStatement *stmt,
+ const gchar *name,
+ gint64 value)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
+ g_return_if_fail (name != NULL);
+
+ return TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->bind_int (stmt,
+ name,
+ value);
+}
+
+/**
+ * tracker_sparql_statement_bind_double:
+ * @stmt: a #TrackerSparqlStatement
+ * @name: variable name
+ * @value: value
+ *
+ * Binds the double @value to variable @name.
+ */
+void
+tracker_sparql_statement_bind_double (TrackerSparqlStatement *stmt,
+ const gchar *name,
+ gdouble value)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
+ g_return_if_fail (name != NULL);
+
+ return TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->bind_double (stmt,
+ name,
+ value);
+}
+
+/**
+ * tracker_sparql_statement_bind_string:
+ * @stmt: a #TrackerSparqlStatement
+ * @name: variable name
+ * @value: value
+ *
+ * Binds the string @value to variable @name.
+ */
+void
+tracker_sparql_statement_bind_string (TrackerSparqlStatement *stmt,
+ const gchar *name,
+ const gchar *value)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
+ g_return_if_fail (name != NULL);
+ g_return_if_fail (value != NULL);
+
+ return TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->bind_string (stmt,
+ name,
+ value);
+}
+
+/**
+ * tracker_sparql_statement_execute:
+ * @stmt: a #TrackerSparqlStatement
+ * @cancellable: a #GCancellable used to cancel the operation
+ * @error: #GError for error reporting.
+ *
+ * Executes the SPARQL query with the currently bound values.
+ *
+ * Returns: (transfer full): A #TrackerSparqlCursor
+ */
+TrackerSparqlCursor *
+tracker_sparql_statement_execute (TrackerSparqlStatement *stmt,
+ GCancellable *cancellable,
+ GError **error)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt), NULL);
+ g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (!error || !*error, NULL);
+
+ return TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->execute (stmt,
+ cancellable,
+ error);
+}
+
+/**
+ * tracker_sparql_statement_execute_async:
+ * @stmt: a #TrackerSparqlStatement
+ * @cancellable: a #GCancellable used to cancel the operation
+ * @callback: user-defined #GAsyncReadyCallback to be called when
+ * asynchronous operation is finished.
+ * @user_data: user-defined data to be passed to @callback
+ *
+ * Asynchronously executes the SPARQL query with the currently bound values.
+ */
+void
+tracker_sparql_statement_execute_async (TrackerSparqlStatement *stmt,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ return TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->execute_async (stmt,
+ cancellable,
+ callback,
+ user_data);
+}
+
+/**
+ * tracker_sparql_statement_execute_finish:
+ * @stmt: a #TrackerSparqlStatement
+ * @res: The #GAsyncResult from the callback used to return the #TrackerSparqlCursor
+ * @error: The error which occurred or %NULL
+ *
+ * Finishes the asynchronous operation started through
+ * tracker_sparql_statement_execute_async().
+ *
+ * Returns: (transfer full): A #TrackerSparqlCursor
+ */
+TrackerSparqlCursor *
+tracker_sparql_statement_execute_finish (TrackerSparqlStatement *stmt,
+ GAsyncResult *res,
+ GError **error)
+{
+ g_return_val_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt), NULL);
+ g_return_val_if_fail (G_IS_ASYNC_RESULT (res), NULL);
+ g_return_val_if_fail (!error || !*error, NULL);
+
+ return TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->execute_finish (stmt,
+ res,
+ error);
+}
+
+/**
+ * tracker_sparql_statement_clear_bindings:
+ * @self: a #TrackerSparqlStatement
+ *
+ * Clears all boolean/string/integer/double bindings.
+ *
+ * Since: 3.0
+ */
+void
+tracker_sparql_statement_clear_bindings (TrackerSparqlStatement *stmt)
+{
+ g_return_if_fail (TRACKER_IS_SPARQL_STATEMENT (stmt));
+
+ TRACKER_SPARQL_STATEMENT_GET_CLASS (stmt)->clear_bindings (stmt);
+}
diff --git a/src/libtracker-sparql/tracker-statement.h b/src/libtracker-sparql/tracker-statement.h
new file mode 100644
index 000000000..128e6bc09
--- /dev/null
+++ b/src/libtracker-sparql/tracker-statement.h
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2018, Red Hat Ltd.
+ *
+ * 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 __TRACKER_SPARQL_STATEMENT_H__
+#define __TRACKER_SPARQL_STATEMENT_H__
+
+#if !defined (__LIBTRACKER_SPARQL_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-sparql/tracker-sparql.h> must be included directly."
+#endif
+
+#include <gio/gio.h>
+
+#define TRACKER_TYPE_SPARQL_STATEMENT tracker_sparql_statement_get_type ()
+#define TRACKER_SPARQL_TYPE_STATEMENT TRACKER_TYPE_SPARQL_STATEMENT
+G_DECLARE_DERIVABLE_TYPE (TrackerSparqlStatement,
+ tracker_sparql_statement,
+ TRACKER, SPARQL_STATEMENT,
+ GObject)
+
+#include "tracker-connection.h"
+#include "tracker-cursor.h"
+
+struct _TrackerSparqlStatementClass
+{
+ GObjectClass parent_class;
+
+ void (* bind_int) (TrackerSparqlStatement *stmt,
+ const gchar *name,
+ gint64 value);
+ void (* bind_boolean) (TrackerSparqlStatement *stmt,
+ const gchar *name,
+ gboolean value);
+ void (* bind_string) (TrackerSparqlStatement *stmt,
+ const gchar *name,
+ const gchar *value);
+ void (* bind_double) (TrackerSparqlStatement *stmt,
+ const gchar *name,
+ gdouble value);
+
+ TrackerSparqlCursor * (* execute) (TrackerSparqlStatement *stmt,
+ GCancellable *cancellable,
+ GError **error);
+ void (* execute_async) (TrackerSparqlStatement *stmt,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+ TrackerSparqlCursor * (* execute_finish) (TrackerSparqlStatement *stmt,
+ GAsyncResult *res,
+ GError **error);
+ void (* clear_bindings) (TrackerSparqlStatement *stmt);
+};
+
+TrackerSparqlConnection * tracker_sparql_statement_get_connection (TrackerSparqlStatement *stmt);
+
+const gchar * tracker_sparql_statement_get_sparql (TrackerSparqlStatement *stmt);
+
+void tracker_sparql_statement_bind_boolean (TrackerSparqlStatement *stmt,
+ const gchar *name,
+ gboolean value);
+
+void tracker_sparql_statement_bind_int (TrackerSparqlStatement *stmt,
+ const gchar *name,
+ gint64 value);
+
+void tracker_sparql_statement_bind_double (TrackerSparqlStatement *stmt,
+ const gchar *name,
+ gdouble value);
+
+void tracker_sparql_statement_bind_string (TrackerSparqlStatement *stmt,
+ const gchar *name,
+ const gchar *value);
+
+TrackerSparqlCursor * tracker_sparql_statement_execute (TrackerSparqlStatement *stmt,
+ GCancellable *cancellable,
+ GError **error);
+
+void tracker_sparql_statement_execute_async (TrackerSparqlStatement *stmt,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+TrackerSparqlCursor * tracker_sparql_statement_execute_finish (TrackerSparqlStatement *stmt,
+ GAsyncResult *res,
+ GError **error);
+
+void tracker_sparql_statement_clear_bindings (TrackerSparqlStatement *stmt);
+
+#endif /* __TRACKER_SPARQL_STATEMENT_H__ */
diff --git a/src/libtracker-sparql/tracker-statement.vala b/src/libtracker-sparql/tracker-statement.vala
deleted file mode 100644
index 2cae06144..000000000
--- a/src/libtracker-sparql/tracker-statement.vala
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright (C) 2018, Red Hat Ltd.
- *
- * 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.
- */
-
-/**
- * SECTION: tracker-sparql-statement
- * @short_description: Prepared statements
- * @title: TrackerSparqlStatement
- * @stability: Stable
- * @include: tracker-sparql.h
- *
- * The <structname>TrackerSparqlStatement</structname> object represents
- * a SPARQL query. This query may contain parameterized variables
- * (expressed as ~var in the syntax), which may be mapped to arbitrary
- * values prior to execution. This statement may be reused for future
- * queries with different values.
- *
- * The argument bindings may be changed through tracker_sparql_statement_bind_int(),
- * tracker_sparql_statement_bind_boolean(), tracker_sparql_statement_bind_double()
- * and tracker_sparql_statement_bind_string(). Those functions receive
- * a @name argument corresponding for the variable name in the SPARQL query
- * (eg. "var" for ~var) and a @value to map the variable to.
- *
- * Once all arguments have a value, the query may be executed through
- * tracker_sparql_statement_execute() or tracker_sparql_statement_execute_async().
- *
- * This object was added in Tracker 2.2.
- */
-public abstract class Tracker.Sparql.Statement : Object {
- public string sparql { get; construct set; }
- public Connection connection { get; construct set; }
-
- /**
- * tracker_sparql_statement_bind_int:
- * @self: a #TrackerSparqlStatement
- * @name: variable name
- * @value: value
- *
- * Binds the integer @value to variable @name.
- */
- public abstract void bind_int (string name, int64 value);
-
- /**
- * tracker_sparql_statement_bind_boolean:
- * @self: a #TrackerSparqlStatement
- * @name: variable name
- * @value: value
- *
- * Binds the boolean @value to variable @name.
- */
- public abstract void bind_boolean (string name, bool value);
-
- /**
- * tracker_sparql_statement_bind_string:
- * @self: a #TrackerSparqlStatement
- * @name: variable name
- * @value: value
- *
- * Binds the string @value to variable @name.
- */
- public abstract void bind_string (string name, string value);
-
- /**
- * tracker_sparql_statement_bind_double:
- * @self: a #TrackerSparqlStatement
- * @name: variable name
- * @value: value
- *
- * Binds the double @value to variable @name.
- */
- public abstract void bind_double (string name, double value);
-
- /**
- * tracker_sparql_statement_clear_bindings:
- * @self: a #TrackerSparqlStatement
- *
- * Clears all boolean/string/integer/double bindings.
- *
- * Since: 3.0
- */
- public abstract void clear_bindings ();
-
- /**
- * tracker_sparql_statement_execute:
- * @self: a #TrackerSparqlStatement
- * @cancellable: a #GCancellable used to cancel the operation
- * @error: #GError for error reporting.
- *
- * Executes the SPARQL query with the currently bound values.
- *
- * Returns: (transfer full): A #TrackerSparqlCursor
- */
- public abstract Cursor execute (Cancellable? cancellable) throws Sparql.Error, GLib.Error, GLib.IOError, DBusError;
-
- /**
- * tracker_sparql_statement_execute_finish:
- * @self: a #TrackerSparqlStatement
- * @_res_: The #GAsyncResult from the callback used to return the #TrackerSparqlCursor
- * @error: The error which occurred or %NULL
- *
- * Finishes the asynchronous operation started through
- * tracker_sparql_statement_execute_async().
- *
- * Returns: (transfer full): A #TrackerSparqlCursor
- */
-
- /**
- * tracker_sparql_statement_execute_async:
- * @self: a #TrackerSparqlStatement
- * @cancellable: a #GCancellable used to cancel the operation
- * @_callback_: user-defined #GAsyncReadyCallback to be called when
- * asynchronous operation is finished.
- * @_user_data_: user-defined data to be passed to @_callback_
- *
- * Asynchronously executes the SPARQL query with the currently bound values.
- */
- public async abstract Cursor execute_async (Cancellable? cancellable) throws Sparql.Error, GLib.Error, GLib.IOError, DBusError;
-}
diff --git a/src/libtracker-sparql/tracker-uri.c b/src/libtracker-sparql/tracker-uri.c
index 0b5c3f349..b97f84527 100644
--- a/src/libtracker-sparql/tracker-uri.c
+++ b/src/libtracker-sparql/tracker-uri.c
@@ -26,6 +26,7 @@
#include <glib.h>
#include "tracker-uri.h"
+#include "tracker-utils.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
@@ -47,15 +48,6 @@ tracker_uri_get_type (void)
return g_define_type_id__volatile;
}
-gchar *
-tracker_sparql_escape_uri_vprintf (const gchar *format,
- va_list args);
-gchar *
-tracker_sparql_escape_uri_printf (const gchar* format,
- ...);
-gchar *
-tracker_sparql_escape_uri (const gchar *uri);
-
static const char *
find_conversion (const char *format,
const char **after)
diff --git a/src/libtracker-sparql/tracker-utils.c b/src/libtracker-sparql/tracker-utils.c
new file mode 100644
index 000000000..e630b689a
--- /dev/null
+++ b/src/libtracker-sparql/tracker-utils.c
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
+ *
+ * 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 "tracker-utils.h"
+
+#include "libtracker-data/tracker-uuid.h"
+
+gchar *
+tracker_sparql_escape_string (const gchar* literal)
+{
+ GString *str;
+ const gchar *p;
+
+ str = g_string_new (NULL);
+ p = literal;
+
+ while (*p != '\0') {
+ size_t len;
+
+ len = strcspn (p, "\t\n\r\b\f\'\"\\");
+ g_string_append_len (str, p, len);
+ p += len;
+
+ switch (*p) {
+ case '\t':
+ g_string_append (str, "\\t");
+ break;
+ case '\n':
+ g_string_append (str, "\\n");
+ break;
+ case '\r':
+ g_string_append (str, "\\r");
+ break;
+ case '\b':
+ g_string_append (str, "\\b");
+ break;
+ case '\f':
+ g_string_append (str, "\\f");
+ break;
+ case '"':
+ g_string_append (str, "\\\"");
+ break;
+ case '\'':
+ g_string_append (str, "\\'");
+ break;
+ case '\\':
+ g_string_append (str, "\\\\");
+ break;
+ default:
+ continue;
+ }
+
+ p++;
+ }
+
+ return g_string_free (str, FALSE);
+}
+
+gchar *
+tracker_sparql_get_uuid_urn (void)
+{
+ return tracker_generate_uuid ("urn:uuid");
+}
diff --git a/src/libtracker-sparql/tracker-utils.h b/src/libtracker-sparql/tracker-utils.h
new file mode 100644
index 000000000..2eee4401b
--- /dev/null
+++ b/src/libtracker-sparql/tracker-utils.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
+ *
+ * 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 __TRACKER_UTILS_H__
+#define __TRACKER_UTILS_H__
+
+#include <glib.h>
+
+gchar * tracker_sparql_escape_uri_vprintf (const gchar *format,
+ va_list args);
+gchar * tracker_sparql_escape_uri_printf (const gchar* format,
+ ...);
+gchar * tracker_sparql_escape_uri (const gchar *uri);
+
+gchar* tracker_sparql_escape_string (const gchar* literal);
+gchar* tracker_sparql_get_uuid_urn (void);
+
+#endif /* __TRACKER_UTILS_H__ */
diff --git a/src/libtracker-sparql/tracker-utils.vala b/src/libtracker-sparql/tracker-utils.vala
deleted file mode 100644
index 2dd2484a0..000000000
--- a/src/libtracker-sparql/tracker-utils.vala
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
- *
- * 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.
- */
-
-namespace Tracker.Sparql {
- /**
- * SECTION: tracker-misc
- * @short_description: General purpose utilities provided by the library
- * @title: Utilities
- * @stability: Stable
- * @include: tracker-sparql.h
- *
- * <para>
- * The libtracker-sparql utilities help in the creation of proper SPARQL queries.
- * </para>
- */
-
- // Imported from tracker-uri.c
- public extern string escape_uri_vprintf (string format, va_list args);
- public extern string escape_uri_printf (string format, ...);
- public extern string escape_uri (string uri);
-
- /**
- * tracker_sparql_escape_string:
- * @literal: a string to escape
- *
- * Escapes a string so that it can be used in a SPARQL query.
- *
- * Returns: a newly-allocated string with the escaped version of @literal.
- * The returned string should be freed with g_free() when no longer needed.
- *
- * Since: 0.10
- */
- public string escape_string (string literal) {
- StringBuilder str = new StringBuilder ();
-
- /* Shouldn't cast from const to non-const here, but we know
- * the compiler is going to complain and it's just because
- * Vala string manipulation doesn't allow us to do this more
- * easily. */
- char *p = (char*) literal;
-
- while (*p != '\0') {
- size_t len = Posix.strcspn ((string) p, "\t\n\r\b\f\'\"\\");
- str.append_len ((string) p, (long) len);
- p += len;
-
- switch (*p) {
- case '\t':
- str.append ("\\t");
- break;
- case '\n':
- str.append ("\\n");
- break;
- case '\r':
- str.append ("\\r");
- break;
- case '\b':
- str.append ("\\b");
- break;
- case '\f':
- str.append ("\\f");
- break;
- case '\'':
- str.append ("\\'");
- break;
- case '"':
- str.append ("\\\"");
- break;
- case '\\':
- str.append ("\\\\");
- break;
- default:
- continue;
- }
-
- p++;
- }
-
- return str.str;
- }
-
- /**
- * tracker_sparql_get_uuid_urn:
- *
- * Generates a unique universal identifier to be used for urns
- * when inserting SPARQL into the database. The string returned is
- * in lower case and has the format "urn:uuid:&percnt;s" where
- * &percnt;s is the uuid generated.
- *
- * Returns: a newly-allocated string. The returned string should
- * be freed with g_free() when no longer needed.
- *
- * Since: 0.10
- */
- public string get_uuid_urn () {
- // generate uuid
- return "urn:uuid:%s".printf (GLib.Uuid.string_random ());
- }
-}