summaryrefslogtreecommitdiffstats
path: root/common/facade.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-08-12 00:35:49 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-08-12 00:35:49 +0200
commita8825608e1969acf4622fec3f6b6c284f1c66ea4 (patch)
treeb9f30d0228cedb6f1aa359c5237d399ec2b1e52e /common/facade.h
parentffef7c0341ea42aba550fc6db432da3a334fd7f1 (diff)
downloadsink-a8825608e1969acf4622fec3f6b6c284f1c66ea4.tar.gz
sink-a8825608e1969acf4622fec3f6b6c284f1c66ea4.zip
Moved sendCommand implementations to ResourceAccess
So we have commands in one place, and not in a header file.
Diffstat (limited to 'common/facade.h')
-rw-r--r--common/facade.h57
1 files changed, 4 insertions, 53 deletions
diff --git a/common/facade.h b/common/facade.h
index 52b2134..1715a7f 100644
--- a/common/facade.h
+++ b/common/facade.h
@@ -19,19 +19,13 @@
19 19
20#pragma once 20#pragma once
21 21
22#include "clientapi.h"
23
24#include <QByteArray> 22#include <QByteArray>
25 23
26#include <Async/Async> 24#include <Async/Async>
27 25
28#include "resourceaccess.h" 26#include "resourceaccess.h"
29#include "commands.h" 27#include "commands.h"
30#include "createentity_generated.h"
31#include "modifyentity_generated.h"
32#include "deleteentity_generated.h"
33#include "domainadaptor.h" 28#include "domainadaptor.h"
34#include "entitybuffer.h"
35#include "log.h" 29#include "log.h"
36#include "resultset.h" 30#include "resultset.h"
37#include "entitystorage.h" 31#include "entitystorage.h"
@@ -67,7 +61,7 @@ public:
67 } 61 }
68 62
69 /** 63 /**
70 * 64 * Set the query to run
71 */ 65 */
72 void setQuery(const QueryFunction &query) 66 void setQuery(const QueryFunction &query)
73 { 67 {
@@ -141,7 +135,7 @@ public:
141 } 135 }
142 flatbuffers::FlatBufferBuilder entityFbb; 136 flatbuffers::FlatBufferBuilder entityFbb;
143 mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb); 137 mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb);
144 return sendCreateCommand(bufferTypeForDomainType(), QByteArray::fromRawData(reinterpret_cast<const char*>(entityFbb.GetBufferPointer()), entityFbb.GetSize())); 138 return mResourceAccess->sendCreateCommand(bufferTypeForDomainType(), QByteArray::fromRawData(reinterpret_cast<const char*>(entityFbb.GetBufferPointer()), entityFbb.GetSize()));
145 } 139 }
146 140
147 KAsync::Job<void> modify(const DomainType &domainObject) Q_DECL_OVERRIDE 141 KAsync::Job<void> modify(const DomainType &domainObject) Q_DECL_OVERRIDE
@@ -152,12 +146,12 @@ public:
152 } 146 }
153 flatbuffers::FlatBufferBuilder entityFbb; 147 flatbuffers::FlatBufferBuilder entityFbb;
154 mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb); 148 mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb);
155 return sendModifyCommand(domainObject.identifier(), domainObject.revision(), bufferTypeForDomainType(), QByteArrayList(), QByteArray::fromRawData(reinterpret_cast<const char*>(entityFbb.GetBufferPointer()), entityFbb.GetSize())); 149 return mResourceAccess->sendModifyCommand(domainObject.identifier(), domainObject.revision(), bufferTypeForDomainType(), QByteArrayList(), QByteArray::fromRawData(reinterpret_cast<const char*>(entityFbb.GetBufferPointer()), entityFbb.GetSize()));
156 } 150 }
157 151
158 KAsync::Job<void> remove(const DomainType &domainObject) Q_DECL_OVERRIDE 152 KAsync::Job<void> remove(const DomainType &domainObject) Q_DECL_OVERRIDE
159 { 153 {
160 return sendDeleteCommand(domainObject.identifier(), domainObject.revision(), bufferTypeForDomainType()); 154 return mResourceAccess->sendDeleteCommand(domainObject.identifier(), domainObject.revision(), bufferTypeForDomainType());
161 } 155 }
162 156
163 //TODO JOBAPI return job from sync continuation to execute it as subjob? 157 //TODO JOBAPI return job from sync continuation to execute it as subjob?
@@ -202,55 +196,13 @@ public:
202 } 196 }
203 197
204protected: 198protected:
205 KAsync::Job<void> sendCreateCommand(const QByteArray &resourceBufferType, const QByteArray &buffer)
206 {
207 flatbuffers::FlatBufferBuilder fbb;
208 //This is the resource buffer type and not the domain type
209 auto type = fbb.CreateString(resourceBufferType.constData());
210 auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size());
211 auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta);
212 Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location);
213 mResourceAccess->open();
214 return mResourceAccess->sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb);
215 }
216
217 KAsync::Job<void> sendModifyCommand(const QByteArray &uid, qint64 revision, const QByteArray &resourceBufferType, const QByteArrayList &deletedProperties, const QByteArray &buffer)
218 {
219 flatbuffers::FlatBufferBuilder fbb;
220 auto entityId = fbb.CreateString(uid.constData());
221 //This is the resource buffer type and not the domain type
222 auto type = fbb.CreateString(resourceBufferType.constData());
223 //FIXME
224 auto deletions = 0;
225 auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size());
226 auto location = Akonadi2::Commands::CreateModifyEntity(fbb, revision, entityId, deletions, type, delta);
227 Akonadi2::Commands::FinishModifyEntityBuffer(fbb, location);
228 mResourceAccess->open();
229 return mResourceAccess->sendCommand(Akonadi2::Commands::ModifyEntityCommand, fbb);
230 }
231
232 KAsync::Job<void> sendDeleteCommand(const QByteArray &uid, qint64 revision, const QByteArray &resourceBufferType)
233 {
234 flatbuffers::FlatBufferBuilder fbb;
235 auto entityId = fbb.CreateString(uid.constData());
236 //This is the resource buffer type and not the domain type
237 auto type = fbb.CreateString(resourceBufferType.constData());
238 auto location = Akonadi2::Commands::CreateDeleteEntity(fbb, revision, entityId, type);
239 Akonadi2::Commands::FinishDeleteEntityBuffer(fbb, location);
240 mResourceAccess->open();
241 return mResourceAccess->sendCommand(Akonadi2::Commands::DeleteEntityCommand, fbb);
242 }
243
244 KAsync::Job<void> synchronizeResource(bool sync, bool processAll) 199 KAsync::Job<void> synchronizeResource(bool sync, bool processAll)
245 { 200 {
246 //TODO check if a sync is necessary 201 //TODO check if a sync is necessary
247 //TODO Only sync what was requested 202 //TODO Only sync what was requested
248 //TODO timeout 203 //TODO timeout
249 //TODO the synchronization should normally not be necessary: We just return what is already available.
250
251 if (sync || processAll) { 204 if (sync || processAll) {
252 return KAsync::start<void>([=](KAsync::Future<void> &future) { 205 return KAsync::start<void>([=](KAsync::Future<void> &future) {
253 mResourceAccess->open();
254 mResourceAccess->synchronizeResource(sync, processAll).then<void>([&future]() { 206 mResourceAccess->synchronizeResource(sync, processAll).then<void>([&future]() {
255 future.setFinished(); 207 future.setFinished();
256 }).exec(); 208 }).exec();
@@ -259,7 +211,6 @@ protected:
259 return KAsync::null<void>(); 211 return KAsync::null<void>();
260 } 212 }
261 213
262
263private: 214private:
264 virtual KAsync::Job<qint64> load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision) 215 virtual KAsync::Job<qint64> load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<typename DomainType::Ptr> > &resultProvider, qint64 oldRevision, qint64 newRevision)
265 { 216 {