summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2021-03-09 16:08:56 +0100
committerCarlos Garnacho <carlosg@gnome.org>2021-03-09 17:14:52 +0100
commitcad0aefa0b9e027eefb2d1a7150c966cb0aadcac (patch)
tree84d48f1ff80704dee8fb4177b1a39e7a04a174f5
parent86a4d087b78732b29dd445d2ea7106397a016a4e (diff)
downloadtracker-wip/carlosg/bus-new-async.tar.gz
libtracker-sparql: Add tracker_sparql_connection_bus_new_async/finishwip/carlosg/bus-new-async
The bus connection started creating a dbus proxy that we did not need to autostart, nor read properties from, so we could initially afford to not have an asynchronous version. But later we added more things on it, like session registration in the portal, and pings to check for direct access permissions within a possible sandbox. It now makes sense to have that async variant, so add one.
-rw-r--r--docs/reference/libtracker-sparql/libtracker-sparql-sections.txt2
-rw-r--r--src/libtracker-sparql/bus/tracker-bus.vala9
-rw-r--r--src/libtracker-sparql/tracker-backend.vala27
-rw-r--r--src/libtracker-sparql/tracker-connection.c28
-rw-r--r--src/libtracker-sparql/tracker-connection.h11
-rw-r--r--src/libtracker-sparql/tracker-sparql.vapi1
6 files changed, 72 insertions, 6 deletions
diff --git a/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt b/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
index 1b4f7d845..8dce837dd 100644
--- a/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
+++ b/docs/reference/libtracker-sparql/libtracker-sparql-sections.txt
@@ -106,6 +106,8 @@ tracker_sparql_connection_new_async
tracker_sparql_connection_new_finish
tracker_sparql_connection_remote_new
tracker_sparql_connection_bus_new
+tracker_sparql_connection_bus_new_async
+tracker_sparql_connection_bus_new_finish
tracker_sparql_connection_query
tracker_sparql_connection_query_async
tracker_sparql_connection_query_finish
diff --git a/src/libtracker-sparql/bus/tracker-bus.vala b/src/libtracker-sparql/bus/tracker-bus.vala
index 0cd8362a8..985d3f684 100644
--- a/src/libtracker-sparql/bus/tracker-bus.vala
+++ b/src/libtracker-sparql/bus/tracker-bus.vala
@@ -41,7 +41,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
get { return object_path; }
}
- public Connection (string dbus_name, string object_path, DBusConnection? dbus_connection) throws Sparql.Error, IOError, DBusError, GLib.Error {
+ public async Connection (string dbus_name, string object_path, DBusConnection? dbus_connection, Cancellable? cancellable) throws Sparql.Error, IOError, DBusError, GLib.Error {
Object ();
this.sandboxed = false;
this.bus = dbus_connection;
@@ -54,7 +54,8 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
var message = new DBusMessage.method_call (dbus_name, object_path, DBUS_PEER_IFACE, "Ping");
try {
- this.bus.send_message_with_reply_sync (message, 0, timeout, null).to_gerror();
+ var reply = yield this.bus.send_message_with_reply (message, 0, timeout, cancellable);
+ reply.to_gerror ();
this.dbus_name = dbus_name;
this.object_path = object_path;
return;
@@ -73,8 +74,8 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
var message = new DBusMessage.method_call (PORTAL_NAME, PORTAL_PATH, PORTAL_IFACE, "CreateSession");
message.set_body (new Variant ("(s)", uri));
- var reply = this.bus.send_message_with_reply_sync (message, 0, timeout, null);
- reply.to_gerror();
+ var reply = yield this.bus.send_message_with_reply (message, 0, timeout, cancellable);
+ reply.to_gerror ();
var variant = reply.get_body ();
variant.get_child(0, "o", out object_path);
diff --git a/src/libtracker-sparql/tracker-backend.vala b/src/libtracker-sparql/tracker-backend.vala
index 7ae95eaf8..01b95d0b5 100644
--- a/src/libtracker-sparql/tracker-backend.vala
+++ b/src/libtracker-sparql/tracker-backend.vala
@@ -28,6 +28,29 @@ public static Tracker.Sparql.Connection tracker_sparql_connection_remote_new (st
}
public static Tracker.Sparql.Connection tracker_sparql_connection_bus_new (string service, string? object_path, DBusConnection? conn) throws Tracker.Sparql.Error, IOError, DBusError, GLib.Error {
+ Tracker.get_debug_flags ();
+
+ var context = GLib.MainContext.ref_thread_default();
+ var loop = new GLib.MainLoop(context);
+ GLib.Error? error = null;
+ Tracker.Sparql.Connection? sparql_conn = null;
+ tracker_sparql_connection_bus_new_async.begin(service, object_path, conn, null, (o, res) => {
+ try {
+ sparql_conn = tracker_sparql_connection_bus_new_async.end(res);
+ } catch (Error e) {
+ error = e;
+ }
+ loop.quit();
+ });
+ loop.run ();
+
+ if (error != null)
+ throw error;
+
+ return sparql_conn;
+}
+
+public static async Tracker.Sparql.Connection tracker_sparql_connection_bus_new_async (string service, string? object_path, DBusConnection? conn, Cancellable? cancellable) throws Tracker.Sparql.Error, IOError, DBusError, GLib.Error {
GLib.DBusConnection dbus_conn;
string path;
@@ -36,14 +59,14 @@ public static Tracker.Sparql.Connection tracker_sparql_connection_bus_new (strin
if (conn != null)
dbus_conn = conn;
else
- dbus_conn = GLib.Bus.get_sync (GLib.BusType.SESSION, null);
+ dbus_conn = yield GLib.Bus.get (GLib.BusType.SESSION, cancellable);
if (object_path != null)
path = object_path;
else
path = "/org/freedesktop/Tracker3/Endpoint";
- return new Tracker.Bus.Connection (service, path, dbus_conn);
+ return yield new Tracker.Bus.Connection (service, path, dbus_conn, cancellable);
}
public static Tracker.Sparql.Connection tracker_sparql_connection_new (Tracker.Sparql.ConnectionFlags flags, File? store, File? ontology, Cancellable? cancellable = null) throws GLib.Error, Tracker.Sparql.Error, IOError {
diff --git a/src/libtracker-sparql/tracker-connection.c b/src/libtracker-sparql/tracker-connection.c
index c6284d46e..a1fbc18cf 100644
--- a/src/libtracker-sparql/tracker-connection.c
+++ b/src/libtracker-sparql/tracker-connection.c
@@ -197,6 +197,34 @@ tracker_sparql_connection_lookup_dbus_service (TrackerSparqlConnection *connect
*/
/**
+ * tracker_sparql_connection_bus_new_async:
+ * @service_name: The name of the D-Bus service to connect to.
+ * @object_path: (nullable): The path to the object, or %NULL to use the default.
+ * @dbus_connection: (nullable): The #GDBusConnection to use, or %NULL to use the session bus
+ * @cancellable: (nullable): a #GCancellable, or %NULL
+ * @callback: the #GAsyncReadyCallback called when the operation completes
+ * @user_data: data passed to @callback
+ *
+ * Connects to a database owned by another process on the
+ * local machine. This is an asynchronous operation.
+ *
+ * Since: 3.1
+ */
+
+/**
+ * tracker_sparql_connection_bus_new_finish:
+ * @result: the #GAsyncResult
+ * @error: pointer to a #GError
+ *
+ * Completion function for tracker_sparql_connection_bus_new_async().
+ *
+ * Returns: (transfer full): a new #TrackerSparqlConnection. Call g_object_unref() on the
+ * object when no longer used.
+ *
+ * Since: 3.1
+ */
+
+/**
* tracker_sparql_connection_remote_new:
* @uri_base: Base URI of the remote connection
*
diff --git a/src/libtracker-sparql/tracker-connection.h b/src/libtracker-sparql/tracker-connection.h
index 834f65fb6..d992adbcd 100644
--- a/src/libtracker-sparql/tracker-connection.h
+++ b/src/libtracker-sparql/tracker-connection.h
@@ -92,6 +92,17 @@ TrackerSparqlConnection * tracker_sparql_connection_bus_new (const gchar *s
const gchar *object_path,
GDBusConnection *dbus_connection,
GError **error);
+TRACKER_AVAILABLE_IN_3_1
+void tracker_sparql_connection_bus_new_async (const gchar *service_name,
+ const gchar *object_path,
+ GDBusConnection *dbus_connection,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+TRACKER_AVAILABLE_IN_3_1
+TrackerSparqlConnection * tracker_sparql_connection_bus_new_finish (GAsyncResult *result,
+ GError **error);
+
TRACKER_AVAILABLE_IN_ALL
TrackerSparqlConnection * tracker_sparql_connection_remote_new (const gchar *uri_base);
diff --git a/src/libtracker-sparql/tracker-sparql.vapi b/src/libtracker-sparql/tracker-sparql.vapi
index 6174ff8c4..a65090aa6 100644
--- a/src/libtracker-sparql/tracker-sparql.vapi
+++ b/src/libtracker-sparql/tracker-sparql.vapi
@@ -68,6 +68,7 @@ namespace Tracker {
public extern static new Connection new (Sparql.ConnectionFlags flags, GLib.File? store, GLib.File? ontology, GLib.Cancellable? cancellable = null) throws Sparql.Error, GLib.IOError;
public extern async static new Connection new_async (Sparql.ConnectionFlags flags, GLib.File? store, GLib.File? ontology, GLib.Cancellable? cancellable = null) throws Sparql.Error, GLib.IOError;
public extern static new Connection bus_new (string service_name, string? object_path, GLib.DBusConnection? dbus_connection = null) throws Sparql.Error, GLib.IOError, GLib.DBusError, GLib.Error;
+ public extern async static new Connection bus_new_async (string service_name, string? object_path, GLib.DBusConnection? dbus_connection = null, GLib.Cancellable? cancellable = null) throws Sparql.Error, GLib.IOError, GLib.DBusError, GLib.Error;
public abstract Cursor query (string sparql, GLib.Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, GLib.DBusError;
public async abstract Cursor query_async (string sparql, GLib.Cancellable? cancellable = null) throws Sparql.Error, GLib.Error, GLib.IOError, GLib.DBusError;