summaryrefslogtreecommitdiffstats
path: root/common/clientapi.h
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-07-08 16:48:41 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-07-08 16:48:41 +0200
commit3fe20509c29c40305d0362adbc787edfc29e96d4 (patch)
treef11f9e2604c56ccaa8606023e89b495928d990b3 /common/clientapi.h
parentc0a8d67cde03e33bf21e0f186f85d4c89c7ff572 (diff)
downloadsink-3fe20509c29c40305d0362adbc787edfc29e96d4.tar.gz
sink-3fe20509c29c40305d0362adbc787edfc29e96d4.zip
Filter queries by available resources, and filter resources by
resource-types
Diffstat (limited to 'common/clientapi.h')
-rw-r--r--common/clientapi.h32
1 files changed, 29 insertions, 3 deletions
diff --git a/common/clientapi.h b/common/clientapi.h
index d658003..a01db23 100644
--- a/common/clientapi.h
+++ b/common/clientapi.h
@@ -34,6 +34,7 @@
34#include "threadboundary.h" 34#include "threadboundary.h"
35#include "resultprovider.h" 35#include "resultprovider.h"
36#include "domain/applicationdomaintype.h" 36#include "domain/applicationdomaintype.h"
37#include "resourceconfig.h"
37 38
38namespace async { 39namespace async {
39 //This should abstract if we execute from eventloop or in thread. 40 //This should abstract if we execute from eventloop or in thread.
@@ -110,7 +111,7 @@ class FacadeFactory {
110public: 111public:
111 typedef std::function<std::shared_ptr<void>(const QByteArray &)> FactoryFunction; 112 typedef std::function<std::shared_ptr<void>(const QByteArray &)> FactoryFunction;
112 113
113 static void registerStaticFacades(); 114 void registerStaticFacades();
114 115
115 //FIXME: proper singleton implementation 116 //FIXME: proper singleton implementation
116 static FacadeFactory &instance() 117 static FacadeFactory &instance()
@@ -165,6 +166,11 @@ public:
165 } 166 }
166 167
167private: 168private:
169 FacadeFactory()
170 {
171 registerStaticFacades();
172 }
173
168 QHash<QByteArray, FactoryFunction> mFacadeRegistry; 174 QHash<QByteArray, FactoryFunction> mFacadeRegistry;
169}; 175};
170 176
@@ -188,6 +194,27 @@ public:
188 return split.join('.'); 194 return split.join('.');
189 } 195 }
190 196
197 static QList<QByteArray> getResources(const QList<QByteArray> &resourceFilter)
198 {
199 QList<QByteArray> resources;
200 const auto configuredResources = ResourceConfig::getResources();
201 if (resourceFilter.isEmpty()) {
202 for (const auto &res : configuredResources) {
203 //TODO filter by type
204 resources << res;
205 }
206 } else {
207 for (const auto &res : resourceFilter) {
208 if (configuredResources.contains(res)) {
209 resources << res;
210 } else {
211 qWarning() << "Resource is not existing: " << res;
212 }
213 }
214 }
215 return resources;
216 }
217
191 /** 218 /**
192 * Asynchronusly load a dataset 219 * Asynchronusly load a dataset
193 */ 220 */
@@ -200,9 +227,8 @@ public:
200 //We must guarantee that the emitter is returned before the first result is emitted. 227 //We must guarantee that the emitter is returned before the first result is emitted.
201 //The result provider must be threadsafe. 228 //The result provider must be threadsafe.
202 async::run([query, resultSet](){ 229 async::run([query, resultSet](){
203 //TODO if query.resources is empty, search for all resource that provide the type we're looking for
204 // Query all resources and aggregate results 230 // Query all resources and aggregate results
205 KAsync::iterate(query.resources) 231 KAsync::iterate(getResources(query.resources))
206 .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, KAsync::Future<void> &future) { 232 .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, KAsync::Future<void> &future) {
207 //TODO pass resource identifier to factory 233 //TODO pass resource identifier to factory
208 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource), resource); 234 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource), resource);