[tracker/wip/carlosg/rewrite-bus-impl: 1/5] libtracker-sparql: Declare direct connection constructors in C code




commit dad6b5f08640c1856651e24bb889a49ac49ff8c2
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jul 14 11:42:50 2022 +0200

    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.

 src/libtracker-sparql/core/libtracker-data.vapi  | 205 -----------------------
 src/libtracker-sparql/direct/tracker-direct.c    |  47 +++++-
 src/libtracker-sparql/direct/tracker-direct.h    |  10 +-
 src/libtracker-sparql/direct/tracker-direct.vapi |  10 --
 src/libtracker-sparql/meson.build                |   2 -
 src/libtracker-sparql/tracker-backend.vala       |  14 --
 src/libtracker-sparql/tracker-connection.c       | 186 +++++++++++++-------
 7 files changed, 172 insertions(+), 302 deletions(-)
---
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/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,
@@ -117,67 +118,6 @@ tracker_sparql_connection_lookup_dbus_service (TrackerSparqlConnection  *connect
 /* The constructor functions are defined in the libtracker-sparql-backend, but
  * 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.
@@ -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);
+}


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