summaryrefslogtreecommitdiffstats
path: root/dummyresource
diff options
context:
space:
mode:
Diffstat (limited to 'dummyresource')
-rw-r--r--dummyresource/domainadaptor.cpp25
-rw-r--r--dummyresource/domainadaptor.h6
-rw-r--r--dummyresource/facade.cpp29
-rw-r--r--dummyresource/facade.h14
-rw-r--r--dummyresource/resourcefactory.cpp2
5 files changed, 37 insertions, 39 deletions
diff --git a/dummyresource/domainadaptor.cpp b/dummyresource/domainadaptor.cpp
index 865a4c0..b133614 100644
--- a/dummyresource/domainadaptor.cpp
+++ b/dummyresource/domainadaptor.cpp
@@ -14,11 +14,8 @@
14using namespace DummyCalendar; 14using namespace DummyCalendar;
15using namespace flatbuffers; 15using namespace flatbuffers;
16 16
17using namespace DummyCalendar;
18using namespace flatbuffers;
19
20//This will become a generic implementation that simply takes the resource buffer and local buffer pointer 17//This will become a generic implementation that simply takes the resource buffer and local buffer pointer
21class DummyEventAdaptor : public Akonadi2::Domain::BufferAdaptor 18class DummyEventAdaptor : public Akonadi2::ApplicationDomain::BufferAdaptor
22{ 19{
23public: 20public:
24 DummyEventAdaptor() 21 DummyEventAdaptor()
@@ -55,10 +52,10 @@ public:
55 return props; 52 return props;
56 } 53 }
57 54
58 Akonadi2::Domain::Buffer::Event const *mLocalBuffer; 55 Akonadi2::ApplicationDomain::Buffer::Event const *mLocalBuffer;
59 DummyEvent const *mResourceBuffer; 56 DummyEvent const *mResourceBuffer;
60 57
61 QSharedPointer<PropertyMapper<Akonadi2::Domain::Buffer::Event> > mLocalMapper; 58 QSharedPointer<PropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event> > mLocalMapper;
62 QSharedPointer<PropertyMapper<DummyEvent> > mResourceMapper; 59 QSharedPointer<PropertyMapper<DummyEvent> > mResourceMapper;
63}; 60};
64 61
@@ -73,14 +70,14 @@ DummyEventAdaptorFactory::DummyEventAdaptorFactory()
73 } 70 }
74 return QVariant(); 71 return QVariant();
75 }); 72 });
76 mLocalMapper = QSharedPointer<PropertyMapper<Akonadi2::Domain::Buffer::Event> >::create(); 73 mLocalMapper = QSharedPointer<PropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event> >::create();
77 mLocalMapper->mReadAccessors.insert("summary", [](Akonadi2::Domain::Buffer::Event const *buffer) -> QVariant { 74 mLocalMapper->mReadAccessors.insert("summary", [](Akonadi2::ApplicationDomain::Buffer::Event const *buffer) -> QVariant {
78 if (buffer->summary()) { 75 if (buffer->summary()) {
79 return QString::fromStdString(buffer->summary()->c_str()); 76 return QString::fromStdString(buffer->summary()->c_str());
80 } 77 }
81 return QVariant(); 78 return QVariant();
82 }); 79 });
83 mLocalMapper->mReadAccessors.insert("uid", [](Akonadi2::Domain::Buffer::Event const *buffer) -> QVariant { 80 mLocalMapper->mReadAccessors.insert("uid", [](Akonadi2::ApplicationDomain::Buffer::Event const *buffer) -> QVariant {
84 if (buffer->uid()) { 81 if (buffer->uid()) {
85 return QString::fromStdString(buffer->uid()->c_str()); 82 return QString::fromStdString(buffer->uid()->c_str());
86 } 83 }
@@ -90,10 +87,10 @@ DummyEventAdaptorFactory::DummyEventAdaptorFactory()
90} 87}
91 88
92//TODO pass EntityBuffer instead? 89//TODO pass EntityBuffer instead?
93QSharedPointer<Akonadi2::Domain::BufferAdaptor> DummyEventAdaptorFactory::createAdaptor(const Akonadi2::Entity &entity) 90QSharedPointer<Akonadi2::ApplicationDomain::BufferAdaptor> DummyEventAdaptorFactory::createAdaptor(const Akonadi2::Entity &entity)
94{ 91{
95 const auto resourceBuffer = Akonadi2::EntityBuffer::readBuffer<DummyEvent>(entity.resource()); 92 const auto resourceBuffer = Akonadi2::EntityBuffer::readBuffer<DummyEvent>(entity.resource());
96 const auto localBuffer = Akonadi2::EntityBuffer::readBuffer<Akonadi2::Domain::Buffer::Event>(entity.local()); 93 const auto localBuffer = Akonadi2::EntityBuffer::readBuffer<Akonadi2::ApplicationDomain::Buffer::Event>(entity.local());
97 // const auto metadataBuffer = Akonadi2::EntityBuffer::readBuffer<Akonadi2::Metadata>(entity.metadata()); 94 // const auto metadataBuffer = Akonadi2::EntityBuffer::readBuffer<Akonadi2::Metadata>(entity.metadata());
98 95
99 auto adaptor = QSharedPointer<DummyEventAdaptor>::create(); 96 auto adaptor = QSharedPointer<DummyEventAdaptor>::create();
@@ -104,7 +101,7 @@ QSharedPointer<Akonadi2::Domain::BufferAdaptor> DummyEventAdaptorFactory::create
104 return adaptor; 101 return adaptor;
105} 102}
106 103
107void DummyEventAdaptorFactory::createBuffer(const Akonadi2::Domain::Event &event, flatbuffers::FlatBufferBuilder &fbb) 104void DummyEventAdaptorFactory::createBuffer(const Akonadi2::ApplicationDomain::Event &event, flatbuffers::FlatBufferBuilder &fbb)
108{ 105{
109 flatbuffers::FlatBufferBuilder eventFbb; 106 flatbuffers::FlatBufferBuilder eventFbb;
110 eventFbb.Clear(); 107 eventFbb.Clear();
@@ -119,10 +116,10 @@ void DummyEventAdaptorFactory::createBuffer(const Akonadi2::Domain::Event &event
119 flatbuffers::FlatBufferBuilder localFbb; 116 flatbuffers::FlatBufferBuilder localFbb;
120 { 117 {
121 auto uid = localFbb.CreateString(event.getProperty("uid").toString().toStdString()); 118 auto uid = localFbb.CreateString(event.getProperty("uid").toString().toStdString());
122 auto localBuilder = Akonadi2::Domain::Buffer::EventBuilder(localFbb); 119 auto localBuilder = Akonadi2::ApplicationDomain::Buffer::EventBuilder(localFbb);
123 localBuilder.add_uid(uid); 120 localBuilder.add_uid(uid);
124 auto location = localBuilder.Finish(); 121 auto location = localBuilder.Finish();
125 Akonadi2::Domain::Buffer::FinishEventBuffer(localFbb, location); 122 Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location);
126 } 123 }
127 124
128 Akonadi2::EntityBuffer::assembleEntityBuffer(fbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); 125 Akonadi2::EntityBuffer::assembleEntityBuffer(fbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize());
diff --git a/dummyresource/domainadaptor.h b/dummyresource/domainadaptor.h
index a2fb8a9..143121a 100644
--- a/dummyresource/domainadaptor.h
+++ b/dummyresource/domainadaptor.h
@@ -5,11 +5,11 @@
5#include "dummycalendar_generated.h" 5#include "dummycalendar_generated.h"
6#include "entity_generated.h" 6#include "entity_generated.h"
7 7
8class DummyEventAdaptorFactory : public DomainTypeAdaptorFactory<Akonadi2::Domain::Event, Akonadi2::Domain::Buffer::Event, DummyCalendar::DummyEvent> 8class DummyEventAdaptorFactory : public DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, DummyCalendar::DummyEvent>
9{ 9{
10public: 10public:
11 DummyEventAdaptorFactory(); 11 DummyEventAdaptorFactory();
12 virtual ~DummyEventAdaptorFactory() {}; 12 virtual ~DummyEventAdaptorFactory() {};
13 virtual QSharedPointer<Akonadi2::Domain::BufferAdaptor> createAdaptor(const Akonadi2::Entity &entity); 13 virtual QSharedPointer<Akonadi2::ApplicationDomain::BufferAdaptor> createAdaptor(const Akonadi2::Entity &entity);
14 virtual void createBuffer(const Akonadi2::Domain::Event &event, flatbuffers::FlatBufferBuilder &fbb); 14 virtual void createBuffer(const Akonadi2::ApplicationDomain::Event &event, flatbuffers::FlatBufferBuilder &fbb);
15}; 15};
diff --git a/dummyresource/facade.cpp b/dummyresource/facade.cpp
index 7c64675..980833f 100644
--- a/dummyresource/facade.cpp
+++ b/dummyresource/facade.cpp
@@ -38,7 +38,7 @@ using namespace flatbuffers;
38 38
39 39
40DummyResourceFacade::DummyResourceFacade() 40DummyResourceFacade::DummyResourceFacade()
41 : Akonadi2::GenericFacade<Akonadi2::Domain::Event>("org.kde.dummy"), 41 : Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event>("org.kde.dummy"),
42 mFactory(new DummyEventAdaptorFactory) 42 mFactory(new DummyEventAdaptorFactory)
43{ 43{
44} 44}
@@ -47,30 +47,30 @@ DummyResourceFacade::~DummyResourceFacade()
47{ 47{
48} 48}
49 49
50Async::Job<void> DummyResourceFacade::create(const Akonadi2::Domain::Event &domainObject) 50Async::Job<void> DummyResourceFacade::create(const Akonadi2::ApplicationDomain::Event &domainObject)
51{ 51{
52 flatbuffers::FlatBufferBuilder entityFbb; 52 flatbuffers::FlatBufferBuilder entityFbb;
53 mFactory->createBuffer(domainObject, entityFbb); 53 mFactory->createBuffer(domainObject, entityFbb);
54 return sendCreateCommand("event", QByteArray::fromRawData(reinterpret_cast<const char*>(entityFbb.GetBufferPointer()), entityFbb.GetSize())); 54 return sendCreateCommand("event", QByteArray::fromRawData(reinterpret_cast<const char*>(entityFbb.GetBufferPointer()), entityFbb.GetSize()));
55} 55}
56 56
57Async::Job<void> DummyResourceFacade::modify(const Akonadi2::Domain::Event &domainObject) 57Async::Job<void> DummyResourceFacade::modify(const Akonadi2::ApplicationDomain::Event &domainObject)
58{ 58{
59 //Create message buffer and send to resource 59 //Create message buffer and send to resource
60 return Async::null<void>(); 60 return Async::null<void>();
61} 61}
62 62
63Async::Job<void> DummyResourceFacade::remove(const Akonadi2::Domain::Event &domainObject) 63Async::Job<void> DummyResourceFacade::remove(const Akonadi2::ApplicationDomain::Event &domainObject)
64{ 64{
65 //Create message buffer and send to resource 65 //Create message buffer and send to resource
66 return Async::null<void>(); 66 return Async::null<void>();
67} 67}
68 68
69static std::function<bool(const std::string &key, DummyEvent const *buffer, Akonadi2::Domain::Buffer::Event const *local)> prepareQuery(const Akonadi2::Query &query) 69static std::function<bool(const std::string &key, DummyEvent const *buffer, Akonadi2::ApplicationDomain::Buffer::Event const *local)> prepareQuery(const Akonadi2::Query &query)
70{ 70{
71 //Compose some functions to make query matching fast. 71 //Compose some functions to make query matching fast.
72 //This way we can process the query once, and convert all values into something that can be compared quickly 72 //This way we can process the query once, and convert all values into something that can be compared quickly
73 std::function<bool(const std::string &key, DummyEvent const *buffer, Akonadi2::Domain::Buffer::Event const *local)> preparedQuery; 73 std::function<bool(const std::string &key, DummyEvent const *buffer, Akonadi2::ApplicationDomain::Buffer::Event const *local)> preparedQuery;
74 if (!query.ids.isEmpty()) { 74 if (!query.ids.isEmpty()) {
75 //Match by id 75 //Match by id
76 //TODO: for id's a direct lookup would be way faster 76 //TODO: for id's a direct lookup would be way faster
@@ -81,7 +81,7 @@ static std::function<bool(const std::string &key, DummyEvent const *buffer, Akon
81 for (const auto &id : query.ids) { 81 for (const auto &id : query.ids) {
82 ids << id.toStdString(); 82 ids << id.toStdString();
83 } 83 }
84 preparedQuery = [ids](const std::string &key, DummyEvent const *buffer, Akonadi2::Domain::Buffer::Event const *local) { 84 preparedQuery = [ids](const std::string &key, DummyEvent const *buffer, Akonadi2::ApplicationDomain::Buffer::Event const *local) {
85 if (ids.contains(key)) { 85 if (ids.contains(key)) {
86 return true; 86 return true;
87 } 87 }
@@ -90,7 +90,7 @@ static std::function<bool(const std::string &key, DummyEvent const *buffer, Akon
90 } else if (!query.propertyFilter.isEmpty()) { 90 } else if (!query.propertyFilter.isEmpty()) {
91 if (query.propertyFilter.contains("uid")) { 91 if (query.propertyFilter.contains("uid")) {
92 const QByteArray uid = query.propertyFilter.value("uid").toByteArray(); 92 const QByteArray uid = query.propertyFilter.value("uid").toByteArray();
93 preparedQuery = [uid](const std::string &key, DummyEvent const *buffer, Akonadi2::Domain::Buffer::Event const *local) { 93 preparedQuery = [uid](const std::string &key, DummyEvent const *buffer, Akonadi2::ApplicationDomain::Buffer::Event const *local) {
94 if (local && local->uid() && (QByteArray::fromRawData(local->uid()->c_str(), local->uid()->size()) == uid)) { 94 if (local && local->uid() && (QByteArray::fromRawData(local->uid()->c_str(), local->uid()->size()) == uid)) {
95 return true; 95 return true;
96 } 96 }
@@ -99,14 +99,14 @@ static std::function<bool(const std::string &key, DummyEvent const *buffer, Akon
99 } 99 }
100 } else { 100 } else {
101 //Match everything 101 //Match everything
102 preparedQuery = [](const std::string &key, DummyEvent const *buffer, Akonadi2::Domain::Buffer::Event const *local) { 102 preparedQuery = [](const std::string &key, DummyEvent const *buffer, Akonadi2::ApplicationDomain::Buffer::Event const *local) {
103 return true; 103 return true;
104 }; 104 };
105 } 105 }
106 return preparedQuery; 106 return preparedQuery;
107} 107}
108 108
109void DummyResourceFacade::readValue(QSharedPointer<Akonadi2::Storage> storage, const QByteArray &key, const std::function<void(const Akonadi2::Domain::Event::Ptr &)> &resultCallback, std::function<bool(const std::string &key, DummyEvent const *buffer, Akonadi2::Domain::Buffer::Event const *local)> preparedQuery) 109void DummyResourceFacade::readValue(QSharedPointer<Akonadi2::Storage> storage, const QByteArray &key, const std::function<void(const Akonadi2::ApplicationDomain::Event::Ptr &)> &resultCallback, std::function<bool(const std::string &key, DummyEvent const *buffer, Akonadi2::ApplicationDomain::Buffer::Event const *local)> preparedQuery)
110{ 110{
111 storage->scan(key, [=](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { 111 storage->scan(key, [=](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool {
112 112
@@ -119,7 +119,7 @@ void DummyResourceFacade::readValue(QSharedPointer<Akonadi2::Storage> storage, c
119 Akonadi2::EntityBuffer buffer(dataValue, dataSize); 119 Akonadi2::EntityBuffer buffer(dataValue, dataSize);
120 120
121 const auto resourceBuffer = Akonadi2::EntityBuffer::readBuffer<DummyEvent>(buffer.entity().resource()); 121 const auto resourceBuffer = Akonadi2::EntityBuffer::readBuffer<DummyEvent>(buffer.entity().resource());
122 const auto localBuffer = Akonadi2::EntityBuffer::readBuffer<Akonadi2::Domain::Buffer::Event>(buffer.entity().local()); 122 const auto localBuffer = Akonadi2::EntityBuffer::readBuffer<Akonadi2::ApplicationDomain::Buffer::Event>(buffer.entity().local());
123 const auto metadataBuffer = Akonadi2::EntityBuffer::readBuffer<Akonadi2::Metadata>(buffer.entity().metadata()); 123 const auto metadataBuffer = Akonadi2::EntityBuffer::readBuffer<Akonadi2::Metadata>(buffer.entity().metadata());
124 124
125 if (!resourceBuffer || !metadataBuffer) { 125 if (!resourceBuffer || !metadataBuffer) {
@@ -135,8 +135,8 @@ void DummyResourceFacade::readValue(QSharedPointer<Akonadi2::Storage> storage, c
135 //Not i.e. for tags that are stored as flags in each entity of an imap store. 135 //Not i.e. for tags that are stored as flags in each entity of an imap store.
136 auto adaptor = mFactory->createAdaptor(buffer.entity()); 136 auto adaptor = mFactory->createAdaptor(buffer.entity());
137 //TODO only copy requested properties 137 //TODO only copy requested properties
138 auto memoryAdaptor = QSharedPointer<Akonadi2::Domain::MemoryBufferAdaptor>::create(*adaptor); 138 auto memoryAdaptor = QSharedPointer<Akonadi2::ApplicationDomain::MemoryBufferAdaptor>::create(*adaptor);
139 auto event = QSharedPointer<Akonadi2::Domain::Event>::create("org.kde.dummy", QByteArray::fromRawData(static_cast<char*>(keyValue), keySize), revision, memoryAdaptor); 139 auto event = QSharedPointer<Akonadi2::ApplicationDomain::Event>::create("org.kde.dummy", QByteArray::fromRawData(static_cast<char*>(keyValue), keySize), revision, memoryAdaptor);
140 resultCallback(event); 140 resultCallback(event);
141 } 141 }
142 return true; 142 return true;
@@ -146,7 +146,7 @@ void DummyResourceFacade::readValue(QSharedPointer<Akonadi2::Storage> storage, c
146 }); 146 });
147} 147}
148 148
149Async::Job<void> DummyResourceFacade::load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::Domain::Event::Ptr &)> &resultCallback) 149Async::Job<void> DummyResourceFacade::load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::ApplicationDomain::Event::Ptr &)> &resultCallback)
150{ 150{
151 return synchronizeResource(query.syncOnDemand, query.processAll).then<void>([=](Async::Future<void> &future) { 151 return synchronizeResource(query.syncOnDemand, query.processAll).then<void>([=](Async::Future<void> &future) {
152 //Now that the sync is complete we can execute the query 152 //Now that the sync is complete we can execute the query
@@ -154,6 +154,7 @@ Async::Job<void> DummyResourceFacade::load(const Akonadi2::Query &query, const s
154 154
155 auto storage = QSharedPointer<Akonadi2::Storage>::create(Akonadi2::Store::storageLocation(), "org.kde.dummy"); 155 auto storage = QSharedPointer<Akonadi2::Storage>::create(Akonadi2::Store::storageLocation(), "org.kde.dummy");
156 156
157 //Index lookups
157 QVector<QByteArray> keys; 158 QVector<QByteArray> keys;
158 if (query.propertyFilter.contains("uid")) { 159 if (query.propertyFilter.contains("uid")) {
159 static Index uidIndex(Akonadi2::Store::storageLocation(), "org.kde.dummy.index.uid", Akonadi2::Storage::ReadOnly); 160 static Index uidIndex(Akonadi2::Store::storageLocation(), "org.kde.dummy.index.uid", Akonadi2::Storage::ReadOnly);
diff --git a/dummyresource/facade.h b/dummyresource/facade.h
index 195c50f..7bef2cc 100644
--- a/dummyresource/facade.h
+++ b/dummyresource/facade.h
@@ -29,17 +29,17 @@
29#include "dummycalendar_generated.h" 29#include "dummycalendar_generated.h"
30#include "common/domainadaptor.h" 30#include "common/domainadaptor.h"
31 31
32class DummyResourceFacade : public Akonadi2::GenericFacade<Akonadi2::Domain::Event> 32class DummyResourceFacade : public Akonadi2::GenericFacade<Akonadi2::ApplicationDomain::Event>
33{ 33{
34public: 34public:
35 DummyResourceFacade(); 35 DummyResourceFacade();
36 virtual ~DummyResourceFacade(); 36 virtual ~DummyResourceFacade();
37 virtual Async::Job<void> create(const Akonadi2::Domain::Event &domainObject); 37 virtual Async::Job<void> create(const Akonadi2::ApplicationDomain::Event &domainObject);
38 virtual Async::Job<void> modify(const Akonadi2::Domain::Event &domainObject); 38 virtual Async::Job<void> modify(const Akonadi2::ApplicationDomain::Event &domainObject);
39 virtual Async::Job<void> remove(const Akonadi2::Domain::Event &domainObject); 39 virtual Async::Job<void> remove(const Akonadi2::ApplicationDomain::Event &domainObject);
40 virtual Async::Job<void> load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::Domain::Event::Ptr &)> &resultCallback); 40 virtual Async::Job<void> load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::ApplicationDomain::Event::Ptr &)> &resultCallback);
41 41
42private: 42private:
43 void readValue(QSharedPointer<Akonadi2::Storage> storage, const QByteArray &key, const std::function<void(const Akonadi2::Domain::Event::Ptr &)> &resultCallback, std::function<bool(const std::string &key, DummyCalendar::DummyEvent const *buffer, Akonadi2::Domain::Buffer::Event const *local)>); 43 void readValue(QSharedPointer<Akonadi2::Storage> storage, const QByteArray &key, const std::function<void(const Akonadi2::ApplicationDomain::Event::Ptr &)> &resultCallback, std::function<bool(const std::string &key, DummyCalendar::DummyEvent const *buffer, Akonadi2::ApplicationDomain::Buffer::Event const *local)>);
44 QSharedPointer<DomainTypeAdaptorFactory<Akonadi2::Domain::Event, Akonadi2::Domain::Buffer::Event, DummyCalendar::DummyEvent> > mFactory; 44 QSharedPointer<DomainTypeAdaptorFactory<Akonadi2::ApplicationDomain::Event, Akonadi2::ApplicationDomain::Buffer::Event, DummyCalendar::DummyEvent> > mFactory;
45}; 45};
diff --git a/dummyresource/resourcefactory.cpp b/dummyresource/resourcefactory.cpp
index ea37466..04413c2 100644
--- a/dummyresource/resourcefactory.cpp
+++ b/dummyresource/resourcefactory.cpp
@@ -416,7 +416,7 @@ Akonadi2::Resource *DummyResourceFactory::createResource()
416 416
417void DummyResourceFactory::registerFacades(Akonadi2::FacadeFactory &factory) 417void DummyResourceFactory::registerFacades(Akonadi2::FacadeFactory &factory)
418{ 418{
419 factory.registerFacade<Akonadi2::Domain::Event, DummyResourceFacade>(PLUGIN_NAME); 419 factory.registerFacade<Akonadi2::ApplicationDomain::Event, DummyResourceFacade>(PLUGIN_NAME);
420} 420}
421 421
422#include "resourcefactory.moc" 422#include "resourcefactory.moc"