summaryrefslogtreecommitdiffstats
path: root/common/resultprovider.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-11-13 23:31:41 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-11-13 23:31:41 +0100
commit75c231f0758603120ec562af772b48b5f6ac0e24 (patch)
tree39abf8f038bd379ee3c0640a7476e6129ed71f8c /common/resultprovider.h
parent09aafbd1373b5d1152ac7a453a140a7f76c2e90e (diff)
downloadsink-75c231f0758603120ec562af772b48b5f6ac0e24.tar.gz
sink-75c231f0758603120ec562af772b48b5f6ac0e24.zip
DummyResourceTest and QueryTest are passing
sync has been removed from the query code and is now a separate step
Diffstat (limited to 'common/resultprovider.h')
-rw-r--r--common/resultprovider.h189
1 files changed, 14 insertions, 175 deletions
diff --git a/common/resultprovider.h b/common/resultprovider.h
index 43d21a4..0d23127 100644
--- a/common/resultprovider.h
+++ b/common/resultprovider.h
@@ -23,6 +23,9 @@
23#include <functional> 23#include <functional>
24#include <memory> 24#include <memory>
25#include "threadboundary.h" 25#include "threadboundary.h"
26#include "resultset.h"
27#include "log.h"
28#include "modelresult.h"
26 29
27using namespace async; 30using namespace async;
28 31
@@ -117,18 +120,6 @@ public:
117 // mResultEmitter->clear(); 120 // mResultEmitter->clear();
118 } 121 }
119 122
120 // QSharedPointer<ResultEmitter<T> > emitter()
121 // {
122 // if (!mResultEmitter) {
123 // //We have to go over a separate var and return that, otherwise we'd delete the emitter immediately again
124 // auto sharedPtr = QSharedPointer<ResultEmitter<T> >(new ResultEmitter<T>, [this](ResultEmitter<T> *emitter){ done(); delete emitter; });
125 // mResultEmitter = sharedPtr;
126 // return sharedPtr;
127 // }
128 //
129 // return mResultEmitter.toStrongRef();
130 // }
131
132 /** 123 /**
133 * For lifetimemanagement only. 124 * For lifetimemanagement only.
134 * We keep the runner alive as long as the result provider exists. 125 * We keep the runner alive as long as the result provider exists.
@@ -162,40 +153,6 @@ public:
162 mQueryRunner = runner; 153 mQueryRunner = runner;
163 } 154 }
164 155
165 // qint64 fetch(const ResultSet &resultSet)
166 // {
167 // //Fetch a bunch
168 // //
169 // // Akonadi2::Storage storage(Akonadi2::storageLocation(), mResourceInstanceIdentifier);
170 // // storage.setDefaultErrorHandler([](const Akonadi2::Storage::Error &error) {
171 // // Warning() << "Error during query: " << error.store << error.message;
172 // // });
173 // //
174 // // auto transaction = storage.createTransaction(Akonadi2::Storage::ReadOnly);
175 //
176 // // Log() << "Querying" << baseRevision << Akonadi2::Storage::maxRevision(transaction);
177 // // auto resultSet = getResultSet(query, transaction, baseRevision);
178 // while (resultSet.next([this](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &value, Akonadi2::Operation operation) -> bool {
179 // switch (operation) {
180 // case Akonadi2::Operation_Creation:
181 // Trace() << "Got creation";
182 // //TODO Only copy in result provider
183 // add(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<T>(*value).template staticCast<T>());
184 // break;
185 // case Akonadi2::Operation_Modification:
186 // Trace() << "Got modification";
187 // modify(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<T>(*value).template staticCast<T>());
188 // break;
189 // case Akonadi2::Operation_Removal:
190 // Trace() << "Got removal";
191 // remove(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<T>(*value).template staticCast<T>());
192 // break;
193 // }
194 // return true;
195 // })){};
196 // // return Akonadi2::Storage::maxRevision(transaction);
197 // }
198
199private: 156private:
200 void done() 157 void done()
201 { 158 {
@@ -212,129 +169,6 @@ private:
212 std::function<void()> mOnDoneCallback; 169 std::function<void()> mOnDoneCallback;
213}; 170};
214 171
215
216
217
218
219
220template<class T>
221class SyncResultProvider : public ResultProviderInterface<T> {
222public:
223 void add(const T &value)
224 {
225 mResultEmitter->addHandler(value);
226 }
227
228 void modify(const T &value)
229 {
230 mResultEmitter->modifyHandler(value);
231 }
232
233 void remove(const T &value)
234 {
235 mResultEmitter->removeHandler(value);
236 }
237
238 void initialResultSetComplete()
239 {
240 mResultEmitter->initialResultSetComplete();
241 }
242
243 void complete()
244 {
245 mResultEmitter->complete();
246 }
247
248 void clear()
249 {
250 mResultEmitter->clear();
251 }
252
253 QSharedPointer<ResultEmitter<T> > emitter()
254 {
255 if (!mResultEmitter) {
256 //We have to go over a separate var and return that, otherwise we'd delete the emitter immediately again
257 auto sharedPtr = QSharedPointer<ResultEmitter<T> >(new ResultEmitter<T>, [this](ResultEmitter<T> *emitter){ done(); delete emitter; });
258 mResultEmitter = sharedPtr;
259 return sharedPtr;
260 }
261
262 return mResultEmitter.toStrongRef();
263 }
264
265 /**
266 * For lifetimemanagement only.
267 * We keep the runner alive as long as the result provider exists.
268 */
269 void setFacade(const std::shared_ptr<void> &facade)
270 {
271 mFacade = facade;
272 }
273
274 void onDone(const std::function<void()> &callback)
275 {
276 mOnDoneCallback = callback;
277 }
278
279 bool isDone() const
280 {
281 //The existance of the emitter currently defines wether we're done or not.
282 return mResultEmitter.toStrongRef().isNull();
283 }
284
285 // qint64 fetch(const ResultSet &resultSet)
286 // {
287 // //Fetch a bunch
288 // //
289 // // Akonadi2::Storage storage(Akonadi2::storageLocation(), mResourceInstanceIdentifier);
290 // // storage.setDefaultErrorHandler([](const Akonadi2::Storage::Error &error) {
291 // // Warning() << "Error during query: " << error.store << error.message;
292 // // });
293 // //
294 // // auto transaction = storage.createTransaction(Akonadi2::Storage::ReadOnly);
295 //
296 // // Log() << "Querying" << baseRevision << Akonadi2::Storage::maxRevision(transaction);
297 // // auto resultSet = getResultSet(query, transaction, baseRevision);
298 // while (resultSet.next([this](const Akonadi2::ApplicationDomain::ApplicationDomainType::Ptr &value, Akonadi2::Operation operation) -> bool {
299 // switch (operation) {
300 // case Akonadi2::Operation_Creation:
301 // Trace() << "Got creation";
302 // //TODO Only copy in result provider
303 // add(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<T>(*value).template staticCast<T>());
304 // break;
305 // case Akonadi2::Operation_Modification:
306 // Trace() << "Got modification";
307 // modify(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<T>(*value).template staticCast<T>());
308 // break;
309 // case Akonadi2::Operation_Removal:
310 // Trace() << "Got removal";
311 // remove(Akonadi2::ApplicationDomain::ApplicationDomainType::getInMemoryRepresentation<T>(*value).template staticCast<T>());
312 // break;
313 // }
314 // return true;
315 // })){};
316 // // return Akonadi2::Storage::maxRevision(transaction);
317 // }
318
319private:
320 void done()
321 {
322 qWarning() << "done";
323 if (mOnDoneCallback) {
324 mOnDoneCallback();
325 mOnDoneCallback = std::function<void()>();
326 }
327 }
328
329 QWeakPointer<ResultEmitter<T> > mResultEmitter;
330 std::shared_ptr<void> mFacade;
331 std::function<void()> mOnDoneCallback;
332 QSharedPointer<ThreadBoundary> mThreadBoundary;
333};
334
335
336
337
338/* 172/*
339* The promise side for the result emitter 173* The promise side for the result emitter
340*/ 174*/
@@ -434,18 +268,18 @@ public:
434 } 268 }
435 269
436 /** 270 /**
437 * For lifetimemanagement only. 271 * For lifetimemanagement only.
438 * We keep the runner alive as long as the result provider exists. 272 * We keep the runner alive as long as the result provider exists.
439 */ 273 */
440 void setQueryRunner(const QSharedPointer<QObject> &runner) 274 void setQueryRunner(const QSharedPointer<QObject> &runner)
441 { 275 {
442 mQueryRunner = runner; 276 mQueryRunner = runner;
443 } 277 }
444 278
445 /** 279 /**
446 * For lifetimemanagement only. 280 * For lifetimemanagement only.
447 * We keep the runner alive as long as the result provider exists. 281 * We keep the runner alive as long as the result provider exists.
448 */ 282 */
449 void setFacade(const std::shared_ptr<void> &facade) 283 void setFacade(const std::shared_ptr<void> &facade)
450 { 284 {
451 mFacade = facade; 285 mFacade = facade;
@@ -463,6 +297,11 @@ public:
463 return mResultEmitter.toStrongRef().isNull(); 297 return mResultEmitter.toStrongRef().isNull();
464 } 298 }
465 299
300 void setFetcher(const std::function<void(const QByteArray &parent)> &fetcher)
301 {
302 fetcher(QByteArray());
303 }
304
466private: 305private:
467 void done() 306 void done()
468 { 307 {