summaryrefslogtreecommitdiffstats
path: root/common/domainadaptor.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-06-01 09:26:31 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-06-01 09:26:31 +0200
commit9ae4fcadc9200f1c9cf6322b98449b0de69112ac (patch)
tree930e9e326980dd10e2975a5f69cc982d1fb9e580 /common/domainadaptor.h
parent9a9557b6431e8d27420603f4895e480d766f6ae2 (diff)
downloadsink-9ae4fcadc9200f1c9cf6322b98449b0de69112ac.tar.gz
sink-9ae4fcadc9200f1c9cf6322b98449b0de69112ac.zip
Generalized creating the buffer.
Diffstat (limited to 'common/domainadaptor.h')
-rw-r--r--common/domainadaptor.h36
1 files changed, 35 insertions, 1 deletions
diff --git a/common/domainadaptor.h b/common/domainadaptor.h
index c9a3a01..ca89fba 100644
--- a/common/domainadaptor.h
+++ b/common/domainadaptor.h
@@ -30,6 +30,7 @@
30#include "entitybuffer.h" 30#include "entitybuffer.h"
31#include "propertymapper.h" 31#include "propertymapper.h"
32#include "domain/event.h" 32#include "domain/event.h"
33#include "log.h"
33 34
34/** 35/**
35 * Create a buffer from a domain object using the provided mappings 36 * Create a buffer from a domain object using the provided mappings
@@ -58,6 +59,25 @@ flatbuffers::Offset<Buffer> createBufferPart(const Akonadi2::ApplicationDomain::
58} 59}
59 60
60/** 61/**
62 * Create the buffer and finish the FlatBufferBuilder.
63 *
64 * After this the buffer can be extracted from the FlatBufferBuilder object.
65 */
66template <typename Buffer, typename BufferBuilder>
67static void createBufferPartBuffer(const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, WritePropertyMapper<BufferBuilder> &mapper)
68{
69 auto pos = createBufferPart<BufferBuilder, Buffer>(domainObject, fbb, mapper);
70 // Because we cannot template the following call
71 // Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(fbb, pos);
72 // FIXME: This means all buffers in here must have the AKFB identifier
73 fbb.Finish(pos, "AKFB");
74 flatbuffers::Verifier verifier(fbb.GetBufferPointer(), fbb.GetSize());
75 if (!verifier.VerifyBuffer<Buffer>()) {
76 Warning() << "Created invalid uffer";
77 }
78}
79
80/**
61 * A generic adaptor implementation that uses a property mapper to read/write values. 81 * A generic adaptor implementation that uses a property mapper to read/write values.
62 * 82 *
63 * TODO: this is the read-only part. Create a write only equivalent 83 * TODO: this is the read-only part. Create a write only equivalent
@@ -149,7 +169,21 @@ public:
149 return adaptor; 169 return adaptor;
150 } 170 }
151 171
152 virtual void createBuffer(const DomainType &domainType, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE {}; 172 virtual void createBuffer(const DomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE
173 {
174 flatbuffers::FlatBufferBuilder localFbb;
175 if (mLocalWriteMapper) {
176 createBufferPartBuffer<LocalBuffer, LocalBuilder>(domainObject, localFbb, *mLocalWriteMapper);
177 }
178
179 flatbuffers::FlatBufferBuilder resFbb;
180 if (mResourceWriteMapper) {
181 createBufferPartBuffer<ResourceBuffer, ResourceBuilder>(domainObject, resFbb, *mResourceWriteMapper);
182 }
183
184 Akonadi2::EntityBuffer::assembleEntityBuffer(fbb, 0, 0, resFbb.GetBufferPointer(), resFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize());
185 }
186
153 187
154protected: 188protected:
155 QSharedPointer<ReadPropertyMapper<LocalBuffer> > mLocalMapper; 189 QSharedPointer<ReadPropertyMapper<LocalBuffer> > mLocalMapper;