#include "clientapi.h" #include "resourceaccess.h" #include "commands.h" #include "resourcefacade.h" #include "log.h" #include #define ASYNCINTHREAD #ifndef ASYNCINTHREAD #include #endif namespace async { void run(const std::function &runner) { #ifndef ASYNCINTHREAD auto timer = new QTimer(); timer->setSingleShot(true); QObject::connect(timer, &QTimer::timeout, [runner, timer]() { delete timer; runner(); }); timer->start(0); #else //TODO use a job that runs in a thread? QtConcurrent::run(runner); #endif }; } // namespace async namespace Akonadi2 { void FacadeFactory::registerStaticFacades() { registerFacade("resourceconfig"); } void Store::shutdown(const QByteArray &identifier) { Trace() << "shutdown"; ResourceAccess::connectToServer(identifier).then>([identifier](const QSharedPointer &socket, KAsync::Future &future) { //We can't currently reuse the socket socket->close(); auto resourceAccess = QSharedPointer::create(identifier); resourceAccess->open(); resourceAccess->sendCommand(Akonadi2::Commands::ShutdownCommand).then([&future, resourceAccess]() { future.setFinished(); }).exec(); }, [](int, const QString &) { //Resource isn't started, nothing to shutdown }).exec().waitForFinished(); } void Store::synchronize(const QByteArray &identifier) { Trace() << "synchronize"; auto resourceAccess = QSharedPointer::create(identifier); resourceAccess->open(); resourceAccess->synchronizeResource(true, false).exec().waitForFinished(); } } // namespace Akonadi2