[tracker/wip/carlosg/domain-ontologies: 89/116] libtracker-sparql: Use TrackerDomainOntology on tracker_sparql_connection_get()



commit 97559a5ae9e685de77db1b5668b79809a3499f6b
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Jun 19 20:05:53 2017 +0200

    libtracker-sparql: Use TrackerDomainOntology on tracker_sparql_connection_get()
    
    Add a global tracker_sparql_connection_set_domain() call that allows setting
    domain ontology that the client shall use. This only affects the connection
    obtained through tracker_sparql_connection_get(), other constructors may have
    different settings.

 src/libtracker-bus/tracker-bus.vala                |   18 ++++++++------
 src/libtracker-sparql-backend/Makefile.am          |    3 +-
 src/libtracker-sparql-backend/meson.build          |    7 ++++-
 src/libtracker-sparql-backend/tracker-backend.vala |   25 ++++++++++++++++----
 src/libtracker-sparql/tracker-connection.vala      |   12 ++++++---
 tests/functional-tests/ipc/test-bus-query.vala     |    2 +-
 tests/functional-tests/ipc/test-bus-update.vala    |    2 +-
 7 files changed, 47 insertions(+), 22 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-bus.vala b/src/libtracker-bus/tracker-bus.vala
index d254dd5..4ba3eed 100644
--- a/src/libtracker-bus/tracker-bus.vala
+++ b/src/libtracker-bus/tracker-bus.vala
@@ -19,15 +19,17 @@
 
 public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
        DBusConnection bus;
+       string dbus_name;
 
-       public Connection () throws Sparql.Error, IOError, DBusError, GLib.Error {
+       public Connection (string dbus_name) throws Sparql.Error, IOError, DBusError, GLib.Error {
+               this.dbus_name = dbus_name;
                bus = GLib.Bus.get_sync (Tracker.IPC.bus ());
 
                debug ("Waiting for service to become available...");
 
                // do not use proxy to work around race condition in GDBus
                // NB#259760
-               var msg = new DBusMessage.method_call (Tracker.DBUS_SERVICE, Tracker.DBUS_OBJECT_STATUS, 
Tracker.DBUS_INTERFACE_STATUS, "Wait");
+               var msg = new DBusMessage.method_call (dbus_name, Tracker.DBUS_OBJECT_STATUS, 
Tracker.DBUS_INTERFACE_STATUS, "Wait");
                bus.send_message_with_reply_sync (msg, 0, /* timeout */ int.MAX, null).to_gerror ();
 
                debug ("Service is ready");
@@ -60,7 +62,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
        }
 
        void send_query (string sparql, UnixOutputStream output, Cancellable? cancellable, 
AsyncReadyCallback? callback) throws GLib.IOError, GLib.Error {
-               var message = new DBusMessage.method_call (Tracker.DBUS_SERVICE, 
Tracker.DBUS_OBJECT_STEROIDS, Tracker.DBUS_INTERFACE_STEROIDS, "Query");
+               var message = new DBusMessage.method_call (dbus_name, Tracker.DBUS_OBJECT_STEROIDS, 
Tracker.DBUS_INTERFACE_STEROIDS, "Query");
                var fd_list = new UnixFDList ();
                message.set_body (new Variant ("(sh)", sparql, fd_list.append (output.fd)));
                message.set_unix_fd_list (fd_list);
@@ -122,7 +124,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
        }
 
        void send_update (string method, UnixInputStream input, Cancellable? cancellable, AsyncReadyCallback? 
callback) throws GLib.Error, GLib.IOError {
-               var message = new DBusMessage.method_call (Tracker.DBUS_SERVICE, 
Tracker.DBUS_OBJECT_STEROIDS, Tracker.DBUS_INTERFACE_STEROIDS, method);
+               var message = new DBusMessage.method_call (dbus_name, Tracker.DBUS_OBJECT_STEROIDS, 
Tracker.DBUS_INTERFACE_STEROIDS, method);
                var fd_list = new UnixFDList ();
                message.set_body (new Variant ("(h)", fd_list.append (input.fd)));
                message.set_unix_fd_list (fd_list);
@@ -282,7 +284,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
        }
 
        public override void load (File file, Cancellable? cancellable = null) throws Sparql.Error, IOError, 
DBusError {
-               var message = new DBusMessage.method_call (Tracker.DBUS_SERVICE, 
Tracker.DBUS_OBJECT_RESOURCES, Tracker.DBUS_INTERFACE_RESOURCES, "Load");
+               var message = new DBusMessage.method_call (dbus_name, Tracker.DBUS_OBJECT_RESOURCES, 
Tracker.DBUS_INTERFACE_RESOURCES, "Load");
                message.set_body (new Variant ("(s)", file.get_uri ()));
 
                var reply = bus.send_message_with_reply_sync (message, DBusSendMessageFlags.NONE, int.MAX, 
null, cancellable);
@@ -290,7 +292,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
        }
 
        public async override void load_async (File file, Cancellable? cancellable = null) throws 
Sparql.Error, IOError, DBusError {
-               var message = new DBusMessage.method_call (Tracker.DBUS_SERVICE, 
Tracker.DBUS_OBJECT_RESOURCES, Tracker.DBUS_INTERFACE_RESOURCES, "Load");
+               var message = new DBusMessage.method_call (dbus_name, Tracker.DBUS_OBJECT_RESOURCES, 
Tracker.DBUS_INTERFACE_RESOURCES, "Load");
                message.set_body (new Variant ("(s)", file.get_uri ()));
 
                var reply = yield bus.send_message_with_reply (message, DBusSendMessageFlags.NONE, int.MAX, 
null, cancellable);
@@ -298,7 +300,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
        }
 
        public override Sparql.Cursor? statistics (Cancellable? cancellable = null) throws Sparql.Error, 
IOError, DBusError {
-               var message = new DBusMessage.method_call (Tracker.DBUS_SERVICE, 
Tracker.DBUS_OBJECT_STATISTICS, Tracker.DBUS_INTERFACE_STATISTICS, "Get");
+               var message = new DBusMessage.method_call (dbus_name, Tracker.DBUS_OBJECT_STATISTICS, 
Tracker.DBUS_INTERFACE_STATISTICS, "Get");
 
                var reply = bus.send_message_with_reply_sync (message, DBusSendMessageFlags.NONE, int.MAX, 
null, cancellable);
                handle_error_reply (reply);
@@ -322,7 +324,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
        }
 
        public async override Sparql.Cursor? statistics_async (Cancellable? cancellable = null) throws 
Sparql.Error, IOError, DBusError {
-               var message = new DBusMessage.method_call (Tracker.DBUS_SERVICE, 
Tracker.DBUS_OBJECT_STATISTICS, Tracker.DBUS_INTERFACE_STATISTICS, "Get");
+               var message = new DBusMessage.method_call (dbus_name, Tracker.DBUS_OBJECT_STATISTICS, 
Tracker.DBUS_INTERFACE_STATISTICS, "Get");
 
                var reply = yield bus.send_message_with_reply (message, DBusSendMessageFlags.NONE, int.MAX, 
null, cancellable);
                handle_error_reply (reply);
diff --git a/src/libtracker-sparql-backend/Makefile.am b/src/libtracker-sparql-backend/Makefile.am
index 3b5165d..756c634 100644
--- a/src/libtracker-sparql-backend/Makefile.am
+++ b/src/libtracker-sparql-backend/Makefile.am
@@ -6,7 +6,8 @@ AM_VALAFLAGS =                                         \
        $(top_srcdir)/src/libtracker-sparql/tracker-sparql-$(TRACKER_API_VERSION).vapi \
        $(top_srcdir)/src/libtracker-bus/tracker-bus.vapi \
        $(top_srcdir)/src/libtracker-direct/tracker-direct.vapi \
-       $(top_srcdir)/src/libtracker-remote/tracker-remote.vapi
+       $(top_srcdir)/src/libtracker-remote/tracker-remote.vapi \
+       $(top_srcdir)/src/libtracker-common/libtracker-common.vapi
 
 AM_CPPFLAGS =                                          \
        $(BUILD_VALACFLAGS)                            \
diff --git a/src/libtracker-sparql-backend/meson.build b/src/libtracker-sparql-backend/meson.build
index b183096..b99dc33 100644
--- a/src/libtracker-sparql-backend/meson.build
+++ b/src/libtracker-sparql-backend/meson.build
@@ -1,5 +1,7 @@
 libtracker_sparql = library('tracker-sparql-' + tracker_api_version,
     'tracker-backend.vala',
+    '../libtracker-common/libtracker-common.vapi',
+    c_args: ['-DTRACKER_COMPILATION'],
     install: true,
     install_rpath: tracker_internal_libs_dir,
     c_args: tracker_c_args,
@@ -7,7 +9,8 @@ libtracker_sparql = library('tracker-sparql-' + tracker_api_version,
 )
 
 tracker_sparql_dep = declare_dependency(
-    link_with: [libtracker_sparql],
+    link_with: [libtracker_sparql, libtracker_common],
+    include_directories: srcinc,
+    dependencies: [tracker_sparql_intermediate_dep, tracker_common_dep],
     include_directories: srcinc,
-    dependencies: [tracker_sparql_intermediate_dep],
 )
diff --git a/src/libtracker-sparql-backend/tracker-backend.vala 
b/src/libtracker-sparql-backend/tracker-backend.vala
index 041491d..4f59d00 100644
--- a/src/libtracker-sparql-backend/tracker-backend.vala
+++ b/src/libtracker-sparql-backend/tracker-backend.vala
@@ -17,6 +17,9 @@
  * Boston, MA  02110-1301, USA.
  */
 
+static string domain_name = null;
+static Tracker.DomainOntology domain_ontology = null;
+
 class Tracker.Sparql.Backend : Connection {
        bool initialized;
        Tracker.Sparql.Connection direct = null;
@@ -29,9 +32,10 @@ class Tracker.Sparql.Backend : Connection {
 
        public Backend () throws Sparql.Error, IOError, DBusError, SpawnError {
                try {
+                       domain_ontology = new Tracker.DomainOntology (domain_name, null);
                        load_plugins ();
                } catch (GLib.Error e) {
-                       throw new Sparql.Error.INTERNAL (e.message);
+                       throw new Sparql.Error.INTERNAL ("Failed to load SPARQL backend: " + e.message);
                }
 
                initialized = true;
@@ -150,8 +154,10 @@ class Tracker.Sparql.Backend : Connection {
        }
 
        private Connection create_readonly_direct () throws GLib.Error, Sparql.Error, IOError, DBusError {
-               File store = File.new_for_path (Path.build_filename (Environment.get_user_cache_dir(), 
"tracker"));
-               var conn = new Tracker.Direct.Connection (Tracker.Sparql.ConnectionFlags.READONLY, store, 
null, null);
+               var conn = new Tracker.Direct.Connection (Tracker.Sparql.ConnectionFlags.READONLY,
+                                                         domain_ontology.get_cache (),
+                                                         domain_ontology.get_journal (),
+                                                         domain_ontology.get_ontology ());
                conn.init ();
                return conn;
        }
@@ -185,7 +191,7 @@ class Tracker.Sparql.Backend : Connection {
                                warning ("Falling back to bus backend, the direct backend failed to 
initialize: " + e.message);
                        }
 
-                       bus = new Tracker.Bus.Connection ();
+                       bus = new Tracker.Bus.Connection (domain_ontology.get_domain ());
                        break;
 
                case Backend.DIRECT:
@@ -193,7 +199,7 @@ class Tracker.Sparql.Backend : Connection {
                        break;
 
                case Backend.BUS:
-                       bus = new Tracker.Bus.Connection ();
+                       bus = new Tracker.Bus.Connection (domain_ontology.get_domain ());
                        break;
 
                default:
@@ -343,3 +349,12 @@ public static async Tracker.Sparql.Connection tracker_sparql_connection_local_ne
        yield;
        return conn;
 }
+
+public static void tracker_sparql_connection_set_domain (string? domain) {
+       if (domain_name == null)
+               domain_name = domain;
+}
+
+public static string? tracker_sparql_connection_get_domain () {
+       return domain_name;
+}
diff --git a/src/libtracker-sparql/tracker-connection.vala b/src/libtracker-sparql/tracker-connection.vala
index d3565fd..bb87add 100644
--- a/src/libtracker-sparql/tracker-connection.vala
+++ b/src/libtracker-sparql/tracker-connection.vala
@@ -33,13 +33,13 @@
 // Convenience, hidden in the documentation
 namespace Tracker {
        public const string DBUS_SERVICE = "org.freedesktop.Tracker1";
-       public const string DBUS_INTERFACE_RESOURCES = DBUS_SERVICE + ".Resources";
+       public const string DBUS_INTERFACE_RESOURCES = "org.freedesktop.Tracker1.Resources";
        public const string DBUS_OBJECT_RESOURCES = "/org/freedesktop/Tracker1/Resources";
-       public const string DBUS_INTERFACE_STATISTICS = DBUS_SERVICE + ".Statistics";
+       public const string DBUS_INTERFACE_STATISTICS = "org.freedesktop.Tracker1.Statistics";
        public const string DBUS_OBJECT_STATISTICS = "/org/freedesktop/Tracker1/Statistics";
-       public const string DBUS_INTERFACE_STATUS = DBUS_SERVICE + ".Status";
+       public const string DBUS_INTERFACE_STATUS = "org.freedesktop.Tracker1.Status";
        public const string DBUS_OBJECT_STATUS = "/org/freedesktop/Tracker1/Status";
-       public const string DBUS_INTERFACE_STEROIDS = DBUS_SERVICE + ".Steroids";
+       public const string DBUS_INTERFACE_STEROIDS = "org.freedesktop.Tracker1.Steroids";
        public const string DBUS_OBJECT_STEROIDS = "/org/freedesktop/Tracker1/Steroids";
 }
 
@@ -569,4 +569,8 @@ public abstract class Tracker.Sparql.Connection : Object {
                warning ("Interface 'statistics_async' not implemented");
                return null;
        }
+
+       public extern static void set_domain (string? domain);
+       public extern static string? get_domain ();
 }
+
diff --git a/tests/functional-tests/ipc/test-bus-query.vala b/tests/functional-tests/ipc/test-bus-query.vala
index d8a198e..b818a5f 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 ());
+               TestApp app = new TestApp (new  Tracker.Bus.Connection ("org.freedesktop.Tracker1"));
 
                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 d8a198e..b818a5f 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 ());
+               TestApp app = new TestApp (new  Tracker.Bus.Connection ("org.freedesktop.Tracker1"));
 
                return app.run ();
        } catch (GLib.Error e) {


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