diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-09 22:36:30 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-07-09 22:36:30 +0200 |
commit | 9fb535b4cdd6af360e3bbc5ce914e9a2c11ba047 (patch) | |
tree | 180519d5da6e5343457f43d32a8573d3395ff9b9 | |
parent | 81a497aa35912e44ddebdf84e0a488e08a09aa92 (diff) | |
download | sink-9fb535b4cdd6af360e3bbc5ce914e9a2c11ba047.tar.gz sink-9fb535b4cdd6af360e3bbc5ce914e9a2c11ba047.zip |
Moved the dummy backend to a separate file.
-rw-r--r-- | examples/dummyresource/CMakeLists.txt | 2 | ||||
-rw-r--r-- | examples/dummyresource/dummystore.cpp | 62 | ||||
-rw-r--r-- | examples/dummyresource/dummystore.h | 34 | ||||
-rw-r--r-- | examples/dummyresource/resourcefactory.cpp | 41 |
4 files changed, 101 insertions, 38 deletions
diff --git a/examples/dummyresource/CMakeLists.txt b/examples/dummyresource/CMakeLists.txt index 36b8e54..e4b51dd 100644 --- a/examples/dummyresource/CMakeLists.txt +++ b/examples/dummyresource/CMakeLists.txt | |||
@@ -4,7 +4,7 @@ add_definitions(-DQT_PLUGIN) | |||
4 | include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) | 4 | include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) |
5 | 5 | ||
6 | 6 | ||
7 | add_library(${PROJECT_NAME} SHARED facade.cpp resourcefactory.cpp domainadaptor.cpp resourcefacade.cpp) | 7 | add_library(${PROJECT_NAME} SHARED facade.cpp resourcefactory.cpp domainadaptor.cpp resourcefacade.cpp dummystore.cpp) |
8 | generate_flatbuffers(${PROJECT_NAME} dummycalendar) | 8 | generate_flatbuffers(${PROJECT_NAME} dummycalendar) |
9 | qt5_use_modules(${PROJECT_NAME} Core Network) | 9 | qt5_use_modules(${PROJECT_NAME} Core Network) |
10 | target_link_libraries(${PROJECT_NAME} akonadi2common) | 10 | target_link_libraries(${PROJECT_NAME} akonadi2common) |
diff --git a/examples/dummyresource/dummystore.cpp b/examples/dummyresource/dummystore.cpp new file mode 100644 index 0000000..44bea5c --- /dev/null +++ b/examples/dummyresource/dummystore.cpp | |||
@@ -0,0 +1,62 @@ | |||
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 | */ | ||
19 | #include "dummystore.h" | ||
20 | |||
21 | #include <QString> | ||
22 | |||
23 | #include "dummycalendar_generated.h" | ||
24 | |||
25 | static std::string createEvent() | ||
26 | { | ||
27 | static const size_t attachmentSize = 1024*2; // 2KB | ||
28 | static uint8_t rawData[attachmentSize]; | ||
29 | static flatbuffers::FlatBufferBuilder fbb; | ||
30 | fbb.Clear(); | ||
31 | { | ||
32 | uint8_t *rawDataPtr = nullptr; | ||
33 | auto summary = fbb.CreateString("summary"); | ||
34 | auto data = fbb.CreateUninitializedVector<uint8_t>(attachmentSize, &rawDataPtr); | ||
35 | DummyCalendar::DummyEventBuilder eventBuilder(fbb); | ||
36 | eventBuilder.add_summary(summary); | ||
37 | eventBuilder.add_attachment(data); | ||
38 | auto eventLocation = eventBuilder.Finish(); | ||
39 | DummyCalendar::FinishDummyEventBuffer(fbb, eventLocation); | ||
40 | memcpy((void*)rawDataPtr, rawData, attachmentSize); | ||
41 | } | ||
42 | |||
43 | return std::string(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
44 | } | ||
45 | |||
46 | QMap<QString, QString> populate() | ||
47 | { | ||
48 | QMap<QString, QString> content; | ||
49 | for (int i = 0; i < 2; i++) { | ||
50 | auto event = createEvent(); | ||
51 | content.insert(QString("key%1").arg(i), QString::fromStdString(event)); | ||
52 | } | ||
53 | return content; | ||
54 | } | ||
55 | |||
56 | static QMap<QString, QString> s_dataSource = populate(); | ||
57 | |||
58 | |||
59 | QMap<QString, QString> DummyStore::data() const | ||
60 | { | ||
61 | return s_dataSource; | ||
62 | } | ||
diff --git a/examples/dummyresource/dummystore.h b/examples/dummyresource/dummystore.h new file mode 100644 index 0000000..6a404ae --- /dev/null +++ b/examples/dummyresource/dummystore.h | |||
@@ -0,0 +1,34 @@ | |||
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 | */ | ||
19 | #pragma once | ||
20 | #include <QMap> | ||
21 | |||
22 | class DummyStore | ||
23 | { | ||
24 | public: | ||
25 | //TODO proper singleton | ||
26 | static DummyStore &instance() | ||
27 | { | ||
28 | static DummyStore instance; | ||
29 | return instance; | ||
30 | } | ||
31 | |||
32 | QMap<QString, QString> data() const; | ||
33 | |||
34 | }; | ||
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 | |||
74 | static 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 | |||
95 | QMap<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 | |||
105 | static QMap<QString, QString> s_dataSource = populate(); | ||
106 | |||
107 | |||
108 | DummyResource::DummyResource(const QByteArray &instanceIdentifier) | 74 | DummyResource::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) { |