From 9ae4fcadc9200f1c9cf6322b98449b0de69112ac Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 1 Jun 2015 09:26:31 +0200 Subject: Generalized creating the buffer. --- common/domainadaptor.h | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'common') 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 @@ #include "entitybuffer.h" #include "propertymapper.h" #include "domain/event.h" +#include "log.h" /** * Create a buffer from a domain object using the provided mappings @@ -57,6 +58,25 @@ flatbuffers::Offset createBufferPart(const Akonadi2::ApplicationDomain:: return builder.Finish(); } +/** + * Create the buffer and finish the FlatBufferBuilder. + * + * After this the buffer can be extracted from the FlatBufferBuilder object. + */ +template +static void createBufferPartBuffer(const Akonadi2::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, WritePropertyMapper &mapper) +{ + auto pos = createBufferPart(domainObject, fbb, mapper); + // Because we cannot template the following call + // Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(fbb, pos); + // FIXME: This means all buffers in here must have the AKFB identifier + fbb.Finish(pos, "AKFB"); + flatbuffers::Verifier verifier(fbb.GetBufferPointer(), fbb.GetSize()); + if (!verifier.VerifyBuffer()) { + Warning() << "Created invalid uffer"; + } +} + /** * A generic adaptor implementation that uses a property mapper to read/write values. * @@ -149,7 +169,21 @@ public: return adaptor; } - virtual void createBuffer(const DomainType &domainType, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE {}; + virtual void createBuffer(const DomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb) Q_DECL_OVERRIDE + { + flatbuffers::FlatBufferBuilder localFbb; + if (mLocalWriteMapper) { + createBufferPartBuffer(domainObject, localFbb, *mLocalWriteMapper); + } + + flatbuffers::FlatBufferBuilder resFbb; + if (mResourceWriteMapper) { + createBufferPartBuffer(domainObject, resFbb, *mResourceWriteMapper); + } + + Akonadi2::EntityBuffer::assembleEntityBuffer(fbb, 0, 0, resFbb.GetBufferPointer(), resFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); + } + protected: QSharedPointer > mLocalMapper; -- cgit v1.2.3