summaryrefslogtreecommitdiffstats
path: root/common/facade.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/facade.h')
-rw-r--r--common/facade.h35
1 files changed, 18 insertions, 17 deletions
diff --git a/common/facade.h b/common/facade.h
index 8c6578f..5743aa2 100644
--- a/common/facade.h
+++ b/common/facade.h
@@ -23,7 +23,8 @@
23 23
24#include <QByteArray> 24#include <QByteArray>
25 25
26#include "async/src/async.h" 26#include <Async/Async>
27
27#include "resourceaccess.h" 28#include "resourceaccess.h"
28#include "commands.h" 29#include "commands.h"
29#include "createentity_generated.h" 30#include "createentity_generated.h"
@@ -44,13 +45,13 @@ class QueryRunner : public QObject
44{ 45{
45 Q_OBJECT 46 Q_OBJECT
46public: 47public:
47 typedef std::function<Async::Job<qint64>(qint64 oldRevision, qint64 newRevision)> QueryFunction; 48 typedef std::function<KAsync::Job<qint64>(qint64 oldRevision, qint64 newRevision)> QueryFunction;
48 49
49 QueryRunner(const Akonadi2::Query &query) : mLatestRevision(0) {}; 50 QueryRunner(const Akonadi2::Query &query) : mLatestRevision(0) {};
50 /** 51 /**
51 * Starts query 52 * Starts query
52 */ 53 */
53 Async::Job<void> run(qint64 newRevision = 0) 54 KAsync::Job<void> run(qint64 newRevision = 0)
54 { 55 {
55 //TODO: JOBAPI: that last empty .then should not be necessary 56 //TODO: JOBAPI: that last empty .then should not be necessary
56 return queryFunction(mLatestRevision, newRevision).then<void, qint64>([this](qint64 revision) { 57 return queryFunction(mLatestRevision, newRevision).then<void, qint64>([this](qint64 revision) {
@@ -120,7 +121,7 @@ public:
120 return Akonadi2::ApplicationDomain::getTypeName<DomainType>(); 121 return Akonadi2::ApplicationDomain::getTypeName<DomainType>();
121 } 122 }
122 123
123 Async::Job<void> create(const Akonadi2::ApplicationDomain::Event &domainObject) Q_DECL_OVERRIDE 124 KAsync::Job<void> create(const Akonadi2::ApplicationDomain::Event &domainObject) Q_DECL_OVERRIDE
124 { 125 {
125 if (!mDomainTypeAdaptorFactory) { 126 if (!mDomainTypeAdaptorFactory) {
126 Warning() << "No domain type adaptor factory available"; 127 Warning() << "No domain type adaptor factory available";
@@ -130,25 +131,25 @@ public:
130 return sendCreateCommand(bufferTypeForDomainType(), QByteArray::fromRawData(reinterpret_cast<const char*>(entityFbb.GetBufferPointer()), entityFbb.GetSize())); 131 return sendCreateCommand(bufferTypeForDomainType(), QByteArray::fromRawData(reinterpret_cast<const char*>(entityFbb.GetBufferPointer()), entityFbb.GetSize()));
131 } 132 }
132 133
133 Async::Job<void> modify(const Akonadi2::ApplicationDomain::Event &domainObject) Q_DECL_OVERRIDE 134 KAsync::Job<void> modify(const Akonadi2::ApplicationDomain::Event &domainObject) Q_DECL_OVERRIDE
134 { 135 {
135 //TODO 136 //TODO
136 return Async::null<void>(); 137 return KAsync::null<void>();
137 } 138 }
138 139
139 Async::Job<void> remove(const Akonadi2::ApplicationDomain::Event &domainObject) Q_DECL_OVERRIDE 140 KAsync::Job<void> remove(const Akonadi2::ApplicationDomain::Event &domainObject) Q_DECL_OVERRIDE
140 { 141 {
141 //TODO 142 //TODO
142 return Async::null<void>(); 143 return KAsync::null<void>();
143 } 144 }
144 145
145 //TODO JOBAPI return job from sync continuation to execute it as subjob? 146 //TODO JOBAPI return job from sync continuation to execute it as subjob?
146 Async::Job<void> load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > &resultProvider) Q_DECL_OVERRIDE 147 KAsync::Job<void> load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > &resultProvider) Q_DECL_OVERRIDE
147 { 148 {
148 auto runner = QSharedPointer<QueryRunner>::create(query); 149 auto runner = QSharedPointer<QueryRunner>::create(query);
149 QWeakPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > weakResultProvider = resultProvider; 150 QWeakPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > weakResultProvider = resultProvider;
150 runner->setQuery([this, weakResultProvider, query] (qint64 oldRevision, qint64 newRevision) -> Async::Job<qint64> { 151 runner->setQuery([this, weakResultProvider, query] (qint64 oldRevision, qint64 newRevision) -> KAsync::Job<qint64> {
151 return Async::start<qint64>([this, weakResultProvider, query, oldRevision, newRevision](Async::Future<qint64> &future) { 152 return KAsync::start<qint64>([this, weakResultProvider, query, oldRevision, newRevision](KAsync::Future<qint64> &future) {
152 auto resultProvider = weakResultProvider.toStrongRef(); 153 auto resultProvider = weakResultProvider.toStrongRef();
153 if (!resultProvider) { 154 if (!resultProvider) {
154 Warning() << "Tried executing query after result provider is already gone"; 155 Warning() << "Tried executing query after result provider is already gone";
@@ -175,7 +176,7 @@ public:
175 } 176 }
176 177
177 //We have to capture the runner to keep it alive 178 //We have to capture the runner to keep it alive
178 return synchronizeResource(query.syncOnDemand, query.processAll).template then<void>([runner](Async::Future<void> &future) { 179 return synchronizeResource(query.syncOnDemand, query.processAll).template then<void>([runner](KAsync::Future<void> &future) {
179 runner->run().then<void>([&future]() { 180 runner->run().then<void>([&future]() {
180 future.setFinished(); 181 future.setFinished();
181 }).exec(); 182 }).exec();
@@ -183,7 +184,7 @@ public:
183 } 184 }
184 185
185protected: 186protected:
186 Async::Job<void> sendCreateCommand(const QByteArray &resourceBufferType, const QByteArray &buffer) 187 KAsync::Job<void> sendCreateCommand(const QByteArray &resourceBufferType, const QByteArray &buffer)
187 { 188 {
188 flatbuffers::FlatBufferBuilder fbb; 189 flatbuffers::FlatBufferBuilder fbb;
189 //This is the resource buffer type and not the domain type 190 //This is the resource buffer type and not the domain type
@@ -195,7 +196,7 @@ protected:
195 return mResourceAccess->sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb); 196 return mResourceAccess->sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb);
196 } 197 }
197 198
198 Async::Job<void> synchronizeResource(bool sync, bool processAll) 199 KAsync::Job<void> synchronizeResource(bool sync, bool processAll)
199 { 200 {
200 //TODO check if a sync is necessary 201 //TODO check if a sync is necessary
201 //TODO Only sync what was requested 202 //TODO Only sync what was requested
@@ -203,17 +204,17 @@ protected:
203 //TODO the synchronization should normally not be necessary: We just return what is already available. 204 //TODO the synchronization should normally not be necessary: We just return what is already available.
204 205
205 if (sync || processAll) { 206 if (sync || processAll) {
206 return Async::start<void>([=](Async::Future<void> &future) { 207 return KAsync::start<void>([=](KAsync::Future<void> &future) {
207 mResourceAccess->open(); 208 mResourceAccess->open();
208 mResourceAccess->synchronizeResource(sync, processAll).then<void>([&future]() { 209 mResourceAccess->synchronizeResource(sync, processAll).then<void>([&future]() {
209 future.setFinished(); 210 future.setFinished();
210 }).exec(); 211 }).exec();
211 }); 212 });
212 } 213 }
213 return Async::null<void>(); 214 return KAsync::null<void>();
214 } 215 }
215 216
216 virtual Async::Job<qint64> load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision) { return Async::null<qint64>(); }; 217 virtual KAsync::Job<qint64> load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision) { return KAsync::null<qint64>(); };
217 218
218protected: 219protected:
219 //TODO use one resource access instance per application => make static 220 //TODO use one resource access instance per application => make static