diff options
Diffstat (limited to 'common/clientapi.h')
-rw-r--r-- | common/clientapi.h | 32 |
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 | ||
38 | namespace async { | 39 | namespace 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 { | |||
110 | public: | 111 | public: |
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 | ||
167 | private: | 168 | private: |
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); |