diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2022-07-14 11:42:50 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2022-07-17 15:01:57 +0200 |
commit | dad6b5f08640c1856651e24bb889a49ac49ff8c2 (patch) | |
tree | 93ee4bc424797daf04c622f357fc73d36bb6e724 | |
parent | 25b55abcefa39076f6c794c46f4d6e5aad9aee95 (diff) | |
download | tracker-dad6b5f08640c1856651e24bb889a49ac49ff8c2.tar.gz |
libtracker-sparql: Declare direct connection constructors in C code
We currently have a series of vapi files, just so that the
TrackerSparqlConnection constructors are defined in tracker-backend.vala.
Shuffle this so that we declare the direct connection right at
tracker-connection.c, and avoid/drop all those vapi files.
-rw-r--r-- | src/libtracker-sparql/core/libtracker-data.vapi | 205 | ||||
-rw-r--r-- | src/libtracker-sparql/direct/tracker-direct.c | 47 | ||||
-rw-r--r-- | src/libtracker-sparql/direct/tracker-direct.h | 10 | ||||
-rw-r--r-- | src/libtracker-sparql/direct/tracker-direct.vapi | 10 | ||||
-rw-r--r-- | src/libtracker-sparql/meson.build | 2 | ||||
-rw-r--r-- | src/libtracker-sparql/tracker-backend.vala | 14 | ||||
-rw-r--r-- | src/libtracker-sparql/tracker-connection.c | 186 |
7 files changed, 172 insertions, 302 deletions
diff --git a/src/libtracker-sparql/core/libtracker-data.vapi b/src/libtracker-sparql/core/libtracker-data.vapi deleted file mode 100644 index b520bb92a..000000000 --- a/src/libtracker-sparql/core/libtracker-data.vapi +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (C) 2008-2011, Nokia - * - * 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 { - public enum DB { - UNKNOWN, - COMMON, - CACHE, - METADATA, - CONTENTS - } - - public errordomain DBInterfaceError { - QUERY_ERROR, - CORRUPT, - INTERRUPTED, - OPEN_ERROR, - NO_SPACE - } - - public errordomain DBJournalError { - UNKNOWN, - DAMAGED_JOURNAL_ENTRY, - COULD_NOT_WRITE, - COULD_NOT_CLOSE, - BEGIN_OF_JOURNAL - } - - public enum DBStatementCacheType { - SELECT, - UPDATE, - NONE - } - - public delegate void DBWalCallback (DBInterface iface, int n_pages); - - public interface DBInterface : GLib.Object { - [PrintfFormat] - public DBStatement create_statement (DBStatementCacheType cache_type, ...) throws DBInterfaceError; - [PrintfFormat] - public void execute_query (...) throws DBInterfaceError; - public void sqlite_wal_hook (DBWalCallback callback); - public void sqlite_wal_checkpoint (bool blocking) throws DBInterfaceError; - public unowned GLib.Object get_user_data (); - } - - public delegate void BusyCallback (string status, double progress); - - public enum DBManagerFlags { - FORCE_REINDEX, - REMOVE_ALL, - READONLY, - DO_NOT_CHECK_ONTOLOGY, - ENABLE_MUTEXES, - } - - namespace DBManager { - public void lock (); - public bool trylock (); - public void unlock (); - public bool locale_changed () throws DBInterfaceError; - } - - public class DBCursor : Sparql.Cursor { - } - - public interface DBStatement : GLib.InitiallyUnowned { - public abstract void bind_double (int index, double value); - public abstract void bind_int (int index, int value); - public abstract void bind_text (int index, string value); - public abstract DBCursor start_cursor () throws DBInterfaceError; - public abstract DBCursor start_sparql_cursor (PropertyType[] types, string[] variable_names) throws DBInterfaceError; - } - - public class DBConfig : ConfigFile { - public DBConfig (); - public bool save (); - public int journal_chunk_size { get; set; } - public string journal_rotate_destination { owned get; set; } - } - - namespace DBJournal { - public void set_rotating (bool do_rotating, size_t chunk_size, string? rotate_to); - } - - public class Class : GLib.Object { - public string name { get; set; } - public string uri { get; set; } - public unowned Class[] get_super_classes (); - public void transact_events (); - public bool notify { get; set; } - - public bool has_insert_events (); - public bool has_delete_events (); - public void foreach_delete_event (EventsForeach func); - public void foreach_insert_event (EventsForeach func); - public void reset_ready_events (); - } - - public delegate void EventsForeach (int graph_id, int subject_id, int pred_id, int object_id); - - public class Namespace : GLib.Object { - public string prefix { get; set; } - public string uri { get; set; } - } - - public class Property : GLib.Object { - public string name { get; } - public string table_name { get; } - public string uri { get; set; } - public PropertyType data_type { get; set; } - public Class domain { get; set; } - public Class range { get; set; } - public bool multiple_values { get; set; } - public bool is_inverse_functional_property { get; set; } - public unowned Class[] get_domain_indexes (); - } - - public enum PropertyType { - UNKNOWN, - STRING, - BOOLEAN, - INTEGER, - DOUBLE, - DATE, - DATETIME, - RESOURCE - } - - public class Ontologies : GLib.Object { - public unowned Class get_class_by_uri (string class_uri); - public unowned Property get_property_by_uri (string property_uri); - public unowned Namespace[] get_namespaces (); - public unowned Class[] get_classes (); - public unowned Property[] get_properties (); - } - - public delegate void StatementCallback (int graph_id, string? graph, int subject_id, string subject, int predicate_id, int object_id, string object, GLib.GenericArray<unowned Class> rdf_types); - public delegate void CommitCallback (); - - public class Data.Update : GLib.Object { - public void begin_db_transaction (); - public void commit_db_transaction (); - public void begin_transaction () throws DBInterfaceError; - public void commit_transaction () throws DBInterfaceError; - public void rollback_transaction (); - public void update_sparql (string update) throws Sparql.Error; - public GLib.Variant update_sparql_blank (string update) throws Sparql.Error; - public void load_turtle_file (GLib.File file) throws Sparql.Error; - public void delete_statement (string? graph, string subject, string predicate, GLib.Bytes object) throws Sparql.Error, DateError; - public void update_statement (string? graph, string subject, string predicate, GLib.Bytes? object) throws Sparql.Error, DateError; - public void insert_statement (string? graph, string subject, string predicate, GLib.Bytes object) throws Sparql.Error, DateError; - public void insert_statement_with_uri (string? graph, string subject, string predicate, GLib.Bytes object) throws Sparql.Error; - public void insert_statement_with_string (string? graph, string subject, string predicate, GLib.Bytes object) throws Sparql.Error, DateError; - public void update_buffer_flush () throws DBInterfaceError; - public void update_buffer_might_flush () throws DBInterfaceError; - public void sync (); - - public void add_insert_statement_callback (StatementCallback callback); - public void add_delete_statement_callback (StatementCallback callback); - public void add_commit_statement_callback (CommitCallback callback); - public void add_rollback_statement_callback (CommitCallback callback); - public void remove_insert_statement_callback (StatementCallback callback); - public void remove_delete_statement_callback (StatementCallback callback); - public void remove_commit_statement_callback (CommitCallback callback); - public void remove_rollback_statement_callback (CommitCallback callback); - } - - namespace Data { - public int query_resource_id (Data.Manager manager, DBInterface iface, string uri); - public DBCursor query_sparql_cursor (Data.Manager manager, string query) throws Sparql.Error; - } - - public class Data.Manager : GLib.Object, GLib.Initable { - public Manager (DBManagerFlags flags, GLib.File cache_location, GLib.File data_location, GLib.File ontology_location, bool journal_check, bool restoring_backup, uint select_cache_size, uint update_cache_size); - public unowned Ontologies get_ontologies (); - public unowned DBInterface get_db_interface (); - public unowned DBInterface get_writable_db_interface (); - public unowned Data.Update get_data (); - public void shutdown (); - public GLib.HashTable<string,string> get_namespaces (); - } - - public const string COLLATION_NAME; - - public const string TITLE_COLLATION_NAME; - - public const unichar COLLATION_LAST_CHAR; -} diff --git a/src/libtracker-sparql/direct/tracker-direct.c b/src/libtracker-sparql/direct/tracker-direct.c index 0cef224e0..a8c965520 100644 --- a/src/libtracker-sparql/direct/tracker-direct.c +++ b/src/libtracker-sparql/direct/tracker-direct.c @@ -1544,21 +1544,50 @@ tracker_direct_connection_class_init (TrackerDirectConnectionClass *klass) g_object_class_install_properties (object_class, N_PROPS, props); } -TrackerDirectConnection * +TrackerSparqlConnection * tracker_direct_connection_new (TrackerSparqlConnectionFlags flags, GFile *store, GFile *ontology, GError **error) { - g_return_val_if_fail (!store || G_IS_FILE (store), NULL); - g_return_val_if_fail (!ontology || G_IS_FILE (ontology), NULL); - g_return_val_if_fail (!error || !*error, NULL); + return g_initable_new (TRACKER_TYPE_DIRECT_CONNECTION, + NULL, error, + "flags", flags, + "store-location", store, + "ontology-location", ontology, + NULL); +} - return g_object_new (TRACKER_TYPE_DIRECT_CONNECTION, - "flags", flags, - "store-location", store, - "ontology-location", ontology, - NULL); +void +tracker_direct_connection_new_async (TrackerSparqlConnectionFlags flags, + GFile *store, + GFile *ontology, + GCancellable *cancellable, + GAsyncReadyCallback cb, + gpointer user_data) +{ + g_async_initable_new_async (TRACKER_TYPE_DIRECT_CONNECTION, + G_PRIORITY_DEFAULT, + cancellable, + cb, + user_data, + "flags", flags, + "store-location", store, + "ontology-location", ontology, + NULL); +} + +TrackerSparqlConnection * +tracker_direct_connection_new_finish (GAsyncResult *res, + GError **error) +{ + GAsyncInitable *initable; + + initable = g_task_get_source_object (G_TASK (res)); + + return TRACKER_SPARQL_CONNECTION (g_async_initable_new_finish (initable, + res, + error)); } TrackerDataManager * diff --git a/src/libtracker-sparql/direct/tracker-direct.h b/src/libtracker-sparql/direct/tracker-direct.h index b9d443c37..8b8da5780 100644 --- a/src/libtracker-sparql/direct/tracker-direct.h +++ b/src/libtracker-sparql/direct/tracker-direct.h @@ -48,10 +48,18 @@ struct _TrackerDirectConnection GType tracker_direct_connection_get_type (void) G_GNUC_CONST; -TrackerDirectConnection *tracker_direct_connection_new (TrackerSparqlConnectionFlags flags, +TrackerSparqlConnection *tracker_direct_connection_new (TrackerSparqlConnectionFlags flags, GFile *store, GFile *ontology, GError **error); +void tracker_direct_connection_new_async (TrackerSparqlConnectionFlags flags, + GFile *store, + GFile *ontology, + GCancellable *cancellable, + GAsyncReadyCallback cb, + gpointer user_data); +TrackerSparqlConnection * tracker_direct_connection_new_finish (GAsyncResult *res, + GError **error); TrackerDataManager *tracker_direct_connection_get_data_manager (TrackerDirectConnection *conn); diff --git a/src/libtracker-sparql/direct/tracker-direct.vapi b/src/libtracker-sparql/direct/tracker-direct.vapi deleted file mode 100644 index 3f8b7c938..000000000 --- a/src/libtracker-sparql/direct/tracker-direct.vapi +++ /dev/null @@ -1,10 +0,0 @@ -[CCode (cprefix = "Tracker", gir_namespace = "Tracker", gir_version = "2.0", lower_case_cprefix = "tracker_")] -namespace Tracker { - namespace Direct { - [CCode (cheader_filename = "direct/tracker-direct.h")] - public class Connection : Tracker.Sparql.Connection, GLib.Initable, GLib.AsyncInitable { - public Connection (Tracker.Sparql.ConnectionFlags connection_flags, GLib.File loc, GLib.File? ontology) throws Tracker.Sparql.Error, GLib.IOError, GLib.DBusError; - public unowned Tracker.Data.Manager get_data_manager (); - } - } -} diff --git a/src/libtracker-sparql/meson.build b/src/libtracker-sparql/meson.build index 176c94f69..ce3dedb0f 100644 --- a/src/libtracker-sparql/meson.build +++ b/src/libtracker-sparql/meson.build @@ -106,8 +106,6 @@ libtracker_sparql_private = static_library('tracker-sparql-private', direct_files, remote_files, '../libtracker-common/libtracker-common.vapi', - 'core/libtracker-data.vapi', - 'direct/tracker-direct.vapi', 'tracker-backend.vala', tracker_gresources, diff --git a/src/libtracker-sparql/tracker-backend.vala b/src/libtracker-sparql/tracker-backend.vala index af1102d5a..1657ab25e 100644 --- a/src/libtracker-sparql/tracker-backend.vala +++ b/src/libtracker-sparql/tracker-backend.vala @@ -68,17 +68,3 @@ public static async Tracker.Sparql.Connection tracker_sparql_connection_bus_new_ return yield new Tracker.Bus.Connection (service, path, dbus_conn, cancellable); } - -public static Tracker.Sparql.Connection tracker_sparql_connection_new (Tracker.Sparql.ConnectionFlags flags, File? store, File? ontology, Cancellable? cancellable = null) throws GLib.Error, Tracker.Sparql.Error, IOError { - Tracker.get_debug_flags (); - var conn = new Tracker.Direct.Connection (flags, store, ontology); - conn.init (cancellable); - return conn; -} - -public static async Tracker.Sparql.Connection tracker_sparql_connection_new_async (Tracker.Sparql.ConnectionFlags flags, File? store, File ontology, Cancellable? cancellable = null) throws GLib.Error, Tracker.Sparql.Error, IOError { - Tracker.get_debug_flags (); - var conn = new Tracker.Direct.Connection (flags, store, ontology); - yield conn.init_async (Priority.DEFAULT, cancellable); - return conn; -} diff --git a/src/libtracker-sparql/tracker-connection.c b/src/libtracker-sparql/tracker-connection.c index 398d9ae52..db9c02371 100644 --- a/src/libtracker-sparql/tracker-connection.c +++ b/src/libtracker-sparql/tracker-connection.c @@ -62,6 +62,7 @@ #include "tracker-private.h" #include "tracker-debug.h" +#include "direct/tracker-direct.h" #include "remote/tracker-remote.h" G_DEFINE_ABSTRACT_TYPE (TrackerSparqlConnection, tracker_sparql_connection, @@ -118,67 +119,6 @@ tracker_sparql_connection_lookup_dbus_service (TrackerSparqlConnection *connect * documented here. */ /** - * tracker_sparql_connection_new: - * @flags: values from #TrackerSparqlConnectionFlags - * @store: (nullable): the directory that contains the database as a #GFile, or %NULL - * @ontology: (nullable): the directory that contains the database schemas as a #GFile, or %NULL - * @cancellable: (nullable): a #GCancellable, or %NULL - * @error: pointer to a #GError - * - * Creates or opens a database. - * - * This method should only be used for databases owned by the current process. - * To connect to databases managed by other processes, use - * tracker_sparql_connection_bus_new(). - * - * If @store is %NULL, the database will be created in memory. - * - * The @ontologies parameter must point to a location containing suitable - * `.ontology` files in Turtle format. These control the database schema that - * is used. You can use the default Nepomuk ontologies by calling - * tracker_sparql_get_ontology_nepomuk (). - * - * If you open an existing database using a different @ontology to the one it - * was created with, Tracker will attempt to migrate the existing data to the - * new schema. This may raise an error. In particular, not all migrations are - * possible without causing data loss and Tracker will refuse to delete data - * during a migration. - * - * You can also pass %NULL for @ontologies to mean "use the ontologies that the - * database was created with". This will fail if the database doesn't already - * exist. - * - * Returns: (transfer full): a new #TrackerSparqlConnection. Call - * g_object_unref() on the object when no longer used. - * - * Since: 3.0 - */ - -/** - * tracker_sparql_connection_new_async: - * @flags: values from #TrackerSparqlConnectionFlags - * @store: (nullable): the directory that contains the database as a #GFile, or %NULL - * @ontology: (nullable): the directory that contains the database schemas as a #GFile, or %NULL - * @cancellable: (nullable): a #GCancellable, or %NULL - * @callback: the #GAsyncReadyCallback called when the operation completes - * @user_data: data passed to @callback - * - * Asynchronous version of tracker_sparql_connection_new(). - * - * Since: 3.0 - */ - -/** - * tracker_sparql_connection_new_finish: - * @result: the #GAsyncResult - * @error: pointer to a #GError - * - * Completion function for tracker_sparql_connection_new_async(). - * - * Since: 3.0 - */ - -/** * tracker_sparql_connection_bus_new: * @service_name: The name of the D-Bus service to connect to. * @object_path: (nullable): The path to the object, or %NULL to use the default. @@ -1079,3 +1019,127 @@ tracker_sparql_connection_remote_new (const gchar *uri_base) { return TRACKER_SPARQL_CONNECTION (tracker_remote_connection_new (uri_base)); } + +/** + * tracker_sparql_connection_new: + * @flags: values from #TrackerSparqlConnectionFlags + * @store: (nullable): the directory that contains the database as a #GFile, or %NULL + * @ontology: (nullable): the directory that contains the database schemas as a #GFile, or %NULL + * @cancellable: (nullable): a #GCancellable, or %NULL + * @error: pointer to a #GError + * + * Creates or opens a database. + * + * This method should only be used for databases owned by the current process. + * To connect to databases managed by other processes, use + * tracker_sparql_connection_bus_new(). + * + * If @store is %NULL, the database will be created in memory. + * + * The @ontologies parameter must point to a location containing suitable + * `.ontology` files in Turtle format. These control the database schema that + * is used. You can use the default Nepomuk ontologies by calling + * tracker_sparql_get_ontology_nepomuk (). + * + * If you open an existing database using a different @ontology to the one it + * was created with, Tracker will attempt to migrate the existing data to the + * new schema. This may raise an error. In particular, not all migrations are + * possible without causing data loss and Tracker will refuse to delete data + * during a migration. + * + * You can also pass %NULL for @ontologies to mean "use the ontologies that the + * database was created with". This will fail if the database doesn't already + * exist. + * + * Returns: (transfer full): a new #TrackerSparqlConnection. Call + * g_object_unref() on the object when no longer used. + * + * Since: 3.0 + */ +TrackerSparqlConnection * +tracker_sparql_connection_new (TrackerSparqlConnectionFlags flags, + GFile *store, + GFile *ontology, + GCancellable *cancellable, + GError **error) +{ + g_return_val_if_fail (!store || G_IS_FILE (store), NULL); + g_return_val_if_fail (!ontology || G_IS_FILE (ontology), NULL); + g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL); + g_return_val_if_fail (!error || !*error, NULL); + + return tracker_direct_connection_new (flags, store, ontology, error); +} + +static void +new_async_cb (GObject *source, + GAsyncResult *res, + gpointer user_data) +{ + TrackerSparqlConnection *conn; + GTask *task = user_data; + GError *error = NULL; + + conn = tracker_direct_connection_new_finish (res, &error); + + if (conn) + g_task_return_pointer (task, conn, g_object_unref); + else + g_task_return_error (task, error); +} + +/** + * tracker_sparql_connection_new_async: + * @flags: values from #TrackerSparqlConnectionFlags + * @store: (nullable): the directory that contains the database as a #GFile, or %NULL + * @ontology: (nullable): the directory that contains the database schemas as a #GFile, or %NULL + * @cancellable: (nullable): a #GCancellable, or %NULL + * @callback: the #GAsyncReadyCallback called when the operation completes + * @user_data: data passed to @callback + * + * Asynchronous version of tracker_sparql_connection_new(). + * + * Since: 3.0 + */ + +void +tracker_sparql_connection_new_async (TrackerSparqlConnectionFlags flags, + GFile *store, + GFile *ontology, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + + g_return_if_fail (!store || G_IS_FILE (store)); + g_return_if_fail (!ontology || G_IS_FILE (ontology)); + g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); + + task = g_task_new (NULL, cancellable, callback, user_data); + g_task_set_source_tag (task, tracker_sparql_connection_new_async); + + tracker_direct_connection_new_async (flags, store, ontology, cancellable, + new_async_cb, task); +} + +/** + * tracker_sparql_connection_new_finish: + * @result: the #GAsyncResult + * @error: pointer to a #GError + * + * Completion function for tracker_sparql_connection_new_async(). + * + * Since: 3.0 + */ +TrackerSparqlConnection * +tracker_sparql_connection_new_finish (GAsyncResult *res, + GError **error) +{ + g_return_val_if_fail (G_IS_TASK (res), NULL); + g_return_val_if_fail (g_task_get_source_tag (G_TASK (res)) == + tracker_sparql_connection_new_async, + NULL); + + return g_task_propagate_pointer (G_TASK (res), error); +} |