summaryrefslogtreecommitdiffstats
path: root/common/clientapi.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/clientapi.h')
-rw-r--r--common/clientapi.h16
1 files changed, 8 insertions, 8 deletions
diff --git a/common/clientapi.h b/common/clientapi.h
index 748baa6..2d926fd 100644
--- a/common/clientapi.h
+++ b/common/clientapi.h
@@ -108,7 +108,7 @@ public:
108 108
109class FacadeFactory { 109class FacadeFactory {
110public: 110public:
111 typedef std::function<std::shared_ptr<void>()> FactoryFunction; 111 typedef std::function<std::shared_ptr<void>(const QByteArray &)> FactoryFunction;
112 112
113 //FIXME: proper singleton implementation 113 //FIXME: proper singleton implementation
114 static FacadeFactory &instance() 114 static FacadeFactory &instance()
@@ -126,7 +126,7 @@ public:
126 void registerFacade(const QByteArray &resource) 126 void registerFacade(const QByteArray &resource)
127 { 127 {
128 const QByteArray typeName = ApplicationDomain::getTypeName<DomainType>(); 128 const QByteArray typeName = ApplicationDomain::getTypeName<DomainType>();
129 mFacadeRegistry.insert(key(resource, typeName), [](){ return std::shared_ptr<Facade>(new Facade); }); 129 mFacadeRegistry.insert(key(resource, typeName), [](const QByteArray &instanceIdentifier){ return std::make_shared<Facade>(instanceIdentifier); });
130 } 130 }
131 131
132 /* 132 /*
@@ -152,11 +152,11 @@ public:
152 } 152 }
153 153
154 template<class DomainType> 154 template<class DomainType>
155 std::shared_ptr<StoreFacade<DomainType> > getFacade(const QByteArray &resource) 155 std::shared_ptr<StoreFacade<DomainType> > getFacade(const QByteArray &resource, const QByteArray &instanceIdentifier)
156 { 156 {
157 const QByteArray typeName = ApplicationDomain::getTypeName<DomainType>(); 157 const QByteArray typeName = ApplicationDomain::getTypeName<DomainType>();
158 if (auto factoryFunction = mFacadeRegistry.value(key(resource, typeName))) { 158 if (auto factoryFunction = mFacadeRegistry.value(key(resource, typeName))) {
159 return std::static_pointer_cast<StoreFacade<DomainType> >(factoryFunction()); 159 return std::static_pointer_cast<StoreFacade<DomainType> >(factoryFunction(instanceIdentifier));
160 } 160 }
161 qWarning() << "Failed to find facade for resource: " << resource << " and type: " << typeName; 161 qWarning() << "Failed to find facade for resource: " << resource << " and type: " << typeName;
162 return std::shared_ptr<StoreFacade<DomainType> >(); 162 return std::shared_ptr<StoreFacade<DomainType> >();
@@ -199,7 +199,7 @@ public:
199 KAsync::iterate(query.resources) 199 KAsync::iterate(query.resources)
200 .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, KAsync::Future<void> &future) { 200 .template each<void, QByteArray>([query, resultSet](const QByteArray &resource, KAsync::Future<void> &future) {
201 //TODO pass resource identifier to factory 201 //TODO pass resource identifier to factory
202 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource)); 202 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resource), resource);
203 if (facade) { 203 if (facade) {
204 facade->load(query, resultSet).template then<void>([&future](){future.setFinished();}).exec(); 204 facade->load(query, resultSet).template then<void>([&future](){future.setFinished();}).exec();
205 //Keep the facade alive for the lifetime of the resultSet. 205 //Keep the facade alive for the lifetime of the resultSet.
@@ -244,7 +244,7 @@ public:
244 template <class DomainType> 244 template <class DomainType>
245 static void create(const DomainType &domainObject, const QByteArray &resourceIdentifier) { 245 static void create(const DomainType &domainObject, const QByteArray &resourceIdentifier) {
246 //Potentially move to separate thread as well 246 //Potentially move to separate thread as well
247 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier)); 247 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier), resourceIdentifier);
248 facade->create(domainObject).exec().waitForFinished(); 248 facade->create(domainObject).exec().waitForFinished();
249 //TODO return job? 249 //TODO return job?
250 } 250 }
@@ -257,7 +257,7 @@ public:
257 template <class DomainType> 257 template <class DomainType>
258 static void modify(const DomainType &domainObject, const QByteArray &resourceIdentifier) { 258 static void modify(const DomainType &domainObject, const QByteArray &resourceIdentifier) {
259 //Potentially move to separate thread as well 259 //Potentially move to separate thread as well
260 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier)); 260 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier), resourceIdentifier);
261 facade->modify(domainObject).exec().waitForFinished(); 261 facade->modify(domainObject).exec().waitForFinished();
262 //TODO return job? 262 //TODO return job?
263 } 263 }
@@ -268,7 +268,7 @@ public:
268 template <class DomainType> 268 template <class DomainType>
269 static void remove(const DomainType &domainObject, const QByteArray &resourceIdentifier) { 269 static void remove(const DomainType &domainObject, const QByteArray &resourceIdentifier) {
270 //Potentially move to separate thread as well 270 //Potentially move to separate thread as well
271 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier)); 271 auto facade = FacadeFactory::instance().getFacade<DomainType>(resourceName(resourceIdentifier), resourceIdentifier);
272 facade->remove(domainObject).exec().waitForFinished(); 272 facade->remove(domainObject).exec().waitForFinished();
273 //TODO return job? 273 //TODO return job?
274 } 274 }