diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-04-09 14:23:16 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-04-09 14:23:16 +0200 |
commit | 855e3d7d0e3779e76e5af55bbf4c851acbd76e56 (patch) | |
tree | 11f93ef8661b1e39b9c66ddb395ddb84204c849c /dummyresource/facade.cpp | |
parent | 3062983d075761c457249b8c3c1248aa0d45e46a (diff) | |
download | sink-855e3d7d0e3779e76e5af55bbf4c851acbd76e56.tar.gz sink-855e3d7d0e3779e76e5af55bbf4c851acbd76e56.zip |
Started a facade base implementation.
Diffstat (limited to 'dummyresource/facade.cpp')
-rw-r--r-- | dummyresource/facade.cpp | 34 |
1 files changed, 3 insertions, 31 deletions
diff --git a/dummyresource/facade.cpp b/dummyresource/facade.cpp index 1af735e..209ad0d 100644 --- a/dummyresource/facade.cpp +++ b/dummyresource/facade.cpp | |||
@@ -28,7 +28,6 @@ | |||
28 | #include "event_generated.h" | 28 | #include "event_generated.h" |
29 | #include "entity_generated.h" | 29 | #include "entity_generated.h" |
30 | #include "metadata_generated.h" | 30 | #include "metadata_generated.h" |
31 | #include "createentity_generated.h" | ||
32 | #include "domainadaptor.h" | 31 | #include "domainadaptor.h" |
33 | #include <common/entitybuffer.h> | 32 | #include <common/entitybuffer.h> |
34 | #include <common/index.h> | 33 | #include <common/index.h> |
@@ -37,9 +36,9 @@ | |||
37 | using namespace DummyCalendar; | 36 | using namespace DummyCalendar; |
38 | using namespace flatbuffers; | 37 | using namespace flatbuffers; |
39 | 38 | ||
39 | |||
40 | DummyResourceFacade::DummyResourceFacade() | 40 | DummyResourceFacade::DummyResourceFacade() |
41 | : Akonadi2::StoreFacade<Akonadi2::Domain::Event>(), | 41 | : Akonadi2::GenericFacade<Akonadi2::Domain::Event>("org.kde.dummy"), |
42 | mResourceAccess(new Akonadi2::ResourceAccess("org.kde.dummy")), | ||
43 | mFactory(new DummyEventAdaptorFactory) | 42 | mFactory(new DummyEventAdaptorFactory) |
44 | { | 43 | { |
45 | } | 44 | } |
@@ -52,15 +51,7 @@ Async::Job<void> DummyResourceFacade::create(const Akonadi2::Domain::Event &doma | |||
52 | { | 51 | { |
53 | flatbuffers::FlatBufferBuilder entityFbb; | 52 | flatbuffers::FlatBufferBuilder entityFbb; |
54 | mFactory->createBuffer(domainObject, entityFbb); | 53 | mFactory->createBuffer(domainObject, entityFbb); |
55 | 54 | return sendCreateCommand("event", QByteArray::fromRawData(reinterpret_cast<const char*>(entityFbb.GetBufferPointer()), entityFbb.GetSize())); | |
56 | flatbuffers::FlatBufferBuilder fbb; | ||
57 | //This is the resource buffer type and not the domain type | ||
58 | auto type = fbb.CreateString("event"); | ||
59 | auto delta = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
60 | auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta); | ||
61 | Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location); | ||
62 | mResourceAccess->open(); | ||
63 | return mResourceAccess->sendCommand(Akonadi2::Commands::CreateEntityCommand, fbb); | ||
64 | } | 55 | } |
65 | 56 | ||
66 | Async::Job<void> DummyResourceFacade::modify(const Akonadi2::Domain::Event &domainObject) | 57 | Async::Job<void> DummyResourceFacade::modify(const Akonadi2::Domain::Event &domainObject) |
@@ -115,25 +106,6 @@ static std::function<bool(const std::string &key, DummyEvent const *buffer, Akon | |||
115 | return preparedQuery; | 106 | return preparedQuery; |
116 | } | 107 | } |
117 | 108 | ||
118 | Async::Job<void> DummyResourceFacade::synchronizeResource(bool sync, bool processAll) | ||
119 | { | ||
120 | //TODO check if a sync is necessary | ||
121 | //TODO Only sync what was requested | ||
122 | //TODO timeout | ||
123 | //TODO the synchronization should normally not be necessary: We just return what is already available. | ||
124 | |||
125 | if (sync || processAll) { | ||
126 | return Async::start<void>([=](Async::Future<void> &future) { | ||
127 | mResourceAccess->open(); | ||
128 | mResourceAccess->synchronizeResource(sync, processAll).then<void>([&future](Async::Future<void> &f) { | ||
129 | future.setFinished(); | ||
130 | f.setFinished(); | ||
131 | }).exec(); | ||
132 | }); | ||
133 | } | ||
134 | return Async::null<void>(); | ||
135 | } | ||
136 | |||
137 | 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::Domain::Event::Ptr &)> &resultCallback, std::function<bool(const std::string &key, DummyEvent const *buffer, Akonadi2::Domain::Buffer::Event const *local)> preparedQuery) |
138 | { | 110 | { |
139 | 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 { |