diff options
Diffstat (limited to 'dummyresource/facade.cpp')
-rw-r--r-- | dummyresource/facade.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
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 | ||
40 | DummyResourceFacade::DummyResourceFacade() | 40 | DummyResourceFacade::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 | ||
50 | Async::Job<void> DummyResourceFacade::create(const Akonadi2::Domain::Event &domainObject) | 50 | Async::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 | ||
57 | Async::Job<void> DummyResourceFacade::modify(const Akonadi2::Domain::Event &domainObject) | 57 | Async::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 | ||
63 | Async::Job<void> DummyResourceFacade::remove(const Akonadi2::Domain::Event &domainObject) | 63 | Async::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 | ||
69 | static std::function<bool(const std::string &key, DummyEvent const *buffer, Akonadi2::Domain::Buffer::Event const *local)> prepareQuery(const Akonadi2::Query &query) | 69 | static 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 | ||
109 | void 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) | 109 | void 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 | ||
149 | Async::Job<void> DummyResourceFacade::load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::Domain::Event::Ptr &)> &resultCallback) | 149 | Async::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); |