summaryrefslogtreecommitdiffstats
path: root/common/clientapi.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-01-18 18:36:41 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-01-18 18:36:41 +0100
commit67e83aadde8db2bb1293cee61e8c6306a4ffcca0 (patch)
tree10531201cb5dca7617e17a4e4393bda20694c4ca /common/clientapi.cpp
parenta857d9b36f80adf045cd195653cb2f8b91452981 (diff)
downloadsink-67e83aadde8db2bb1293cee61e8c6306a4ffcca0.tar.gz
sink-67e83aadde8db2bb1293cee61e8c6306a4ffcca0.zip
Working resource inspection
Diffstat (limited to 'common/clientapi.cpp')
-rw-r--r--common/clientapi.cpp41
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 &notification) {
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
317class Akonadi2::Notifier::Private {
318public:
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
329Notifier::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 &notification) {
333 for (const auto &handler : d->handler) {
334 handler(notification);
335 }
336 });
337 d->resourceAccess << resourceAccess;
338}
339
340void 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); \