diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-18 18:36:41 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-01-18 18:36:41 +0100 |
commit | 67e83aadde8db2bb1293cee61e8c6306a4ffcca0 (patch) | |
tree | 10531201cb5dca7617e17a4e4393bda20694c4ca /common/clientapi.cpp | |
parent | a857d9b36f80adf045cd195653cb2f8b91452981 (diff) | |
download | sink-67e83aadde8db2bb1293cee61e8c6306a4ffcca0.tar.gz sink-67e83aadde8db2bb1293cee61e8c6306a4ffcca0.zip |
Working resource inspection
Diffstat (limited to 'common/clientapi.cpp')
-rw-r--r-- | common/clientapi.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/common/clientapi.cpp b/common/clientapi.cpp index deab962..40257bb 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp | |||
@@ -298,13 +298,50 @@ KAsync::Job<void> Resources::inspect(const Inspection &inspectionCommand) | |||
298 | Trace() << "Sending inspection " << resource; | 298 | Trace() << "Sending inspection " << resource; |
299 | auto resourceAccess = QSharedPointer<Akonadi2::ResourceAccess>::create(resource); | 299 | auto resourceAccess = QSharedPointer<Akonadi2::ResourceAccess>::create(resource); |
300 | resourceAccess->open(); | 300 | resourceAccess->open(); |
301 | auto notifier = QSharedPointer<Akonadi2::Notifier>::create(resourceAccess); | ||
301 | auto id = QUuid::createUuid().toByteArray(); | 302 | auto id = QUuid::createUuid().toByteArray(); |
302 | return resourceAccess->sendInspectionCommand(id, ApplicationDomain::getTypeName<DomainType>(), inspectionCommand.entityIdentifier, inspectionCommand.property, inspectionCommand.expectedValue) | 303 | return resourceAccess->sendInspectionCommand(id, ApplicationDomain::getTypeName<DomainType>(), inspectionCommand.entityIdentifier, inspectionCommand.property, inspectionCommand.expectedValue) |
303 | .template then<void>([resourceAccess]() { | 304 | .template then<void>([resourceAccess, notifier, id](KAsync::Future<void> &future) { |
304 | //TODO wait for inspection notification | 305 | notifier->registerHandler([&future, id](const ResourceNotification ¬ification) { |
306 | if (notification.id == id) { | ||
307 | if (notification.code) { | ||
308 | future.setError(-1, "Inspection returned an error: " + notification.message); | ||
309 | } else { | ||
310 | future.setFinished(); | ||
311 | } | ||
312 | } | ||
313 | }); | ||
305 | }); | 314 | }); |
306 | } | 315 | } |
307 | 316 | ||
317 | class Akonadi2::Notifier::Private { | ||
318 | public: | ||
319 | Private() | ||
320 | : context(new QObject) | ||
321 | { | ||
322 | |||
323 | } | ||
324 | QList<QSharedPointer<ResourceAccess> > resourceAccess; | ||
325 | QList<std::function<void(const ResourceNotification &)> > handler; | ||
326 | QSharedPointer<QObject> context; | ||
327 | }; | ||
328 | |||
329 | Notifier::Notifier(const QSharedPointer<ResourceAccess> &resourceAccess) | ||
330 | : d(new Akonadi2::Notifier::Private) | ||
331 | { | ||
332 | QObject::connect(resourceAccess.data(), &ResourceAccess::notification, d->context.data(), [this](const ResourceNotification ¬ification) { | ||
333 | for (const auto &handler : d->handler) { | ||
334 | handler(notification); | ||
335 | } | ||
336 | }); | ||
337 | d->resourceAccess << resourceAccess; | ||
338 | } | ||
339 | |||
340 | void Notifier::registerHandler(std::function<void(const ResourceNotification &)> handler) | ||
341 | { | ||
342 | d->handler << handler; | ||
343 | } | ||
344 | |||
308 | #define REGISTER_TYPE(T) template KAsync::Job<void> Store::remove<T>(const T &domainObject); \ | 345 | #define REGISTER_TYPE(T) template KAsync::Job<void> Store::remove<T>(const T &domainObject); \ |
309 | template KAsync::Job<void> Store::create<T>(const T &domainObject); \ | 346 | template KAsync::Job<void> Store::create<T>(const T &domainObject); \ |
310 | template KAsync::Job<void> Store::modify<T>(const T &domainObject); \ | 347 | template KAsync::Job<void> Store::modify<T>(const T &domainObject); \ |