From 3fc8ce958fc244e64a3a3a92f3b1440aae04133b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 25 Jan 2015 11:23:08 +0100 Subject: A way to ensure all messages have been processed. As queries become reactive this should become less important. We can then just wait until all results become available. For tests it is in either case useful though. --- dummyresource/facade.cpp | 8 ++++---- dummyresource/facade.h | 2 +- dummyresource/resourcefactory.cpp | 7 +++++++ dummyresource/resourcefactory.h | 1 + 4 files changed, 13 insertions(+), 5 deletions(-) (limited to 'dummyresource') diff --git a/dummyresource/facade.cpp b/dummyresource/facade.cpp index 1aaec68..fcce871 100644 --- a/dummyresource/facade.cpp +++ b/dummyresource/facade.cpp @@ -115,16 +115,16 @@ static std::function DummyResourceFacade::synchronizeResource(bool sync) +Async::Job DummyResourceFacade::synchronizeResource(bool sync, bool processAll) { //TODO check if a sync is necessary //TODO Only sync what was requested //TODO timeout - if (sync) { + if (sync || processAll) { return Async::start([=](Async::Future &future) { mResourceAccess->open(); - mResourceAccess->synchronizeResource().then([&future](Async::Future &f) { + mResourceAccess->synchronizeResource(sync, processAll).then([&future](Async::Future &f) { future.setFinished(); f.setFinished(); }).exec(); @@ -195,7 +195,7 @@ void DummyResourceFacade::readValue(QSharedPointer storage, c Async::Job DummyResourceFacade::load(const Akonadi2::Query &query, const std::function &resultCallback) { - return synchronizeResource(query.syncOnDemand).then([=](Async::Future &future) { + return synchronizeResource(query.syncOnDemand, query.processAll).then([=](Async::Future &future) { //Now that the sync is complete we can execute the query const auto preparedQuery = prepareQuery(query); diff --git a/dummyresource/facade.h b/dummyresource/facade.h index c9c8047..1f69161 100644 --- a/dummyresource/facade.h +++ b/dummyresource/facade.h @@ -44,7 +44,7 @@ public: private: void readValue(QSharedPointer storage, const QByteArray &key, const std::function &resultCallback, std::function); - Async::Job synchronizeResource(bool sync); + Async::Job synchronizeResource(bool sync, bool processAll); QSharedPointer mResourceAccess; QSharedPointer > mFactory; }; diff --git a/dummyresource/resourcefactory.cpp b/dummyresource/resourcefactory.cpp index 18083cb..f510cd5 100644 --- a/dummyresource/resourcefactory.cpp +++ b/dummyresource/resourcefactory.cpp @@ -387,7 +387,14 @@ Async::Job DummyResource::synchronizeWithSource(Akonadi2::Pipeline *pipeli } } //TODO find items to remove + qDebug() << "sync complete"; + f.setFinished(); + }); +} +Async::Job DummyResource::processAllMessages() +{ + return Async::start([this](Async::Future &f) { //We have to wait for all items to be processed to ensure the synced items are available when a query gets executed. //TODO: report errors while processing sync? if (mSynchronizerQueue.isEmpty()) { diff --git a/dummyresource/resourcefactory.h b/dummyresource/resourcefactory.h index 767eba1..3b99d5e 100644 --- a/dummyresource/resourcefactory.h +++ b/dummyresource/resourcefactory.h @@ -35,6 +35,7 @@ class DummyResource : public Akonadi2::Resource public: DummyResource(); Async::Job synchronizeWithSource(Akonadi2::Pipeline *pipeline); + Async::Job processAllMessages(); void processCommand(int commandId, const QByteArray &data, uint size, Akonadi2::Pipeline *pipeline); void configurePipeline(Akonadi2::Pipeline *pipeline); int error() const; -- cgit v1.2.3