diff options
Diffstat (limited to 'common/resourcecontrol.cpp')
-rw-r--r-- | common/resourcecontrol.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/common/resourcecontrol.cpp b/common/resourcecontrol.cpp index af98b8b..f885deb 100644 --- a/common/resourcecontrol.cpp +++ b/common/resourcecontrol.cpp | |||
@@ -133,27 +133,26 @@ KAsync::Job<void> ResourceControl::flushReplayQueue(const QByteArray &resourceId | |||
133 | template <class DomainType> | 133 | template <class DomainType> |
134 | KAsync::Job<void> ResourceControl::inspect(const Inspection &inspectionCommand) | 134 | KAsync::Job<void> ResourceControl::inspect(const Inspection &inspectionCommand) |
135 | { | 135 | { |
136 | auto resource = inspectionCommand.resourceIdentifier; | 136 | auto resourceIdentifier = inspectionCommand.resourceIdentifier; |
137 | 137 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resourceIdentifier, ResourceConfig::getResourceType(resourceIdentifier)); | |
138 | auto time = QSharedPointer<QTime>::create(); | ||
139 | time->start(); | ||
140 | SinkTrace() << "Sending inspection " << resource; | ||
141 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); | ||
142 | resourceAccess->open(); | ||
143 | auto notifier = QSharedPointer<Sink::Notifier>::create(resourceAccess); | 138 | auto notifier = QSharedPointer<Sink::Notifier>::create(resourceAccess); |
144 | auto id = QUuid::createUuid().toByteArray(); | 139 | auto id = QUuid::createUuid().toByteArray(); |
145 | return resourceAccess->sendInspectionCommand(inspectionCommand.type, id, ApplicationDomain::getTypeName<DomainType>(), inspectionCommand.entityIdentifier, inspectionCommand.property, inspectionCommand.expectedValue) | 140 | return KAsync::start<void>([=](KAsync::Future<void> &future) { |
146 | .template then<void>([resourceAccess, notifier, id, time](KAsync::Future<void> &future) { | 141 | notifier->registerHandler([&future, id](const Notification ¬ification) { |
147 | notifier->registerHandler([&future, id, time](const Notification ¬ification) { | ||
148 | if (notification.id == id) { | 142 | if (notification.id == id) { |
149 | SinkTrace() << "Inspection complete." << Log::TraceTime(time->elapsed()); | 143 | SinkTrace() << "Inspection complete"; |
150 | if (notification.code) { | 144 | if (notification.code) { |
145 | SinkWarning() << "Inspection returned an error"; | ||
151 | future.setError(-1, "Inspection returned an error: " + notification.message); | 146 | future.setError(-1, "Inspection returned an error: " + notification.message); |
152 | } else { | 147 | } else { |
153 | future.setFinished(); | 148 | future.setFinished(); |
154 | } | 149 | } |
155 | } | 150 | } |
156 | }); | 151 | }); |
152 | resourceAccess->sendInspectionCommand(inspectionCommand.type, id, ApplicationDomain::getTypeName<DomainType>(), inspectionCommand.entityIdentifier, inspectionCommand.property, inspectionCommand.expectedValue).onError([&future] (const KAsync::Error &error) { | ||
153 | SinkWarning() << "Failed to send command"; | ||
154 | future.setError(1, "Failed to send command: " + error.errorMessage); | ||
155 | }).exec(); | ||
157 | }); | 156 | }); |
158 | } | 157 | } |
159 | 158 | ||