Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Silbe <sascha@silbe.org>2009-08-11 22:17:50 (GMT)
committer Sascha Silbe <sascha@silbe.org>2009-08-13 22:36:17 (GMT)
commit9b9ac683b5797c7cfc24d87a14a56e19e1d129e9 (patch)
tree959f8e123deb70a3febdf87837cb9d81d7f30ac6
parent93b04e6517baea3b795bc57d54f02d13975427a7 (diff)
add API to check/wait for index rebuild to finish
-rw-r--r--src/carquinyol/datastore.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
index 41b16b5..e75d4db 100644
--- a/src/carquinyol/datastore.py
+++ b/src/carquinyol/datastore.py
@@ -50,6 +50,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,
@@ -109,6 +110,11 @@ class DataStore(dbus.service.Object):
if not uids:
logging.debug('Finished updating index.')
layoutmanager.get_instance().index_updated = True
+ self.Ready()
+ for callback in self._wait_ready_queue:
+ callback()
+
+ self._wait_ready_queue = []
return False
else:
return True
@@ -342,3 +348,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 layoutmanager.get_instance().index_updated
+
+ @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 layoutmanager.get_instance().index_updated:
+ 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