summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/clientapi.h19
1 files changed, 5 insertions, 14 deletions
diff --git a/common/clientapi.h b/common/clientapi.h
index 6d66e40..f7f4c13 100644
--- a/common/clientapi.h
+++ b/common/clientapi.h
@@ -490,7 +490,7 @@ public:
490 } 490 }
491 491
492 template<class DomainType> 492 template<class DomainType>
493 QSharedPointer<StoreFacade<DomainType> > getFacade(const QByteArray &resource) 493 std::shared_ptr<StoreFacade<DomainType> > getFacade(const QByteArray &resource)
494 { 494 {
495 const QByteArray typeName = ApplicationDomain::getTypeName<DomainType>(); 495 const QByteArray typeName = ApplicationDomain::getTypeName<DomainType>();
496 auto factoryFunction = mFacadeRegistry.value(key(resource, typeName)); 496 auto factoryFunction = mFacadeRegistry.value(key(resource, typeName));
@@ -499,27 +499,19 @@ public:
499 auto ptr = static_cast<StoreFacade<DomainType>* >(factoryFunction(externallyManaged)); 499 auto ptr = static_cast<StoreFacade<DomainType>* >(factoryFunction(externallyManaged));
500 if (externallyManaged) { 500 if (externallyManaged) {
501 //Allows tests to manage the lifetime of injected facades themselves 501 //Allows tests to manage the lifetime of injected facades themselves
502 return QSharedPointer<StoreFacade<DomainType> >(ptr, doNothingDeleter); 502 return std::shared_ptr<StoreFacade<DomainType> >(ptr, doNothingDeleter);
503 } else { 503 } else {
504 return QSharedPointer<StoreFacade<DomainType> >(ptr); 504 return std::shared_ptr<StoreFacade<DomainType> >(ptr);
505 } 505 }
506 } 506 }
507 qWarning() << "Failed to find facade for resource: " << resource << " and type: " << typeName; 507 qWarning() << "Failed to find facade for resource: " << resource << " and type: " << typeName;
508 return QSharedPointer<StoreFacade<DomainType> >(); 508 return std::shared_ptr<StoreFacade<DomainType> >();
509 } 509 }
510 510
511private: 511private:
512 QHash<QByteArray, FactoryFunction> mFacadeRegistry; 512 QHash<QByteArray, FactoryFunction> mFacadeRegistry;
513}; 513};
514 514
515template <class DomainType>
516struct LifeExtender {
517 LifeExtender(const QSharedPointer<StoreFacade<DomainType> > &f) : facade(f) {}
518private:
519 QSharedPointer<StoreFacade<DomainType> > facade;
520};
521
522
523/** 515/**
524 * Store interface used in the client API. 516 * Store interface used in the client API.
525 */ 517 */
@@ -551,8 +543,7 @@ public:
551 auto facade = FacadeFactory::instance().getFacade<DomainType>(resource); 543 auto facade = FacadeFactory::instance().getFacade<DomainType>(resource);
552 facade->load(query, resultSet).template then<void>([&future](){future.setFinished();}).exec(); 544 facade->load(query, resultSet).template then<void>([&future](){future.setFinished();}).exec();
553 //Keep the facade alive for the duration for the lifetime of the resultSet. 545 //Keep the facade alive for the duration for the lifetime of the resultSet.
554 //TODO If the factory returned a std::shared_ptr we wouldn't require LifeExtender 546 resultSet->setFacade(facade);
555 resultSet->setFacade(std::make_shared<LifeExtender<DomainType> >(facade));
556 }).template then<void>([query, resultSet]() { 547 }).template then<void>([query, resultSet]() {
557 resultSet->initialResultSetComplete(); 548 resultSet->initialResultSetComplete();
558 if (!query.liveQuery) { 549 if (!query.liveQuery) {