From b0e7af2972b82364f8ca95fef8031cbd018d54e0 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 29 Apr 2015 01:11:40 +0200 Subject: Avoid starting the resource for shutdown. --- common/clientapi.cpp | 18 ++++++++++++++---- common/resourceaccess.cpp | 6 ++++-- common/resourceaccess.h | 4 ++++ 3 files changed, 22 insertions(+), 6 deletions(-) (limited to 'common') diff --git a/common/clientapi.cpp b/common/clientapi.cpp index c6f5582..5cb3b69 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp @@ -2,6 +2,7 @@ #include "clientapi.h" #include "resourceaccess.h" #include "commands.h" +#include "log.h" namespace async { @@ -39,10 +40,19 @@ QByteArray getTypeName() void Store::shutdown(const QByteArray &identifier) { - Akonadi2::ResourceAccess resourceAccess(identifier); - //FIXME this starts the resource, just to shut it down again if it's not running in the first place. - resourceAccess.open(); - resourceAccess.sendCommand(Akonadi2::Commands::ShutdownCommand).exec().waitForFinished(); + Trace() << "shutdown"; + ResourceAccess::connectToServer(identifier).then>([identifier](const QSharedPointer &socket, Async::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(); } } // namespace Akonadi2 diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index c6d701d..28aaf2e 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp @@ -84,7 +84,7 @@ ResourceAccess::Private::Private(const QByteArray &name, ResourceAccess *q) } //Connects to server and returns connected socket on success -static Async::Job > connectToServer(const QByteArray &identifier) +Async::Job > ResourceAccess::connectToServer(const QByteArray &identifier) { auto s = QSharedPointer::create(); return Async::start >([identifier, s](Async::Future > &future) { @@ -161,7 +161,9 @@ ResourceAccess::ResourceAccess(const QByteArray &resourceName, QObject *parent) ResourceAccess::~ResourceAccess() { - + if (!d->resultHandler.isEmpty()) { + Warning() << "Left jobs running while shutting down ResourceAccess"; + } } QByteArray ResourceAccess::resourceName() const diff --git a/common/resourceaccess.h b/common/resourceaccess.h index dc7640d..c16a9d2 100644 --- a/common/resourceaccess.h +++ b/common/resourceaccess.h @@ -46,6 +46,10 @@ public: Async::Job sendCommand(int commandId); Async::Job sendCommand(int commandId, flatbuffers::FlatBufferBuilder &fbb); Async::Job synchronizeResource(bool remoteSync, bool localSync); + /** + * Tries to connect to server, and returns a connected socket on success. + */ + static Async::Job > connectToServer(const QByteArray &identifier); public Q_SLOTS: void open(); -- cgit v1.2.3