[tracker] Revert "Revert "Add tracker_sparql_connection_get/set_dbus_connection()""



commit d73f8b4aa3391feaf6645e8d138b0be531771441
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Sep 9 22:44:42 2018 +0200

    Revert "Revert "Add tracker_sparql_connection_get/set_dbus_connection()""
    
    This reverts commit df768eff07c817924f431ece0d09a24edab74de2.
    
    Now that we branched for tracker-2.2, reintroduce this new API.

 src/libtracker-bus/tracker-bus.vala                |  8 ++++--
 src/libtracker-sparql-backend/tracker-backend.vala | 13 ++++++++--
 src/libtracker-sparql/tracker-connection.vala      | 29 ++++++++++++++++++++++
 src/libtracker-sparql/tracker-notifier.c           |  4 ++-
 tests/functional-tests/ipc/test-bus-query.vala     |  2 +-
 tests/functional-tests/ipc/test-bus-update.vala    |  2 +-
 6 files changed, 51 insertions(+), 7 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-bus.vala b/src/libtracker-bus/tracker-bus.vala
index 4ba3eedb4..3b971d030 100644
--- a/src/libtracker-bus/tracker-bus.vala
+++ b/src/libtracker-bus/tracker-bus.vala
@@ -21,9 +21,13 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
        DBusConnection bus;
        string dbus_name;
 
-       public Connection (string dbus_name) throws Sparql.Error, IOError, DBusError, GLib.Error {
+       public Connection (string dbus_name, DBusConnection? dbus_connection) throws Sparql.Error, IOError, 
DBusError, GLib.Error {
                this.dbus_name = dbus_name;
-               bus = GLib.Bus.get_sync (Tracker.IPC.bus ());
+
+               if (dbus_connection == null)
+                       bus = GLib.Bus.get_sync (Tracker.IPC.bus ());
+               else
+                       bus = dbus_connection;
 
                debug ("Waiting for service to become available...");
 
diff --git a/src/libtracker-sparql-backend/tracker-backend.vala 
b/src/libtracker-sparql-backend/tracker-backend.vala
index e46725ff5..7768d5f07 100644
--- a/src/libtracker-sparql-backend/tracker-backend.vala
+++ b/src/libtracker-sparql-backend/tracker-backend.vala
@@ -19,6 +19,7 @@
 
 static string domain_name = null;
 static Tracker.DomainOntology domain_ontology = null;
+static DBusConnection global_dbus_connection = null;
 
 class Tracker.Sparql.Backend : Connection {
        bool initialized;
@@ -192,7 +193,7 @@ class Tracker.Sparql.Backend : Connection {
 
                switch (backend) {
                case Backend.AUTO:
-                       bus = new Tracker.Bus.Connection (domain_ontology.get_domain ("Tracker1"));
+                       bus = new Tracker.Bus.Connection (domain_ontology.get_domain ("Tracker1"), 
global_dbus_connection);
 
                        try {
                                direct = create_readonly_direct ();
@@ -207,7 +208,7 @@ class Tracker.Sparql.Backend : Connection {
                        break;
 
                case Backend.BUS:
-                       bus = new Tracker.Bus.Connection (domain_ontology.get_domain ("Tracker1"));
+                       bus = new Tracker.Bus.Connection (domain_ontology.get_domain ("Tracker1"), 
global_dbus_connection);
                        break;
 
                default:
@@ -358,3 +359,11 @@ public static void tracker_sparql_connection_set_domain (string? domain) {
 public static string? tracker_sparql_connection_get_domain () {
        return domain_name;
 }
+
+public static void tracker_sparql_connection_set_dbus_connection (DBusConnection dbus_connection) {
+       global_dbus_connection = dbus_connection;
+}
+
+public static DBusConnection? tracker_sparql_connection_get_dbus_connection () {
+       return global_dbus_connection;
+}
diff --git a/src/libtracker-sparql/tracker-connection.vala b/src/libtracker-sparql/tracker-connection.vala
index 412f7e88f..a949ea26a 100644
--- a/src/libtracker-sparql/tracker-connection.vala
+++ b/src/libtracker-sparql/tracker-connection.vala
@@ -606,4 +606,33 @@ public abstract class Tracker.Sparql.Connection : Object {
         * Since: 2.0
         */
        public extern static string? get_domain ();
+
+       /**
+        * tracker_sparql_connection_set_dbus_connection:
+        * @dbus_connection: A #GDBusConnection to a suitable message bus.
+        *
+        * By default, a connection is opened to the session-wide Tracker services
+        * running on the D-Bus session bus. This function allows you to connect to
+        * Tracker services that are running on a different bus.
+        *
+        * This function must be called before any tracker_sparql_connection_get()
+        * calls happen.
+        *
+        * See also: the TRACKER_IPC_BUS environment variable.
+        *
+        * Since: 2.2
+        */
+       public extern static void set_dbus_connection (DBusConnection dbus_connection);
+
+       /**
+        * tracker_sparql_connection_get_dbus_connection:
+        *
+        * Gets the D-Bus connection that is used to contact the Tracker services.
+        *
+        * Returns: (transfer none): A #GDBusConnection instance, or %NULL if the
+        *                           default is being used.
+        *
+        * Since: 2.0
+        */
+       public extern static DBusConnection? get_dbus_connection ();
 }
diff --git a/src/libtracker-sparql/tracker-notifier.c b/src/libtracker-sparql/tracker-notifier.c
index d0cf748b3..4f7647d24 100644
--- a/src/libtracker-sparql/tracker-notifier.c
+++ b/src/libtracker-sparql/tracker-notifier.c
@@ -704,7 +704,9 @@ tracker_notifier_initable_init (GInitable     *initable,
        tracker_notifier_cache_id (notifier, "nie:dataSource");
        tracker_notifier_cache_id (notifier, "tracker:extractor-data-source");
 
-       priv->dbus_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, cancellable, error);
+       priv->dbus_connection = tracker_sparql_connection_get_dbus_connection ();
+       if (!priv->dbus_connection)
+               priv->dbus_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, cancellable, error);
        if (!priv->dbus_connection)
                return FALSE;
 
diff --git a/tests/functional-tests/ipc/test-bus-query.vala b/tests/functional-tests/ipc/test-bus-query.vala
index b818a5f02..997dc9e7c 100644
--- a/tests/functional-tests/ipc/test-bus-query.vala
+++ b/tests/functional-tests/ipc/test-bus-query.vala
@@ -5,7 +5,7 @@ int
 main( string[] args )
 {
        try {
-               TestApp app = new TestApp (new  Tracker.Bus.Connection ("org.freedesktop.Tracker1"));
+               TestApp app = new TestApp (new  Tracker.Bus.Connection ("org.freedesktop.Tracker1", null));
 
                return app.run ();
        } catch (GLib.Error e) {
diff --git a/tests/functional-tests/ipc/test-bus-update.vala b/tests/functional-tests/ipc/test-bus-update.vala
index b818a5f02..997dc9e7c 100644
--- a/tests/functional-tests/ipc/test-bus-update.vala
+++ b/tests/functional-tests/ipc/test-bus-update.vala
@@ -5,7 +5,7 @@ int
 main( string[] args )
 {
        try {
-               TestApp app = new TestApp (new  Tracker.Bus.Connection ("org.freedesktop.Tracker1"));
+               TestApp app = new TestApp (new  Tracker.Bus.Connection ("org.freedesktop.Tracker1", null));
 
                return app.run ();
        } catch (GLib.Error e) {


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