[tracker/sam/app-domains: 1/2] Add tracker_sparql_connection_get/set_dbus_connection()
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/sam/app-domains: 1/2] Add tracker_sparql_connection_get/set_dbus_connection()
- Date: Sun, 22 Apr 2018 21:30:51 +0000 (UTC)
commit 37368f34e4417932e34554b983621c7ba57f7754
Author: Sam Thursfield <sam afuera me uk>
Date: Fri Apr 20 19:00:31 2018 +0200
Add tracker_sparql_connection_get/set_dbus_connection()
Up til now libtracker-sparql could only connect to the Tracker store
if it was running on the session or system bus. When using a custom
domain rule that isn't installed in /usr it's necessary to run the Tracker
daemons on a separate, private bus and thus it's necessary to have a
way of passing the bus connection into libtracker-sparql.
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 4ba3eed..3b971d0 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 23cc27c..da96f9e 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 ());
+ 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;
+}
diff --git a/src/libtracker-sparql/tracker-connection.vala b/src/libtracker-sparql/tracker-connection.vala
index 412f7e8..a949ea2 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 72b29da..8f9d65c 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)
+ 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 b818a5f..997dc9e 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 b818a5f..997dc9e 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]