summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/resourcefacade.cpp10
-rw-r--r--common/resourcefacade.h2
2 files changed, 9 insertions, 3 deletions
diff --git a/common/resourcefacade.cpp b/common/resourcefacade.cpp
index 6e135b3..898e3ad 100644
--- a/common/resourcefacade.cpp
+++ b/common/resourcefacade.cpp
@@ -57,7 +57,7 @@ static bool matchesFilter(const QHash<QByteArray, Query::Comparator> &filter, co
57 57
58template<typename DomainType> 58template<typename DomainType>
59LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, const QByteArray &identifier, ConfigNotifier &configNotifier) 59LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, const QByteArray &identifier, ConfigNotifier &configNotifier)
60 : mResultProvider(new ResultProvider<typename DomainType::Ptr>), mConfigStore(identifier) 60 : mResultProvider(new ResultProvider<typename DomainType::Ptr>), mConfigStore(identifier), mGuard(new QObject)
61{ 61{
62 QObject *guard = new QObject; 62 QObject *guard = new QObject;
63 mResultProvider->setFetcher([this, query, guard, &configNotifier](const QSharedPointer<DomainType> &) { 63 mResultProvider->setFetcher([this, query, guard, &configNotifier](const QSharedPointer<DomainType> &) {
@@ -139,6 +139,11 @@ LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query,
139// 139//
140// } 140// }
141 141
142template<typename DomainType>
143QObject *LocalStorageQueryRunner<DomainType>::guard() const
144{
145 return mGuard.get();
146}
142 147
143template<typename DomainType> 148template<typename DomainType>
144void LocalStorageQueryRunner<DomainType>::updateStatus(DomainType &entity) 149void LocalStorageQueryRunner<DomainType>::updateStatus(DomainType &entity)
@@ -284,8 +289,7 @@ QPair<KAsync::Job<void>, typename Sink::ResultEmitter<typename ApplicationDomain
284 runner->setStatusUpdater([runner, monitoredResources](ApplicationDomain::SinkResource &resource) { 289 runner->setStatusUpdater([runner, monitoredResources](ApplicationDomain::SinkResource &resource) {
285 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier())); 290 auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource.identifier(), ResourceConfig::getResourceType(resource.identifier()));
286 if (!monitoredResources->contains(resource.identifier())) { 291 if (!monitoredResources->contains(resource.identifier())) {
287 //TODO disconnect at some point when the runner is done 292 auto ret = QObject::connect(resourceAccess.data(), &ResourceAccess::notification, runner->guard(), [resource, runner, resourceAccess](const Notification &notification) {
288 auto ret = QObject::connect(resourceAccess.data(), &ResourceAccess::notification, [resource, runner, resourceAccess](const Notification &notification) {
289 Trace() << "Received notification in facade: " << notification.type; 293 Trace() << "Received notification in facade: " << notification.type;
290 if (notification.type == Notification::Status) { 294 if (notification.type == Notification::Status) {
291 runner->statusChanged(resource.identifier()); 295 runner->statusChanged(resource.identifier());
diff --git a/common/resourcefacade.h b/common/resourcefacade.h
index 2573b31..64e082f 100644
--- a/common/resourcefacade.h
+++ b/common/resourcefacade.h
@@ -63,12 +63,14 @@ public:
63 typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr emitter(); 63 typename Sink::ResultEmitter<typename DomainType::Ptr>::Ptr emitter();
64 void setStatusUpdater(const std::function<void(DomainType &)> &); 64 void setStatusUpdater(const std::function<void(DomainType &)> &);
65 void statusChanged(const QByteArray &identifier); 65 void statusChanged(const QByteArray &identifier);
66 QObject *guard() const;
66 67
67private: 68private:
68 void updateStatus(DomainType &entity); 69 void updateStatus(DomainType &entity);
69 std::function<void(DomainType &)> mStatusUpdater; 70 std::function<void(DomainType &)> mStatusUpdater;
70 QSharedPointer<Sink::ResultProvider<typename DomainType::Ptr>> mResultProvider; 71 QSharedPointer<Sink::ResultProvider<typename DomainType::Ptr>> mResultProvider;
71 ConfigStore mConfigStore; 72 ConfigStore mConfigStore;
73 std::unique_ptr<QObject> mGuard;
72}; 74};
73 75
74template <typename DomainType> 76template <typename DomainType>