[tracker/tracker-0.16] libtracker-bus: allow cancellation when iterating cursor



commit 8255e1a77801141e0b8ad712d4d68586950bc83c
Author: Aleksander Morgado <aleksander lanedo com>
Date:   Fri Oct 11 20:58:23 2013 +0200

    libtracker-bus: allow cancellation when iterating cursor
    
    In the same way as the direct backend allows it.
    
    Also modify the unit test so that we make sure the cancellation is detected.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=676209

 src/libtracker-bus/tracker-array-cursor.vala  |    4 ++++
 src/libtracker-bus/tracker-bus-fd-cursor.vala |    4 ++++
 tests/libtracker-sparql/tracker-test.c        |   10 +++++-----
 3 files changed, 13 insertions(+), 5 deletions(-)
---
diff --git a/src/libtracker-bus/tracker-array-cursor.vala b/src/libtracker-bus/tracker-array-cursor.vala
index e7bb971..9c66db5 100644
--- a/src/libtracker-bus/tracker-array-cursor.vala
+++ b/src/libtracker-bus/tracker-array-cursor.vala
@@ -57,6 +57,10 @@ internal class Tracker.Bus.ArrayCursor : Tracker.Sparql.Cursor {
        }
 
        public override bool next (Cancellable? cancellable = null) throws GLib.Error {
+               if (cancellable != null && cancellable.is_cancelled ()) {
+                       throw new IOError.CANCELLED ("Operation was cancelled");
+               }
+
                if (current_row >= rows - 1) {
                        return false;
                }
diff --git a/src/libtracker-bus/tracker-bus-fd-cursor.vala b/src/libtracker-bus/tracker-bus-fd-cursor.vala
index d7c055e..a0e8815 100644
--- a/src/libtracker-bus/tracker-bus-fd-cursor.vala
+++ b/src/libtracker-bus/tracker-bus-fd-cursor.vala
@@ -86,6 +86,10 @@ class Tracker.Bus.FDCursor : Tracker.Sparql.Cursor {
        public override bool next (Cancellable? cancellable = null) throws GLib.Error {
                int last_offset;
 
+               if (cancellable != null && cancellable.is_cancelled ()) {
+                       throw new IOError.CANCELLED ("Operation was cancelled");
+               }
+
                if (buffer_index >= buffer_size) {
                        return false;
                }
diff --git a/tests/libtracker-sparql/tracker-test.c b/tests/libtracker-sparql/tracker-test.c
index e06e0a6..d559c8e 100644
--- a/tests/libtracker-sparql/tracker-test.c
+++ b/tests/libtracker-sparql/tracker-test.c
@@ -167,11 +167,6 @@ test_tracker_sparql_cursor_next_async_cb (GObject      *source,
                        g_main_loop_quit (main_loop);
                }
        } else {
-               tracker_sparql_cursor_next_async (cursor,
-                                                 cancellables[query],
-                                                 test_tracker_sparql_cursor_next_async_cb,
-                                                 user_data);
-
                next++;
 
                /* Random number here for next_count_to_cancel is "2",
@@ -184,6 +179,11 @@ test_tracker_sparql_cursor_next_async_cb (GObject      *source,
                                 next);
                        g_cancellable_cancel (cancellables[query]);
                }
+
+               tracker_sparql_cursor_next_async (cursor,
+                                                 cancellables[query],
+                                                 test_tracker_sparql_cursor_next_async_cb,
+                                                 user_data);
        }
 }
 


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