summaryrefslogtreecommitdiffstats
path: root/examples/dummyresource/resourcefactory.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-07-09 22:36:30 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-07-09 22:36:30 +0200
commit9fb535b4cdd6af360e3bbc5ce914e9a2c11ba047 (patch)
tree180519d5da6e5343457f43d32a8573d3395ff9b9 /examples/dummyresource/resourcefactory.cpp
parent81a497aa35912e44ddebdf84e0a488e08a09aa92 (diff)
downloadsink-9fb535b4cdd6af360e3bbc5ce914e9a2c11ba047.tar.gz
sink-9fb535b4cdd6af360e3bbc5ce914e9a2c11ba047.zip
Moved the dummy backend to a separate file.
Diffstat (limited to 'examples/dummyresource/resourcefactory.cpp')
-rw-r--r--examples/dummyresource/resourcefactory.cpp41
1 files changed, 4 insertions, 37 deletions
diff --git a/examples/dummyresource/resourcefactory.cpp b/examples/dummyresource/resourcefactory.cpp
index de13aa9..3596a82 100644
--- a/examples/dummyresource/resourcefactory.cpp
+++ b/examples/dummyresource/resourcefactory.cpp
@@ -31,6 +31,7 @@
31#include "index.h" 31#include "index.h"
32#include "log.h" 32#include "log.h"
33#include "domain/event.h" 33#include "domain/event.h"
34#include "dummystore.h"
34#include <QUuid> 35#include <QUuid>
35#include <assert.h> 36#include <assert.h>
36 37
@@ -70,41 +71,6 @@ protected:
70}; 71};
71 72
72 73
73
74static std::string createEvent()
75{
76 static const size_t attachmentSize = 1024*2; // 2KB
77 static uint8_t rawData[attachmentSize];
78 static flatbuffers::FlatBufferBuilder fbb;
79 fbb.Clear();
80 {
81 uint8_t *rawDataPtr = Q_NULLPTR;
82 auto summary = fbb.CreateString("summary");
83 auto data = fbb.CreateUninitializedVector<uint8_t>(attachmentSize, &rawDataPtr);
84 DummyCalendar::DummyEventBuilder eventBuilder(fbb);
85 eventBuilder.add_summary(summary);
86 eventBuilder.add_attachment(data);
87 auto eventLocation = eventBuilder.Finish();
88 DummyCalendar::FinishDummyEventBuffer(fbb, eventLocation);
89 memcpy((void*)rawDataPtr, rawData, attachmentSize);
90 }
91
92 return std::string(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize());
93}
94
95QMap<QString, QString> populate()
96{
97 QMap<QString, QString> content;
98 for (int i = 0; i < 2; i++) {
99 auto event = createEvent();
100 content.insert(QString("key%1").arg(i), QString::fromStdString(event));
101 }
102 return content;
103}
104
105static QMap<QString, QString> s_dataSource = populate();
106
107
108DummyResource::DummyResource(const QByteArray &instanceIdentifier) 74DummyResource::DummyResource(const QByteArray &instanceIdentifier)
109 : Akonadi2::GenericResource(instanceIdentifier) 75 : Akonadi2::GenericResource(instanceIdentifier)
110{ 76{
@@ -157,8 +123,9 @@ KAsync::Job<void> DummyResource::synchronizeWithSource(Akonadi2::Pipeline *pipel
157{ 123{
158 return KAsync::start<void>([this, pipeline](KAsync::Future<void> &f) { 124 return KAsync::start<void>([this, pipeline](KAsync::Future<void> &f) {
159 //TODO use a read-only transaction during the complete sync to sync against a defined revision 125 //TODO use a read-only transaction during the complete sync to sync against a defined revision
160 auto storage = QSharedPointer<Akonadi2::Storage>::create(Akonadi2::Store::storageLocation(), "org.kde.dummy.instance1"); 126 auto storage = QSharedPointer<Akonadi2::Storage>::create(Akonadi2::Store::storageLocation(), mResourceInstanceIdentifier);
161 for (auto it = s_dataSource.constBegin(); it != s_dataSource.constEnd(); it++) { 127 const auto data = DummyStore::instance().data();
128 for (auto it = data.constBegin(); it != data.constEnd(); it++) {
162 bool isNew = true; 129 bool isNew = true;
163 if (storage->exists()) { 130 if (storage->exists()) {
164 findByRemoteId(storage, it.key(), [&](void *keyValue, int keySize, void *dataValue, int dataSize) { 131 findByRemoteId(storage, it.key(), [&](void *keyValue, int keySize, void *dataValue, int dataSize) {