diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-19 20:18:14 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-19 20:25:29 +0200 |
commit | a908ea3ecb5ad78e4bdadf13d40ff76d0a038b76 (patch) | |
tree | 3d3d6d503ca12b6eb13fe6158502859a57d3669d /common/facade.h | |
parent | c563ee72f25c42a1c6f492c5f2d4e56c2c91df2a (diff) | |
download | sink-a908ea3ecb5ad78e4bdadf13d40ff76d0a038b76.tar.gz sink-a908ea3ecb5ad78e4bdadf13d40ff76d0a038b76.zip |
Modify/Delete actions
Diffstat (limited to 'common/facade.h')
-rw-r--r-- | common/facade.h | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/common/facade.h b/common/facade.h index abd4113..2ee7f42 100644 --- a/common/facade.h +++ b/common/facade.h | |||
@@ -28,6 +28,8 @@ | |||
28 | #include "resourceaccess.h" | 28 | #include "resourceaccess.h" |
29 | #include "commands.h" | 29 | #include "commands.h" |
30 | #include "createentity_generated.h" | 30 | #include "createentity_generated.h" |
31 | #include "modifyentity_generated.h" | ||
32 | #include "deleteentity_generated.h" | ||
31 | #include "domainadaptor.h" | 33 | #include "domainadaptor.h" |
32 | #include "entitybuffer.h" | 34 | #include "entitybuffer.h" |
33 | #include "log.h" | 35 | #include "log.h" |
@@ -128,6 +130,7 @@ public: | |||
128 | { | 130 | { |
129 | if (!mDomainTypeAdaptorFactory) { | 131 | if (!mDomainTypeAdaptorFactory) { |
130 | Warning() << "No domain type adaptor factory available"; | 132 | Warning() << "No domain type adaptor factory available"; |
133 | return KAsync::error<void>(); | ||
131 | } | 134 | } |
132 | flatbuffers::FlatBufferBuilder entityFbb; | 135 | flatbuffers::FlatBufferBuilder entityFbb; |
133 | mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb); | 136 | mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb); |
@@ -136,14 +139,18 @@ public: | |||
136 | 139 | ||
137 | KAsync::Job<void> modify(const DomainType &domainObject) Q_DECL_OVERRIDE | 140 | KAsync::Job<void> modify(const DomainType &domainObject) Q_DECL_OVERRIDE |
138 | { | 141 | { |
139 | //TODO | 142 | if (!mDomainTypeAdaptorFactory) { |
140 | return KAsync::null<void>(); | 143 | Warning() << "No domain type adaptor factory available"; |
144 | return KAsync::error<void>(); | ||
145 | } | ||
146 | flatbuffers::FlatBufferBuilder entityFbb; | ||
147 | mDomainTypeAdaptorFactory->createBuffer(domainObject, entityFbb); | ||
148 | return sendModifyCommand(domainObject.identifier(), domainObject.revision(), bufferTypeForDomainType(), QByteArrayList(), QByteArray::fromRawData(reinterpret_cast<const char*>(entityFbb.GetBufferPointer()), entityFbb.GetSize())); | ||
141 | } | 149 | } |
142 | 150 | ||
143 | KAsync::Job<void> remove(const DomainType &domainObject) Q_DECL_OVERRIDE | 151 | KAsync::Job<void> remove(const DomainType &domainObject) Q_DECL_OVERRIDE |
144 | { | 152 | { |
145 | //TODO | 153 | return sendDeleteCommand(domainObject.identifier(), domainObject.revision(), bufferTypeForDomainType()); |
146 | return KAsync::null<void>(); | ||
147 | } | 154 | } |
148 | 155 | ||
149 | //TODO JOBAPI return job from sync continuation to execute it as subjob? | 156 | //TODO JOBAPI return job from sync continuation to execute it as subjob? |
@@ -199,6 +206,33 @@ protected: | |||
199 | return mResourceAccess->sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb); | 206 | return mResourceAccess->sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb); |
200 | } | 207 | } |
201 | 208 | ||
209 | KAsync::Job<void> sendModifyCommand(const QByteArray &uid, qint64 revision, const QByteArray &resourceBufferType, const QByteArrayList &deletedProperties, const QByteArray &buffer) | ||
210 | { | ||
211 | flatbuffers::FlatBufferBuilder fbb; | ||
212 | auto entityId = fbb.CreateString(uid.constData()); | ||
213 | //This is the resource buffer type and not the domain type | ||
214 | auto type = fbb.CreateString(resourceBufferType.constData()); | ||
215 | //FIXME | ||
216 | auto deletions = 0; | ||
217 | auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, buffer.constData(), buffer.size()); | ||
218 | auto location = Akonadi2::Commands::CreateModifyEntity(fbb, revision, entityId, deletions, type, delta); | ||
219 | Akonadi2::Commands::FinishModifyEntityBuffer(fbb, location); | ||
220 | mResourceAccess->open(); | ||
221 | return mResourceAccess->sendCommand(Akonadi2::Commands::ModifyEntityCommand, fbb); | ||
222 | } | ||
223 | |||
224 | KAsync::Job<void> sendDeleteCommand(const QByteArray &uid, qint64 revision, const QByteArray &resourceBufferType) | ||
225 | { | ||
226 | flatbuffers::FlatBufferBuilder fbb; | ||
227 | auto entityId = fbb.CreateString(uid.constData()); | ||
228 | //This is the resource buffer type and not the domain type | ||
229 | auto type = fbb.CreateString(resourceBufferType.constData()); | ||
230 | auto location = Akonadi2::Commands::CreateDeleteEntity(fbb, revision, entityId, type); | ||
231 | Akonadi2::Commands::FinishDeleteEntityBuffer(fbb, location); | ||
232 | mResourceAccess->open(); | ||
233 | return mResourceAccess->sendCommand(Akonadi2::Commands::DeleteEntityCommand, fbb); | ||
234 | } | ||
235 | |||
202 | KAsync::Job<void> synchronizeResource(bool sync, bool processAll) | 236 | KAsync::Job<void> synchronizeResource(bool sync, bool processAll) |
203 | { | 237 | { |
204 | //TODO check if a sync is necessary | 238 | //TODO check if a sync is necessary |