From 2388e86dcdcd6ebb13193091a8c3e03843b03285 Mon Sep 17 00:00:00 2001
From: Sascha Silbe <sascha@silbe.org>
Date: Wed, 12 Aug 2009 00:17:50 +0200
Subject: [PATCH] add API to check/wait for index rebuild to finish
---
src/carquinyol/datastore.py | 37 +++++++++++++++++++++++++++++++++++++
1 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
index 0307046..c9c790c 100644
a
|
b
|
class DataStore(dbus.service.Object): |
50 | 50 | """ |
51 | 51 | |
52 | 52 | def __init__(self, **options): |
| 53 | self._wait_ready_queue = [] |
53 | 54 | bus_name = dbus.service.BusName(DS_SERVICE, |
54 | 55 | bus=dbus.SessionBus(), |
55 | 56 | replace_existing=False, |
… |
… |
class DataStore(dbus.service.Object): |
109 | 110 | if not uids: |
110 | 111 | logging.debug('Finished updating index.') |
111 | 112 | layoutmanager.get_instance().index_updated = True |
| 113 | self.Ready() |
| 114 | for callback in self._wait_ready_queue: |
| 115 | callback() |
| 116 | |
| 117 | self._wait_ready_queue = [] |
112 | 118 | return False |
113 | 119 | else: |
114 | 120 | return True |
… |
… |
class DataStore(dbus.service.Object): |
342 | 348 | @dbus.service.signal(DS_DBUS_INTERFACE, signature="a{sv}") |
343 | 349 | def Unmounted(self, descriptor): |
344 | 350 | pass |
| 351 | |
| 352 | @dbus.service.method(DS_DBUS_INTERFACE, |
| 353 | in_signature='', |
| 354 | out_signature='b') |
| 355 | def check_ready(self): |
| 356 | """Check whether datastore is ready for processing (regular) API |
| 357 | calls. |
| 358 | |
| 359 | Return True if datastore is fully operational. |
| 360 | """ |
| 361 | return layoutmanager.get_instance().index_updated |
| 362 | |
| 363 | @dbus.service.method(DS_DBUS_INTERFACE, |
| 364 | in_signature='', |
| 365 | out_signature='', |
| 366 | async_callbacks=('async_cb', 'async_err_cb')) |
| 367 | def wait_ready(self, async_cb, async_err_cb): |
| 368 | """Block until the datastore is ready for processing (regular) API |
| 369 | calls. |
| 370 | """ |
| 371 | if layoutmanager.get_instance().index_updated: |
| 372 | async_cb() |
| 373 | return |
| 374 | |
| 375 | self._wait_ready_queue.append(async_cb) |
| 376 | |
| 377 | @dbus.service.signal(DS_DBUS_INTERFACE, signature='') |
| 378 | def Ready(self): |
| 379 | """Signal emitted after datastore is ready for processing API calls. |
| 380 | """ |
| 381 | pass |