[Sugar-devel] [PATCH sugar-datastore v2 2/3] add API to check/wait for index rebuild to finish (SL#1160)

Sascha Silbe silbe at activitycentral.com
Fri Feb 11 07:58:06 EST 2011


Signed-off-by: Sascha Silbe <silbe at activitycentral.com>
---
 src/carquinyol/datastore.py |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
index 12458fb..69d50f4 100644
--- a/src/carquinyol/datastore.py
+++ b/src/carquinyol/datastore.py
@@ -52,6 +52,7 @@ class DataStore(dbus.service.Object):
     """
 
     def __init__(self, **options):
+        self._wait_ready_queue = []
         bus_name = dbus.service.BusName(DS_SERVICE,
                                         bus=dbus.SessionBus(),
                                         replace_existing=False,
@@ -163,6 +164,12 @@ class DataStore(dbus.service.Object):
             self._index_store.flush()
             self._index_updating = False
             logging.debug('Finished updating index.')
+
+            self.Ready()
+            for callback in self._wait_ready_queue:
+                callback()
+
+            self._wait_ready_queue = []
             return False
         else:
             return True
@@ -422,3 +429,34 @@ class DataStore(dbus.service.Object):
     @dbus.service.signal(DS_DBUS_INTERFACE, signature="a{sv}")
     def Unmounted(self, descriptor):
         pass
+
+    @dbus.service.method(DS_DBUS_INTERFACE,
+                         in_signature='',
+                         out_signature='b')
+    def check_ready(self):
+        """Check whether datastore is ready for processing (regular) API
+        calls.
+
+        Return True if datastore is fully operational.
+        """
+        return not self._index_updating
+
+    @dbus.service.method(DS_DBUS_INTERFACE,
+             in_signature='',
+             out_signature='',
+             async_callbacks=('async_cb', 'async_err_cb'))
+    def wait_ready(self, async_cb, async_err_cb):
+        """Block until the datastore is ready for processing (regular) API
+        calls.
+        """
+        if not self._index_updating:
+            async_cb()
+            return
+
+        self._wait_ready_queue.append(async_cb)
+
+    @dbus.service.signal(DS_DBUS_INTERFACE, signature='')
+    def Ready(self):
+        """Signal emitted after datastore is ready for processing API calls.
+        """
+        pass
-- 
1.7.2.3



More information about the Sugar-devel mailing list