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



commit 145cadd0f305438de247bf370289feb5ef4e127c
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/tracker-backend.vala |   20 +++++++++++++++-----
 src/libtracker-sparql/tracker-connection.vala      |   11 +++++++----
 4 files changed, 34 insertions(+), 18 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-bus.vala b/src/libtracker-bus/tracker-bus.vala
index 544c221..2618476 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 {
+       public Connection (string dbus_name) throws Sparql.Error, IOError, DBusError {
+               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/tracker-backend.vala 
b/src/libtracker-sparql-backend/tracker-backend.vala
index 041491d..99048ec 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,7 @@ public static async Tracker.Sparql.Connection tracker_sparql_connection_local_ne
        yield;
        return conn;
 }
+
+public static void tracker_sparql_connection_set_domain (string? domain) {
+       domain_name = domain;
+}
diff --git a/src/libtracker-sparql/tracker-connection.vala b/src/libtracker-sparql/tracker-connection.vala
index d3565fd..c8517b3 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,7 @@ public abstract class Tracker.Sparql.Connection : Object {
                warning ("Interface 'statistics_async' not implemented");
                return null;
        }
+
+       public extern static void set_domain (string? domain);
 }
+


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