summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/clientapi.h43
1 files changed, 32 insertions, 11 deletions
diff --git a/client/clientapi.h b/client/clientapi.h
index 8924328..4e98d05 100644
--- a/client/clientapi.h
+++ b/client/clientapi.h
@@ -6,6 +6,20 @@
6#include <functional> 6#include <functional>
7#include "store/database.h" 7#include "store/database.h"
8 8
9namespace async {
10 //This should abstract if we execute from eventloop or in thread.
11 //It supposed to allow the caller to finish the current method before executing the runner.
12 void run(const std::function<void()> &runner) {
13 //FIXME we should be using a Job instead of a timer
14 auto timer = new QTimer;
15 timer->setSingleShot(true);
16 QObject::connect(timer, &QTimer::timeout, runner);
17 QObject::connect(timer, &QTimer::timeout, timer, &QObject::deleteLater);
18 timer->start(0);
19 };
20
21}
22
9namespace ClientAPI { 23namespace ClientAPI {
10 24
11/** 25/**
@@ -133,6 +147,11 @@ private:
133 * It probably also makes sense to have a domain specific part of the query, 147 * It probably also makes sense to have a domain specific part of the query,
134 * such as what properties we're interested in (necessary information for on-demand 148 * such as what properties we're interested in (necessary information for on-demand
135 * loading of data). 149 * loading of data).
150 *
151 * The query defines:
152 * * what resources to search
153 * * filters on various properties (parent collection, startDate range, ....)
154 * * properties we need (for on-demand querying)
136 */ 155 */
137class Query 156class Query
138{ 157{
@@ -210,7 +229,7 @@ public:
210 void load(const Query &query, const std::function<void(const Event &)> &resultCallback) { 229 void load(const Query &query, const std::function<void(const Event &)> &resultCallback) {
211 //retrieve buffers from storage 230 //retrieve buffers from storage
212 QList<EventBuffer> queryresult; 231 QList<EventBuffer> queryresult;
213 foreach(const EventBuffer &buffer, queryresult) { 232 for(const EventBuffer &buffer : queryresult) {
214 resultCallback(transformToDomainType(buffer)); 233 resultCallback(transformToDomainType(buffer));
215 } 234 }
216 } 235 }
@@ -244,6 +263,8 @@ public:
244 263
245/** 264/**
246 * Store interface used in the client API 265 * Store interface used in the client API
266 *
267 * TODO: For testing we need to be able to inject dummy StoreFacades.
247 */ 268 */
248class Store { 269class Store {
249public: 270public:
@@ -255,17 +276,17 @@ public:
255 { 276 {
256 QSharedPointer<ResultProvider<DomainType> > resultSet(new ResultProvider<DomainType>); 277 QSharedPointer<ResultProvider<DomainType> > resultSet(new ResultProvider<DomainType>);
257 278
258 //Create a job that executes the search function. 279 //Execute the search in a thread.
259 //We must guarantee that the emitter is returned before the first result is emitted. 280 //We must guarantee that the emitter is returned before the first result is emitted.
260 //The thread boundary handling is implemented in the result provider. 281 //The result provider must be threadsafe.
261 // QtConcurrent::run([provider, resultSet](){ 282 async::run([resultSet, query](){
262 // // Query all resources and aggregate results 283 // Query all resources and aggregate results
263 // // query tells us in which resources we're interested 284 // query tells us in which resources we're interested
264 // for(const auto &resource, query.resources()) { 285 for(const QString &resource : query.resources()) {
265 // auto facade = FacadeFactory::getFacade(resource); 286 auto facade = FacadeFactory::getFacade<DomainType>(resource);
266 // facade.load<DomainType>(query, resultSet.add); 287 facade.load(query, resultSet.add);
267 // } 288 }
268 // }); 289 });
269 return resultSet->emitter(); 290 return resultSet->emitter();
270 } 291 }
271 292