blob: 5edab9750323f5ffd85689a1965a9d849426ee51 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#include "clientapi.h"
#include "resourceaccess.h"
#include "commands.h"
#include "resourcefacade.h"
#include "log.h"
#include "definitions.h"
#include <QtConcurrent/QtConcurrentRun>
#include <QTimer>
#define ASYNCINTHREAD
namespace async
{
void run(const std::function<void()> &runner) {
auto timer = new QTimer();
timer->setSingleShot(true);
QObject::connect(timer, &QTimer::timeout, [runner, timer]() {
delete timer;
#ifndef ASYNCINTHREAD
runner();
#else
QtConcurrent::run(runner);
#endif
});
timer->start(0);
};
} // namespace async
namespace Akonadi2
{
void Store::shutdown(const QByteArray &identifier)
{
Trace() << "shutdown";
ResourceAccess::connectToServer(identifier).then<void, QSharedPointer<QLocalSocket>>([identifier](const QSharedPointer<QLocalSocket> &socket, KAsync::Future<void> &future) {
//We can't currently reuse the socket
socket->close();
auto resourceAccess = QSharedPointer<Akonadi2::ResourceAccess>::create(identifier);
resourceAccess->open();
resourceAccess->sendCommand(Akonadi2::Commands::ShutdownCommand).then<void>([&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<Akonadi2::ResourceAccess>::create(identifier);
resourceAccess->open();
resourceAccess->synchronizeResource(true, false).exec().waitForFinished();
}
} // namespace Akonadi2
|