diff options
Diffstat (limited to 'dummyresource')
-rw-r--r-- | dummyresource/facade.cpp | 23 | ||||
-rw-r--r-- | dummyresource/facade.h | 4 | ||||
-rw-r--r-- | dummyresource/resourcefactory.cpp | 4 |
3 files changed, 20 insertions, 11 deletions
diff --git a/dummyresource/facade.cpp b/dummyresource/facade.cpp index 13c174b..b7ba2c2 100644 --- a/dummyresource/facade.cpp +++ b/dummyresource/facade.cpp | |||
@@ -118,22 +118,29 @@ static std::function<bool(const std::string &key, DummyEvent const *buffer)> pre | |||
118 | return preparedQuery; | 118 | return preparedQuery; |
119 | } | 119 | } |
120 | 120 | ||
121 | void DummyResourceFacade::synchronizeResource(const std::function<void()> &continuation) | 121 | Async::Job<void> DummyResourceFacade::synchronizeResource(bool sync) |
122 | { | 122 | { |
123 | //TODO check if a sync is necessary | 123 | //TODO check if a sync is necessary |
124 | //TODO Only sync what was requested | 124 | //TODO Only sync what was requested |
125 | //TODO timeout | 125 | //TODO timeout |
126 | mResourceAccess->synchronizeResource().then<void>([continuation](Async::Future<void> &f){ | 126 | |
127 | continuation(); | 127 | if (sync) { |
128 | f.setFinished(); | 128 | return Async::start<void>([=](Async::Future<void> &future) { |
129 | }).exec(); | 129 | mResourceAccess->open(); |
130 | mResourceAccess->synchronizeResource().then<void>([&future](Async::Future<void> &f) { | ||
131 | future.setFinished(); | ||
132 | f.setFinished(); | ||
133 | }).exec(); | ||
134 | }); | ||
135 | } | ||
136 | return Async::null<void>(); | ||
130 | } | 137 | } |
131 | 138 | ||
132 | void DummyResourceFacade::load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::Domain::Event::Ptr &)> &resultCallback, const std::function<void()> &completeCallback) | 139 | Async::Job<void> DummyResourceFacade::load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::Domain::Event::Ptr &)> &resultCallback) |
133 | { | 140 | { |
134 | qDebug() << "load called"; | 141 | qDebug() << "load called"; |
135 | 142 | ||
136 | synchronizeResource([=]() { | 143 | return synchronizeResource(query.syncOnDemand).then<void>([=](Async::Future<void> &future) { |
137 | qDebug() << "sync complete"; | 144 | qDebug() << "sync complete"; |
138 | //Now that the sync is complete we can execute the query | 145 | //Now that the sync is complete we can execute the query |
139 | const auto preparedQuery = prepareQuery(query); | 146 | const auto preparedQuery = prepareQuery(query); |
@@ -188,7 +195,7 @@ void DummyResourceFacade::load(const Akonadi2::Query &query, const std::function | |||
188 | } | 195 | } |
189 | return true; | 196 | return true; |
190 | }); | 197 | }); |
191 | completeCallback(); | 198 | future.setFinished(); |
192 | }); | 199 | }); |
193 | } | 200 | } |
194 | 201 | ||
diff --git a/dummyresource/facade.h b/dummyresource/facade.h index 9c8827a..da0b1d6 100644 --- a/dummyresource/facade.h +++ b/dummyresource/facade.h | |||
@@ -40,10 +40,10 @@ public: | |||
40 | virtual Async::Job<void> create(const Akonadi2::Domain::Event &domainObject); | 40 | virtual Async::Job<void> create(const Akonadi2::Domain::Event &domainObject); |
41 | virtual Async::Job<void> modify(const Akonadi2::Domain::Event &domainObject); | 41 | virtual Async::Job<void> modify(const Akonadi2::Domain::Event &domainObject); |
42 | virtual Async::Job<void> remove(const Akonadi2::Domain::Event &domainObject); | 42 | virtual Async::Job<void> remove(const Akonadi2::Domain::Event &domainObject); |
43 | virtual void load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::Domain::Event::Ptr &)> &resultCallback, const std::function<void()> &completeCallback); | 43 | virtual Async::Job<void> load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::Domain::Event::Ptr &)> &resultCallback); |
44 | 44 | ||
45 | private: | 45 | private: |
46 | void synchronizeResource(const std::function<void()> &continuation); | 46 | Async::Job<void> synchronizeResource(bool sync); |
47 | QSharedPointer<Akonadi2::ResourceAccess> mResourceAccess; | 47 | QSharedPointer<Akonadi2::ResourceAccess> mResourceAccess; |
48 | QSharedPointer<DomainTypeAdaptorFactory<Akonadi2::Domain::Event, Akonadi2::Domain::Buffer::Event, DummyCalendar::DummyEvent> > mFactory; | 48 | QSharedPointer<DomainTypeAdaptorFactory<Akonadi2::Domain::Event, Akonadi2::Domain::Buffer::Event, DummyCalendar::DummyEvent> > mFactory; |
49 | }; | 49 | }; |
diff --git a/dummyresource/resourcefactory.cpp b/dummyresource/resourcefactory.cpp index f74eb72..dc716ef 100644 --- a/dummyresource/resourcefactory.cpp +++ b/dummyresource/resourcefactory.cpp | |||
@@ -317,7 +317,9 @@ Async::Job<void> DummyResource::synchronizeWithSource(Akonadi2::Pipeline *pipeli | |||
317 | builder.add_attachment(attachment); | 317 | builder.add_attachment(attachment); |
318 | auto buffer = builder.Finish(); | 318 | auto buffer = builder.Finish(); |
319 | DummyCalendar::FinishDummyEventBuffer(m_fbb, buffer); | 319 | DummyCalendar::FinishDummyEventBuffer(m_fbb, buffer); |
320 | enqueueCommand(mSynchronizerQueue, Akonadi2::Commands::CreateEntityCommand, QByteArray::fromRawData(reinterpret_cast<char const *>(m_fbb.GetBufferPointer()), m_fbb.GetSize())); | 320 | flatbuffers::FlatBufferBuilder entityFbb; |
321 | Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, m_fbb.GetBufferPointer(), m_fbb.GetSize(), 0, 0); | ||
322 | enqueueCommand(mSynchronizerQueue, Akonadi2::Commands::CreateEntityCommand, QByteArray::fromRawData(reinterpret_cast<char const *>(entityFbb.GetBufferPointer()), entityFbb.GetSize())); | ||
321 | } else { //modification | 323 | } else { //modification |
322 | //TODO diff and create modification if necessary | 324 | //TODO diff and create modification if necessary |
323 | } | 325 | } |