summaryrefslogtreecommitdiffstats
path: root/examples/dummyresource/domainadaptor.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-19 14:11:02 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-19 14:11:02 +0200
commitf89e43b3603976bc0e6eb885b3b9a43a6caff1c2 (patch)
tree2ce617aa7a0f6b82b274f8fc9c0e74be5706ea31 /examples/dummyresource/domainadaptor.cpp
parent9ce338c195bdc123633c3018a91908df26848da6 (diff)
downloadsink-f89e43b3603976bc0e6eb885b3b9a43a6caff1c2.tar.gz
sink-f89e43b3603976bc0e6eb885b3b9a43a6caff1c2.zip
Moved client and dummyresource to examples/
Diffstat (limited to 'examples/dummyresource/domainadaptor.cpp')
-rw-r--r--examples/dummyresource/domainadaptor.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/examples/dummyresource/domainadaptor.cpp b/examples/dummyresource/domainadaptor.cpp
new file mode 100644
index 0000000..8649bc3
--- /dev/null
+++ b/examples/dummyresource/domainadaptor.cpp
@@ -0,0 +1,60 @@
1
2#include "domainadaptor.h"
3
4#include <QDebug>
5#include <functional>
6
7#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
15using namespace DummyCalendar;
16using namespace flatbuffers;
17
18
19
20
21DummyEventAdaptorFactory::DummyEventAdaptorFactory()
22 : DomainTypeAdaptorFactory()
23{
24 //TODO turn this into initializeReadPropertyMapper as well?
25 mResourceMapper->addMapping("summary", [](DummyEvent const *buffer) -> QVariant {
26 return propertyToVariant<QString>(buffer->summary());
27 });
28
29 mResourceWriteMapper->addMapping("summary", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(DummyEventBuilder &)> {
30 auto offset = variantToProperty<QString>(value, fbb);
31 return [offset](DummyEventBuilder &builder) { builder.add_summary(offset); };
32 });
33}
34
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