summaryrefslogtreecommitdiffstats
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
parent9a9557b6431e8d27420603f4895e480d766f6ae2 (diff)
downloadsink-9ae4fcadc9200f1c9cf6322b98449b0de69112ac.tar.gz
sink-9ae4fcadc9200f1c9cf6322b98449b0de69112ac.zip
Generalized creating the buffer.
-rw-r--r--common/domainadaptor.h36
-rw-r--r--examples/dummyresource/domainadaptor.cpp56
-rw-r--r--examples/dummyresource/domainadaptor.h19
3 files changed, 71 insertions, 40 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;
diff --git a/examples/dummyresource/domainadaptor.cpp b/examples/dummyresource/domainadaptor.cpp
index 8649bc3..67595af 100644
--- a/examples/dummyresource/domainadaptor.cpp
+++ b/examples/dummyresource/domainadaptor.cpp
@@ -1,23 +1,29 @@
1/*
2 * Copyright (C) 2015 Christian Mollekopf <chrigi_1@fastmail.fm>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
1 19
2#include "domainadaptor.h" 20#include "domainadaptor.h"
3 21
4#include <QDebug>
5#include <functional>
6
7#include "dummycalendar_generated.h" 22#include "dummycalendar_generated.h"
8#include "event_generated.h"
9#include "entity_generated.h"
10#include "metadata_generated.h"
11#include "domainadaptor.h"
12#include "log.h"
13#include <common/entitybuffer.h>
14 23
15using namespace DummyCalendar; 24using namespace DummyCalendar;
16using namespace flatbuffers; 25using namespace flatbuffers;
17 26
18
19
20
21DummyEventAdaptorFactory::DummyEventAdaptorFactory() 27DummyEventAdaptorFactory::DummyEventAdaptorFactory()
22 : DomainTypeAdaptorFactory() 28 : DomainTypeAdaptorFactory()
23{ 29{
@@ -32,29 +38,3 @@ DummyEventAdaptorFactory::DummyEventAdaptorFactory()
32 }); 38 });
33} 39}
34 40
35
36void DummyEventAdaptorFactory::createBuffer(const Akonadi2::ApplicationDomain::Event &event, flatbuffers::FlatBufferBuilder &fbb)
37{
38 flatbuffers::FlatBufferBuilder localFbb;
39 if (mLocalWriteMapper) {
40 auto pos = createBufferPart<Akonadi2::ApplicationDomain::Buffer::EventBuilder, Akonadi2::ApplicationDomain::Buffer::Event>(event, localFbb, *mLocalWriteMapper);
41 Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, pos);
42 flatbuffers::Verifier verifier(localFbb.GetBufferPointer(), localFbb.GetSize());
43 if (!verifier.VerifyBuffer<Akonadi2::ApplicationDomain::Buffer::Event>()) {
44 Warning() << "Created invalid local buffer";
45 }
46 }
47
48 flatbuffers::FlatBufferBuilder resFbb;
49 if (mResourceWriteMapper) {
50 auto pos = createBufferPart<DummyEventBuilder, DummyEvent>(event, resFbb, *mResourceWriteMapper);
51 DummyCalendar::FinishDummyEventBuffer(resFbb, pos);
52 flatbuffers::Verifier verifier(resFbb.GetBufferPointer(), resFbb.GetSize());
53 if (!verifier.VerifyBuffer<DummyEvent>()) {
54 Warning() << "Created invalid resource buffer";
55 }
56 }
57
58 Akonadi2::EntityBuffer::assembleEntityBuffer(fbb, 0, 0, resFbb.GetBufferPointer(), resFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize());
59}
60
diff --git a/examples/dummyresource/domainadaptor.h b/examples/dummyresource/domainadaptor.h
index 0490387..8b6d96b 100644
--- a/examples/dummyresource/domainadaptor.h
+++ b/examples/dummyresource/domainadaptor.h
@@ -1,3 +1,21 @@
1/*
2 * Copyright (C) 2015 Christian Mollekopf <chrigi_1@fastmail.fm>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
1#pragma once 19#pragma once
2 20
3#include "common/domainadaptor.h" 21#include "common/domainadaptor.h"
@@ -10,5 +28,4 @@ class DummyEventAdaptorFactory : public DomainTypeAdaptorFactory<Akonadi2::Appli
10public: 28public:
11 DummyEventAdaptorFactory(); 29 DummyEventAdaptorFactory();
12 virtual ~DummyEventAdaptorFactory() {}; 30 virtual ~DummyEventAdaptorFactory() {};
13 virtual void createBuffer(const Akonadi2::ApplicationDomain::Event &event, flatbuffers::FlatBufferBuilder &fbb);
14}; 31};