[tracker/libtracker-bus: 40/44] libtracker-bus: Fix cancellation



commit 76aacd5cc8b9d4d8dbd4466a2b581beb1aa583a0
Author: Jürg Billeter <j bitron ch>
Date:   Wed Aug 11 15:54:22 2010 +0200

    libtracker-bus: Fix cancellation

 src/libtracker-bus/tracker-bus-fd-cursor.c       |    6 +++-
 src/libtracker-bus/tracker-bus-fd-cursor.h       |    1 +
 src/libtracker-bus/tracker-bus-fd-cursor.vapi    |    2 +-
 src/libtracker-bus/tracker-bus-fd-update.c       |   26 ++++++++++++++++++++-
 src/libtracker-bus/tracker-bus-fd-update.vapi    |    8 +++---
 src/libtracker-bus/tracker-bus.vala              |   26 +++++++++++-----------
 src/libtracker-sparql/tracker-connection.vala    |   20 ++++++++--------
 src/libtracker-sparql/tracker-plugin-loader.vala |   20 ++++++++--------
 8 files changed, 67 insertions(+), 42 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-bus-fd-cursor.c b/src/libtracker-bus/tracker-bus-fd-cursor.c
index 892981c..d8adda9 100644
--- a/src/libtracker-bus/tracker-bus-fd-cursor.c
+++ b/src/libtracker-bus/tracker-bus-fd-cursor.c
@@ -222,6 +222,7 @@ tracker_bus_fd_cursor_finalize (GObject *object)
 TrackerSparqlCursor *
 tracker_bus_fd_query (DBusGConnection  *gconnection,
                       const gchar      *query,
+                      GCancellable     *cancellable,
                       GError          **error)
 {
 #ifdef HAVE_DBUS_FD_PASSING
@@ -258,7 +259,7 @@ tracker_bus_fd_query (DBusGConnection  *gconnection,
 	tracker_dbus_send_and_splice (connection,
 	                              message,
 	                              pipefd[0],
-	                              NULL,
+	                              cancellable,
 	                              (void **) &cursor->buffer,
 	                              &cursor->buffer_size,
 	                              &inner_error);
@@ -314,6 +315,7 @@ query_async_cb (gpointer  buffer,
 void
 tracker_bus_fd_query_async (DBusGConnection     *gconnection,
                             const gchar         *query,
+                            GCancellable        *cancellable,
                             GAsyncReadyCallback  callback,
                             gpointer             user_data)
 {
@@ -357,7 +359,7 @@ tracker_bus_fd_query_async (DBusGConnection     *gconnection,
 	tracker_dbus_send_and_splice_async (connection,
 	                                    message,
 	                                    pipefd[0],
-	                                    NULL,
+	                                    cancellable,
 	                                    query_async_cb, res);
 	/* message is destroyed by tracker_dbus_send_and_splice_async */
 #else  /* HAVE_DBUS_FD_PASSING */
diff --git a/src/libtracker-bus/tracker-bus-fd-cursor.h b/src/libtracker-bus/tracker-bus-fd-cursor.h
index 9b12f9b..2bb9db5 100644
--- a/src/libtracker-bus/tracker-bus-fd-cursor.h
+++ b/src/libtracker-bus/tracker-bus-fd-cursor.h
@@ -32,6 +32,7 @@ G_BEGIN_DECLS
 void
 tracker_bus_fd_query_async (DBusGConnection     *gconnection,
                             const gchar         *query,
+                            GCancellable        *cancellable,
                             GAsyncReadyCallback  callback,
                             gpointer             user_data);
 
diff --git a/src/libtracker-bus/tracker-bus-fd-cursor.vapi b/src/libtracker-bus/tracker-bus-fd-cursor.vapi
index 20482ac..ce5bc98 100644
--- a/src/libtracker-bus/tracker-bus-fd-cursor.vapi
+++ b/src/libtracker-bus/tracker-bus-fd-cursor.vapi
@@ -18,4 +18,4 @@
  */
 
 [CCode (cheader_filename = "libtracker-bus/tracker-bus-fd-cursor.h")]
-public async Tracker.Sparql.Cursor tracker_bus_fd_query_async (DBus.Connection connection, string query) throws DBus.Error;
+public async Tracker.Sparql.Cursor tracker_bus_fd_query_async (DBus.Connection connection, string query, GLib.Cancellable? cancellable) throws Tracker.Sparql.Error, DBus.Error, GLib.IOError;
diff --git a/src/libtracker-bus/tracker-bus-fd-update.c b/src/libtracker-bus/tracker-bus-fd-update.c
index 08c8c97..d9fbfc6 100644
--- a/src/libtracker-bus/tracker-bus-fd-update.c
+++ b/src/libtracker-bus/tracker-bus-fd-update.c
@@ -78,8 +78,30 @@ fast_async_data_free (gpointer data)
 	}
 }
 
+static gboolean
+on_cancel_idle (gpointer data)
+{
+	FastAsyncData *fad = data;
+	GError *error = NULL;
+
+	g_set_error_literal (&error,
+	                     G_IO_ERROR,
+	                     G_IO_ERROR_CANCELLED,
+	                     "Operation was cancelled");
+
+	g_simple_async_result_set_from_error (fad->res, error);
+
+	g_simple_async_result_complete (fad->res);
+
+	g_error_free (error);
+	fast_async_data_free (fad);
+
+	return FALSE;
+}
+
 static void
-on_cancel (FastAsyncData *fad)
+on_cancel (GCancellable *cancellable,
+           FastAsyncData *fad)
 {
 	if (fad->dbus_call) {
 		dbus_pending_call_cancel (fad->dbus_call);
@@ -87,7 +109,7 @@ on_cancel (FastAsyncData *fad)
 		fad->dbus_call = NULL;
 	}
 
-	fast_async_data_free (fad);
+	g_idle_add (on_cancel_idle, fad);
 }
 
 static FastAsyncData *
diff --git a/src/libtracker-bus/tracker-bus-fd-update.vapi b/src/libtracker-bus/tracker-bus-fd-update.vapi
index 67c770c..26df9e2 100644
--- a/src/libtracker-bus/tracker-bus-fd-update.vapi
+++ b/src/libtracker-bus/tracker-bus-fd-update.vapi
@@ -18,10 +18,10 @@
  */
 
 [CCode (cheader_filename = "tracker-bus-fd-update.h")]
-public void tracker_bus_fd_sparql_update (DBus.Connection connection, string query) throws Tracker.Sparql.Error;
+public void tracker_bus_fd_sparql_update (DBus.Connection connection, string query) throws Tracker.Sparql.Error, DBus.Error, GLib.IOError;
 [CCode (cheader_filename = "tracker-bus-fd-update.h")]
-public extern GLib.Variant tracker_bus_fd_sparql_update_blank (DBus.Connection connection, string query) throws Tracker.Sparql.Error;
+public extern GLib.Variant tracker_bus_fd_sparql_update_blank (DBus.Connection connection, string query) throws Tracker.Sparql.Error, DBus.Error, GLib.IOError;
 [CCode (cheader_filename = "tracker-bus-fd-update.h")]
-public extern async void tracker_bus_fd_sparql_update_async (DBus.Connection connection, string query, GLib.Cancellable? cancellable = null) throws Tracker.Sparql.Error;
+public extern async void tracker_bus_fd_sparql_update_async (DBus.Connection connection, string query, GLib.Cancellable? cancellable = null) throws Tracker.Sparql.Error, DBus.Error, GLib.IOError;
 [CCode (cheader_filename = "tracker-bus-fd-update.h")]
-public extern async GLib.Variant tracker_bus_fd_sparql_update_blank_async (DBus.Connection connection, string query, GLib.Cancellable? cancellable = null) throws Tracker.Sparql.Error;
+public extern async GLib.Variant tracker_bus_fd_sparql_update_blank_async (DBus.Connection connection, string query, GLib.Cancellable? cancellable = null) throws Tracker.Sparql.Error, DBus.Error, GLib.IOError;
diff --git a/src/libtracker-bus/tracker-bus.vala b/src/libtracker-bus/tracker-bus.vala
index ce0e4bb..8e4264c 100644
--- a/src/libtracker-bus/tracker-bus.vala
+++ b/src/libtracker-bus/tracker-bus.vala
@@ -39,7 +39,7 @@ private interface Tracker.Bus.Statistics : GLib.Object {
 }
 
 // Imported DBus FD API until we have support with Vala
-public extern Tracker.Sparql.Cursor tracker_bus_fd_query (DBus.Connection connection, string query) throws Tracker.Sparql.Error;
+public extern Tracker.Sparql.Cursor tracker_bus_fd_query (DBus.Connection connection, string query, Cancellable? cancellable) throws Tracker.Sparql.Error, DBus.Error, GLib.IOError;
 
 // Actual class definition
 public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
@@ -86,10 +86,10 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 		initialized = false;
 	}
 
-	public override Sparql.Cursor query (string sparql, Cancellable? cancellable) throws Sparql.Error {
+	public override Sparql.Cursor query (string sparql, Cancellable? cancellable) throws Sparql.Error, IOError {
 		try {
 			if (use_steroids) {
-				return tracker_bus_fd_query (connection, sparql);
+				return tracker_bus_fd_query (connection, sparql, cancellable);
 			} else {
 				string[,] results = resources_object.sparql_query (sparql);
 				return new Tracker.Bus.ArrayCursor ((owned) results, results.length[0], results.length[1]);
@@ -99,10 +99,10 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 		}
 	}
 
-	public async override Sparql.Cursor query_async (string sparql, Cancellable? cancellable = null) throws Sparql.Error {
+	public async override Sparql.Cursor query_async (string sparql, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
 			if (use_steroids) {
-				return yield tracker_bus_fd_query_async (connection, sparql);
+				return yield tracker_bus_fd_query_async (connection, sparql, cancellable);
 			} else {
 				string[,] results = yield resources_object.sparql_query_async (sparql);
 				return new Tracker.Bus.ArrayCursor ((owned) results, results.length[0], results.length[1]);
@@ -112,7 +112,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 		}
 	}
 
-	public override void update (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error {
+	public override void update (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
 			if (use_steroids) {
 				tracker_bus_fd_sparql_update (connection, sparql);
@@ -124,7 +124,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 		}
 	}
 
-	public async override void update_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error {
+	public async override void update_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
 			if (use_steroids) {
 				yield tracker_bus_fd_sparql_update_async (connection, sparql, cancellable);
@@ -136,7 +136,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 		}
 	}
 
-	public override GLib.Variant? update_blank (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error {
+	public override GLib.Variant? update_blank (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		GLib.Variant res = null;
 
 		if (use_steroids) {
@@ -147,7 +147,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 		return res;
 	}
 
-	public async override GLib.Variant? update_blank_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error {
+	public async override GLib.Variant? update_blank_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		GLib.Variant res = null;
 
 		if (use_steroids) {
@@ -159,14 +159,14 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 		return res;
 	}
 
-	public override void load (File file, Cancellable? cancellable = null) throws Sparql.Error {
+	public override void load (File file, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
 			resources_object.load (file.get_uri ());
 		} catch (DBus.Error e) {
 			throw new Sparql.Error.INTERNAL (e.message);
 		}
 	}
-	public async override void load_async (File file, Cancellable? cancellable = null) throws Sparql.Error {
+	public async override void load_async (File file, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
 			yield resources_object.load_async (file.get_uri ());
 		} catch (DBus.Error e) {
@@ -174,7 +174,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 		}
 	}
 
-	public override Sparql.Cursor? statistics (Cancellable? cancellable = null) throws Sparql.Error {
+	public override Sparql.Cursor? statistics (Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
 			string[,] results = statistics_object.Get ();
 			return new Tracker.Bus.ArrayCursor ((owned) results, results.length[0], results.length[1]);
@@ -183,7 +183,7 @@ public class Tracker.Bus.Connection : Tracker.Sparql.Connection {
 		}
 	}
 
-	public async override Sparql.Cursor? statistics_async (Cancellable? cancellable = null) throws Sparql.Error {
+	public async override Sparql.Cursor? statistics_async (Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		try {
 			string[,] results = yield statistics_object.Get_async ();
 			return new Tracker.Bus.ArrayCursor ((owned) results, results.length[0], results.length[1]);
diff --git a/src/libtracker-sparql/tracker-connection.vala b/src/libtracker-sparql/tracker-connection.vala
index 9701fdc..bb4ec8d 100644
--- a/src/libtracker-sparql/tracker-connection.vala
+++ b/src/libtracker-sparql/tracker-connection.vala
@@ -193,7 +193,7 @@ public abstract class Tracker.Sparql.Connection : Object {
 	 * On error, #NULL is returned and the @error is set accordingly.
 	 * Call g_object_unref() on the returned cursor when no longer needed.
 	 */
-	public abstract Cursor query (string sparql, Cancellable? cancellable = null) throws Sparql.Error;
+	public abstract Cursor query (string sparql, Cancellable? cancellable = null) throws Sparql.Error, IOError;
 
 	/**
 	 * tracker_sparql_connection_query_async:
@@ -219,7 +219,7 @@ public abstract class Tracker.Sparql.Connection : Object {
 	 * On error, #NULL is returned and the @error is set accordingly.
 	 * Call g_object_unref() on the returned cursor when no longer needed.
 	 */
-	public async abstract Cursor query_async (string sparql, Cancellable? cancellable = null) throws Sparql.Error;
+	public async abstract Cursor query_async (string sparql, Cancellable? cancellable = null) throws Sparql.Error, IOError;
 
 	/**
 	 * tracker_sparql_connection_update:
@@ -232,7 +232,7 @@ public abstract class Tracker.Sparql.Connection : Object {
 	 * Executes a SPARQL update on the store. The API call is completely
 	 * synchronous, so it may block.
 	 */
-	public virtual void update (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error {
+	public virtual void update (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		warning ("Interface 'update' not implemented");
 	}
 
@@ -257,7 +257,7 @@ public abstract class Tracker.Sparql.Connection : Object {
 	 *
 	 * Finishes the asynchronous SPARQL update operation.
 	 */
-	public async virtual void update_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error {
+	public async virtual void update_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		warning ("Interface 'update_async' not implemented");
 	}
 
@@ -276,7 +276,7 @@ public abstract class Tracker.Sparql.Connection : Object {
 	 * Returns: a #GVariant with the generated URNs, which should be freed with
 	 * g_variant_unref() when no longer used.
 	 */
-	public virtual GLib.Variant? update_blank (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error {
+	public virtual GLib.Variant? update_blank (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		warning ("Interface 'update_blank' not implemented");
 		return null;
 	}
@@ -306,7 +306,7 @@ public abstract class Tracker.Sparql.Connection : Object {
 	 * Returns: a #GVariant with the generated URNs, which should be freed with
 	 * g_variant_unref() when no longer used.
 	 */
-	public async virtual GLib.Variant? update_blank_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error {
+	public async virtual GLib.Variant? update_blank_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		warning ("Interface 'update_blank_async' not implemented");
 		return null;
 	}
@@ -321,7 +321,7 @@ public abstract class Tracker.Sparql.Connection : Object {
 	 * Loads a Turtle file (TTL) into the store. The API call is completely
 	 * synchronous, so it may block.
 	 */
-	public virtual void load (File file, Cancellable? cancellable = null) throws Sparql.Error {
+	public virtual void load (File file, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		warning ("Interface 'load' not implemented");
 	}
 
@@ -345,7 +345,7 @@ public abstract class Tracker.Sparql.Connection : Object {
 	 *
 	 * Finishes the asynchronous load of the Turtle file.
 	 */
-	public async virtual void load_async (File file, Cancellable? cancellable = null) throws Sparql.Error {
+	public async virtual void load_async (File file, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		warning ("Interface 'load_async' not implemented");
 	}
 
@@ -362,7 +362,7 @@ public abstract class Tracker.Sparql.Connection : Object {
 	 * on error. Call g_object_unref() on the returned cursor when no longer
 	 * needed.
 	 */
-	public virtual Cursor? statistics (Cancellable? cancellable = null) throws Sparql.Error {
+	public virtual Cursor? statistics (Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		warning ("Interface 'statistics' not implemented");
 		return null;
 	}
@@ -390,7 +390,7 @@ public abstract class Tracker.Sparql.Connection : Object {
 	 * on error. Call g_object_unref() on the returned cursor when no longer
 	 * needed.
 	 */
-	public async virtual Cursor? statistics_async (Cancellable? cancellable = null) throws Sparql.Error {
+	public async virtual Cursor? statistics_async (Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		warning ("Interface 'statistics_async' not implemented");
 		return null;
 	}
diff --git a/src/libtracker-sparql/tracker-plugin-loader.vala b/src/libtracker-sparql/tracker-plugin-loader.vala
index 0e1e733..333464d 100644
--- a/src/libtracker-sparql/tracker-plugin-loader.vala
+++ b/src/libtracker-sparql/tracker-plugin-loader.vala
@@ -39,7 +39,7 @@ class Tracker.Sparql.PluginLoader : Connection {
 		initialized = true;
 	}
 
-	public override Cursor query (string sparql, Cancellable? cancellable = null) throws Sparql.Error {
+	public override Cursor query (string sparql, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		if (direct != null) {
 			return direct.query (sparql, cancellable);
 		} else {
@@ -47,7 +47,7 @@ class Tracker.Sparql.PluginLoader : Connection {
 		}
 	}
 
-	public async override Cursor query_async (string sparql, Cancellable? cancellable = null) throws Sparql.Error {
+	public async override Cursor query_async (string sparql, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		if (direct != null) {
 			return yield direct.query_async (sparql, cancellable);
 		} else {
@@ -55,35 +55,35 @@ class Tracker.Sparql.PluginLoader : Connection {
 		}
 	}
 
-	public override void update (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error {
+	public override void update (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		bus.update (sparql, priority, cancellable);
 	}
 
-	public override GLib.Variant? update_blank (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error {
+	public override GLib.Variant? update_blank (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		return bus.update_blank (sparql, priority, cancellable);
 	}
 
-	public async override void update_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error {
+	public async override void update_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		yield bus.update_async (sparql, priority, cancellable);
 	}
 
-	public async override GLib.Variant? update_blank_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error {
+	public async override GLib.Variant? update_blank_async (string sparql, int priority = GLib.Priority.DEFAULT, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		return yield bus.update_blank_async (sparql, priority, cancellable);
 	}
 
-	public override void load (File file, Cancellable? cancellable = null) throws Sparql.Error {
+	public override void load (File file, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		bus.load (file, cancellable);
 	}
 
-	public async override void load_async (File file, Cancellable? cancellable = null) throws Sparql.Error {
+	public async override void load_async (File file, Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		yield bus.load_async (file, cancellable);
 	}
 
-	public override Cursor? statistics (Cancellable? cancellable = null) throws Sparql.Error {
+	public override Cursor? statistics (Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		return bus.statistics (cancellable);
 	}
 
-	public async override Cursor? statistics_async (Cancellable? cancellable = null) throws Sparql.Error {
+	public async override Cursor? statistics_async (Cancellable? cancellable = null) throws Sparql.Error, IOError {
 		return yield bus.statistics_async (cancellable);
 	}
 



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