Commit 4c79fd09 authored by Carlos Garnacho's avatar Carlos Garnacho

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.
parent 2ff67ce5
......@@ -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);
......
......@@ -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) \
......
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,
link_whole: libtracker_sparql_intermediate_c,
......@@ -7,9 +9,10 @@ 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],
)
# The introspection generation for libtracker-sparql is awkward because we have
......
......@@ -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;
}
......@@ -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);
public extern static string? get_domain ();
}
......@@ -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) {
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment