diff options
Diffstat (limited to 'dummyresource')
-rw-r--r-- | dummyresource/facade.cpp | 44 | ||||
-rw-r--r-- | dummyresource/facade.h | 9 |
2 files changed, 46 insertions, 7 deletions
diff --git a/dummyresource/facade.cpp b/dummyresource/facade.cpp index 1477fcf..f603c56 100644 --- a/dummyresource/facade.cpp +++ b/dummyresource/facade.cpp | |||
@@ -147,15 +147,51 @@ void DummyResourceFacade::readValue(QSharedPointer<Akonadi2::Storage> storage, c | |||
147 | }); | 147 | }); |
148 | } | 148 | } |
149 | 149 | ||
150 | Async::Job<void> DummyResourceFacade::load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::ApplicationDomain::Event::Ptr &)> &resultCallback) | 150 | Async::Job<void> DummyResourceFacade::load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider) |
151 | { | 151 | { |
152 | return synchronizeResource(query.syncOnDemand, query.processAll).then<void>([=](Async::Future<void> &future) { | 152 | auto runner = QSharedPointer<QueryRunner>::create(query); |
153 | //The runner only lives as long as the resultProvider | ||
154 | resultProvider->setQueryRunner(runner); | ||
155 | runner->setQuery([this, resultProvider, query](qint64 oldRevision, qint64 newRevision) -> Async::Job<qint64> { | ||
156 | return Async::start<qint64>([this, resultProvider, query](Async::Future<qint64> &future) { | ||
157 | //TODO only emit changes and don't replace everything | ||
158 | resultProvider->clear(); | ||
159 | //rerun query | ||
160 | std::function<void(const Akonadi2::ApplicationDomain::Event::Ptr &)> addCallback = std::bind(&Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr>::add, resultProvider, std::placeholders::_1); | ||
161 | load(query, addCallback).then<void, qint64>([resultProvider, &future](qint64 queriedRevision) { | ||
162 | //TODO set revision in result provider? | ||
163 | //TODO update all existing results with new revision | ||
164 | resultProvider->complete(); | ||
165 | future.setValue(queriedRevision); | ||
166 | future.setFinished(); | ||
167 | }).exec(); | ||
168 | }); | ||
169 | }); | ||
170 | |||
171 | auto resourceAccess = mResourceAccess; | ||
172 | //TODO we need to somehow disconnect this | ||
173 | QObject::connect(resourceAccess.data(), &Akonadi2::ResourceAccess::revisionChanged, [runner](qint64 newRevision) { | ||
174 | runner->revisionChanged(newRevision); | ||
175 | }); | ||
176 | |||
177 | return Async::start<void>([runner](Async::Future<void> &future) { | ||
178 | runner->run().then<void>([&future]() { | ||
179 | //TODO if not live query, destroy runner. | ||
180 | future.setFinished(); | ||
181 | }).exec(); | ||
182 | }); | ||
183 | } | ||
184 | |||
185 | Async::Job<qint64> DummyResourceFacade::load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::ApplicationDomain::Event::Ptr &)> &resultCallback) | ||
186 | { | ||
187 | return synchronizeResource(query.syncOnDemand, query.processAll).then<qint64>([=](Async::Future<qint64> &future) { | ||
153 | //Now that the sync is complete we can execute the query | 188 | //Now that the sync is complete we can execute the query |
154 | const auto preparedQuery = prepareQuery(query); | 189 | const auto preparedQuery = prepareQuery(query); |
155 | 190 | ||
156 | auto storage = QSharedPointer<Akonadi2::Storage>::create(Akonadi2::Store::storageLocation(), "org.kde.dummy"); | 191 | auto storage = QSharedPointer<Akonadi2::Storage>::create(Akonadi2::Store::storageLocation(), "org.kde.dummy"); |
157 | 192 | ||
158 | //TODO use transaction over full query and record store revision. We'll need it to update the query. | 193 | storage->startTransaction(Akonadi2::Storage::ReadOnly); |
194 | const qint64 revision = storage->maxRevision(); | ||
159 | 195 | ||
160 | //Index lookups | 196 | //Index lookups |
161 | QVector<QByteArray> keys; | 197 | QVector<QByteArray> keys; |
@@ -177,6 +213,8 @@ Async::Job<void> DummyResourceFacade::load(const Akonadi2::Query &query, const s | |||
177 | readValue(storage, key, resultCallback, preparedQuery); | 213 | readValue(storage, key, resultCallback, preparedQuery); |
178 | } | 214 | } |
179 | } | 215 | } |
216 | storage->abortTransaction(); | ||
217 | future.setValue(revision); | ||
180 | future.setFinished(); | 218 | future.setFinished(); |
181 | }); | 219 | }); |
182 | } | 220 | } |
diff --git a/dummyresource/facade.h b/dummyresource/facade.h index 37ed81d..3ddfe15 100644 --- a/dummyresource/facade.h +++ b/dummyresource/facade.h | |||
@@ -34,10 +34,11 @@ class DummyResourceFacade : public Akonadi2::GenericFacade<Akonadi2::Application | |||
34 | public: | 34 | public: |
35 | DummyResourceFacade(); | 35 | DummyResourceFacade(); |
36 | virtual ~DummyResourceFacade(); | 36 | virtual ~DummyResourceFacade(); |
37 | virtual Async::Job<void> create(const Akonadi2::ApplicationDomain::Event &domainObject); | 37 | Async::Job<void> create(const Akonadi2::ApplicationDomain::Event &domainObject) Q_DECL_OVERRIDE; |
38 | virtual Async::Job<void> modify(const Akonadi2::ApplicationDomain::Event &domainObject); | 38 | Async::Job<void> modify(const Akonadi2::ApplicationDomain::Event &domainObject) Q_DECL_OVERRIDE; |
39 | virtual Async::Job<void> remove(const Akonadi2::ApplicationDomain::Event &domainObject); | 39 | Async::Job<void> remove(const Akonadi2::ApplicationDomain::Event &domainObject) Q_DECL_OVERRIDE; |
40 | virtual Async::Job<void> load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::ApplicationDomain::Event::Ptr &)> &resultCallback); | 40 | Async::Job<qint64> load(const Akonadi2::Query &query, const std::function<void(const Akonadi2::ApplicationDomain::Event::Ptr &)> &resultCallback) Q_DECL_OVERRIDE; |
41 | Async::Job<void> load(const Akonadi2::Query &query, const QSharedPointer<Akonadi2::ResultProvider<Akonadi2::ApplicationDomain::Event::Ptr> > &resultProvider) Q_DECL_OVERRIDE; | ||
41 | 42 | ||
42 | private: | 43 | private: |
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 | 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)>); |