summaryrefslogtreecommitdiffstats
path: root/common/clientapi.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/clientapi.h')
-rw-r--r--common/clientapi.h19
1 files changed, 15 insertions, 4 deletions
diff --git a/common/clientapi.h b/common/clientapi.h
index 2d926fd..d658003 100644
--- a/common/clientapi.h
+++ b/common/clientapi.h
@@ -110,6 +110,8 @@ class FacadeFactory {
110public: 110public:
111 typedef std::function<std::shared_ptr<void>(const QByteArray &)> FactoryFunction; 111 typedef std::function<std::shared_ptr<void>(const QByteArray &)> FactoryFunction;
112 112
113 static void registerStaticFacades();
114
113 //FIXME: proper singleton implementation 115 //FIXME: proper singleton implementation
114 static FacadeFactory &instance() 116 static FacadeFactory &instance()
115 { 117 {
@@ -179,6 +181,9 @@ public:
179 static QByteArray resourceName(const QByteArray &instanceIdentifier) 181 static QByteArray resourceName(const QByteArray &instanceIdentifier)
180 { 182 {
181 auto split = instanceIdentifier.split('.'); 183 auto split = instanceIdentifier.split('.');
184 if (split.size() <= 1) {
185 return instanceIdentifier;
186 }
182 split.removeLast(); 187 split.removeLast();
183 return split.join('.'); 188 return split.join('.');
184 } 189 }
@@ -195,6 +200,7 @@ public:
195 //We must guarantee that the emitter is returned before the first result is emitted. 200 //We must guarantee that the emitter is returned before the first result is emitted.
196 //The result provider must be threadsafe. 201 //The result provider must be threadsafe.
197 async::run([query, resultSet](){ 202 async::run([query, resultSet](){
203 //TODO if query.resources is empty, search for all resource that provide the type we're looking for
198 // Query all resources and aggregate results 204 // Query all resources and aggregate results
199 KAsync::iterate(query.resources) 205 KAsync::iterate(query.resources)
200 .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, KAsync::Future<void> &future) { 206 .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, KAsync::Future<void> &future) {
@@ -205,7 +211,6 @@ public:
205 //Keep the facade alive for the lifetime of the resultSet. 211 //Keep the facade alive for the lifetime of the resultSet.
206 resultSet->setFacade(facade); 212 resultSet->setFacade(facade);
207 } else { 213 } else {
208 qWarning() << "Could not find facade for resource " << resource;
209 //Ignore the error and carry on 214 //Ignore the error and carry on
210 future.setFinished(); 215 future.setFinished();
211 } 216 }
@@ -245,7 +250,9 @@ public:
245 static void create(const DomainType &domainObject, const QByteArray &resourceIdentifier) { 250 static void create(const DomainType &domainObject, const QByteArray &resourceIdentifier) {
246 //Potentially move to separate thread as well 251 //Potentially move to separate thread as well
247 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier), resourceIdentifier); 252 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier), resourceIdentifier);
248 facade->create(domainObject).exec().waitForFinished(); 253 if (facade) {
254 facade->create(domainObject).exec().waitForFinished();
255 }
249 //TODO return job? 256 //TODO return job?
250 } 257 }
251 258
@@ -258,7 +265,9 @@ public:
258 static void modify(const DomainType &domainObject, const QByteArray &resourceIdentifier) { 265 static void modify(const DomainType &domainObject, const QByteArray &resourceIdentifier) {
259 //Potentially move to separate thread as well 266 //Potentially move to separate thread as well
260 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier), resourceIdentifier); 267 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier), resourceIdentifier);
261 facade->modify(domainObject).exec().waitForFinished(); 268 if (facade) {
269 facade->modify(domainObject).exec().waitForFinished();
270 }
262 //TODO return job? 271 //TODO return job?
263 } 272 }
264 273
@@ -269,7 +278,9 @@ public:
269 static void remove(const DomainType &domainObject, const QByteArray &resourceIdentifier) { 278 static void remove(const DomainType &domainObject, const QByteArray &resourceIdentifier) {
270 //Potentially move to separate thread as well 279 //Potentially move to separate thread as well
271 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier), resourceIdentifier); 280 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier), resourceIdentifier);
272 facade->remove(domainObject).exec().waitForFinished(); 281 if (facade) {
282 facade->remove(domainObject).exec().waitForFinished();
283 }
273 //TODO return job? 284 //TODO return job?
274 } 285 }
275 286