Commit 034e7a2e authored by Sam Thursfield's avatar Sam Thursfield

Merge branch 'sam/tracker-sparql-connection-set-dbus-connection'

See !14
parents 4d559447 eb24ea93
......@@ -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...");
......
......@@ -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 ());
bus = new Tracker.Bus.Connection (domain_ontology.get_domain (), 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 ());
bus = new Tracker.Bus.Connection (domain_ontology.get_domain (), 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;
}
......@@ -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 ();
}
......@@ -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;
......
......@@ -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) {
......
......@@ -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) {
......
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