summaryrefslogtreecommitdiffstats
path: root/common/clientapi.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-01-18 14:29:08 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-01-18 14:29:08 +0100
commitd417f01e2eebeedfaae76b40667372bd0fb21fea (patch)
treeab0749c576e0c3fe4ff621c50cbdc038beab2185 /common/clientapi.h
parent47b4442c585a25b2e4b857f2d9e3ab371d942c19 (diff)
downloadsink-d417f01e2eebeedfaae76b40667372bd0fb21fea.tar.gz
sink-d417f01e2eebeedfaae76b40667372bd0fb21fea.zip
Use jobs in queries, sync works again.
Diffstat (limited to 'common/clientapi.h')
-rw-r--r--common/clientapi.h26
1 files changed, 16 insertions, 10 deletions
diff --git a/common/clientapi.h b/common/clientapi.h
index 2f1c127..dd11a0d 100644
--- a/common/clientapi.h
+++ b/common/clientapi.h
@@ -165,7 +165,7 @@ namespace Akonadi2 {
165/** 165/**
166 * Standardized Domain Types 166 * Standardized Domain Types
167 * 167 *
168 * The don't adhere to any standard and can be freely extended 168 * They don't adhere to any standard and can be freely extended
169 * Their sole purpose is providing a standardized interface to access data. 169 * Their sole purpose is providing a standardized interface to access data.
170 * 170 *
171 * This is necessary to decouple resource-backends from application domain containers (otherwise each resource would have to provide a faceade for each application domain container). 171 * This is necessary to decouple resource-backends from application domain containers (otherwise each resource would have to provide a faceade for each application domain container).
@@ -297,6 +297,7 @@ using namespace async;
297class Query 297class Query
298{ 298{
299public: 299public:
300 Query() : syncOnDemand(true) {}
300 //Could also be a propertyFilter 301 //Could also be a propertyFilter
301 QStringList resources; 302 QStringList resources;
302 //Could also be a propertyFilter 303 //Could also be a propertyFilter
@@ -305,6 +306,7 @@ public:
305 QHash<QString, QVariant> propertyFilter; 306 QHash<QString, QVariant> propertyFilter;
306 //Properties to retrieve 307 //Properties to retrieve
307 QSet<QString> requestedProperties; 308 QSet<QString> requestedProperties;
309 bool syncOnDemand;
308}; 310};
309 311
310 312
@@ -324,7 +326,7 @@ public:
324 virtual Async::Job<void> create(const DomainType &domainObject) = 0; 326 virtual Async::Job<void> create(const DomainType &domainObject) = 0;
325 virtual Async::Job<void> modify(const DomainType &domainObject) = 0; 327 virtual Async::Job<void> modify(const DomainType &domainObject) = 0;
326 virtual Async::Job<void> remove(const DomainType &domainObject) = 0; 328 virtual Async::Job<void> remove(const DomainType &domainObject) = 0;
327 virtual void load(const Query &query, const std::function<void(const typename DomainType::Ptr &)> &resultCallback, const std::function<void()> &completeCallback) = 0; 329 virtual Async::Job<void> load(const Query &query, const std::function<void(const typename DomainType::Ptr &)> &resultCallback) = 0;
328}; 330};
329 331
330 332
@@ -418,21 +420,25 @@ public:
418 // query tells us in which resources we're interested 420 // query tells us in which resources we're interested
419 // TODO: queries to individual resources could be parallelized 421 // TODO: queries to individual resources could be parallelized
420 auto eventloop = QSharedPointer<QEventLoop>::create(); 422 auto eventloop = QSharedPointer<QEventLoop>::create();
421 int completeCounter = 0; 423 Async::Job<void> job = Async::null<void>();
422 for(const QString &resource : query.resources) { 424 for(const QString &resource : query.resources) {
423 auto facade = FacadeFactory::instance().getFacade<DomainType>(resource); 425 auto facade = FacadeFactory::instance().getFacade<DomainType>(resource);
424 //We have to bind an instance to the function callback. Since we use a shared pointer this keeps the result provider instance (and thus also the emitter) alive. 426 //We have to bind an instance to the function callback. Since we use a shared pointer this keeps the result provider instance (and thus also the emitter) alive.
425 std::function<void(const typename DomainType::Ptr &)> addCallback = std::bind(&ResultProvider<typename DomainType::Ptr>::add, resultSet, std::placeholders::_1); 427 std::function<void(const typename DomainType::Ptr &)> addCallback = std::bind(&ResultProvider<typename DomainType::Ptr>::add, resultSet, std::placeholders::_1);
426 //We copy the facade pointer to keep it alive 428 //We copy the facade pointer to keep it alive
427 facade->load(query, addCallback, [&completeCounter, &query, resultSet, facade, eventloop]() { 429 job = job.then<void>([facade, query, addCallback](Async::Future<void> &future) {
428 //TODO use jobs instead of this counter 430 Async::Job<void> j = facade->load(query, addCallback);
429 completeCounter++; 431 j.then<void>([&future, facade](Async::Future<void> &f) {
430 if (completeCounter == query.resources.size()) { 432 future.setFinished();
431 resultSet->complete(); 433 f.setFinished();
432 eventloop->quit(); 434 }).exec();
433 }
434 }); 435 });
435 } 436 }
437 job.then<void>([eventloop, resultSet](Async::Future<void> &future) {
438 resultSet->complete();
439 eventloop->quit();
440 future.setFinished();
441 }).exec();
436 //The thread contains no eventloop, so execute one here 442 //The thread contains no eventloop, so execute one here
437 eventloop->exec(QEventLoop::ExcludeUserInputEvents); 443 eventloop->exec(QEventLoop::ExcludeUserInputEvents);
438 }); 444 });