diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-07 12:10:43 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-07 12:10:43 +0200 |
commit | 74610b153e6929d33ef61ebe6443c81dfd32d8a1 (patch) | |
tree | 6e9891f09fb558982030598c954702cde3cba145 | |
parent | 7ac1e222090ecfaa27ea8de2950e8c98a5033137 (diff) | |
download | sink-74610b153e6929d33ef61ebe6443c81dfd32d8a1.tar.gz sink-74610b153e6929d33ef61ebe6443c81dfd32d8a1.zip |
Disconnect one the object is gone.
-rw-r--r-- | common/resourcefacade.cpp | 10 | ||||
-rw-r--r-- | common/resourcefacade.h | 2 |
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 | ||
58 | template<typename DomainType> | 58 | template<typename DomainType> |
59 | LocalStorageQueryRunner<DomainType>::LocalStorageQueryRunner(const Query &query, const QByteArray &identifier, ConfigNotifier &configNotifier) | 59 | LocalStorageQueryRunner<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 | ||
142 | template<typename DomainType> | ||
143 | QObject *LocalStorageQueryRunner<DomainType>::guard() const | ||
144 | { | ||
145 | return mGuard.get(); | ||
146 | } | ||
142 | 147 | ||
143 | template<typename DomainType> | 148 | template<typename DomainType> |
144 | void LocalStorageQueryRunner<DomainType>::updateStatus(DomainType &entity) | 149 | void 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 ¬ification) { |
288 | auto ret = QObject::connect(resourceAccess.data(), &ResourceAccess::notification, [resource, runner, resourceAccess](const Notification ¬ification) { | ||
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 | ||
67 | private: | 68 | private: |
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 | ||
74 | template <typename DomainType> | 76 | template <typename DomainType> |