summaryrefslogtreecommitdiffstats
path: root/common/facade.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-13 20:15:14 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-04-15 09:30:32 +0200
commitc55054e899660f2d667af2c2e573a1267d47358e (patch)
tree0f547effcad0c20521f0bc047a9eb1d4130b052b /common/facade.h
parent4652a39fc6869fc5af46367c35027b2b53478268 (diff)
downloadsink-c55054e899660f2d667af2c2e573a1267d47358e.tar.gz
sink-c55054e899660f2d667af2c2e573a1267d47358e.zip
Use a queryrunner to execute queries.
The queryrunner is responsible for running queries and keeping them up to date. This is required for self-updating queries. To get this to work properly the ResultProvider/emitter had to be fixed. The emitter now only lives as long as the client holds a reference to it, allowing the provider to detect when it is no longer necessary to keep the query alive (because noone is listening). In the process various lifetime issues have been fixed, that we're caused by lambdas capturing smartpointers, that then extended the lifetime of the associated objects unpredictably.
Diffstat (limited to 'common/facade.h')
-rw-r--r--common/facade.h51
1 files changed, 50 insertions, 1 deletions
diff --git a/common/facade.h b/common/facade.h
index 98bcb38..f9b5a83 100644
--- a/common/facade.h
+++ b/common/facade.h
@@ -30,6 +30,55 @@
30#include "domainadaptor.h" 30#include "domainadaptor.h"
31#include "entitybuffer.h" 31#include "entitybuffer.h"
32 32
33/**
34 * A QueryRunner runs a query and updates the corresponding result set.
35 *
36 * The lifetime of the QueryRunner is defined by the resut set (otherwise it's doing useless work),
37 * and by how long a result set must be updated. If the query is one off the runner dies after the execution,
38 * otherwise it lives on the react to changes and updates the corresponding result set.
39 *
40 * QueryRunner has to keep ResourceAccess alive in order to keep getting updates.
41 */
42class QueryRunner : public QObject
43{
44 Q_OBJECT
45public:
46 typedef std::function<Async::Job<qint64>(qint64 oldRevision, qint64 newRevision)> QueryFunction;
47
48 QueryRunner(const Akonadi2::Query &query) : mLatestRevision(0) {};
49 /**
50 * Starts query
51 */
52 Async::Job<void> run(qint64 newRevision = 0)
53 {
54 //TODO: JOBAPI: that last empty .then should not be necessary
55 return queryFunction(mLatestRevision, newRevision).then<void, qint64>([this](qint64 revision) {
56 mLatestRevision = revision;
57 }).then<void>([](){});
58 }
59
60 /**
61 *
62 */
63 void setQuery(const QueryFunction &query)
64 {
65 queryFunction = query;
66 }
67
68public slots:
69 /**
70 * Rerun query with new revision
71 */
72 void revisionChanged(qint64 newRevision)
73 {
74 run(newRevision).exec();
75 }
76
77private:
78 QueryFunction queryFunction;
79 qint64 mLatestRevision;
80};
81
33namespace Akonadi2 { 82namespace Akonadi2 {
34 class ResourceAccess; 83 class ResourceAccess;
35/** 84/**
@@ -80,7 +129,7 @@ protected:
80 return Async::null<void>(); 129 return Async::null<void>();
81 } 130 }
82 131
83private: 132protected:
84 //TODO use one resource access instance per application => make static 133 //TODO use one resource access instance per application => make static
85 QSharedPointer<Akonadi2::ResourceAccess> mResourceAccess; 134 QSharedPointer<Akonadi2::ResourceAccess> mResourceAccess;
86}; 135};