diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-11 11:55:29 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-11 11:55:29 +0200 |
commit | 3a3118e768e1447dc7524328e84b8d7faef81fe1 (patch) | |
tree | af5582170ed6164fffc9365f34b17bf449c0db40 /common/resourcecontrol.cpp | |
parent | f9379318d801df204cc50385c5eca1f28e91755e (diff) | |
parent | ce2fd2666f084eebe443598f6f3740a02913091e (diff) | |
download | sink-3a3118e768e1447dc7524328e84b8d7faef81fe1.tar.gz sink-3a3118e768e1447dc7524328e84b8d7faef81fe1.zip |
Merge branch 'feature/notifications' into develop
Diffstat (limited to 'common/resourcecontrol.cpp')
-rw-r--r-- | common/resourcecontrol.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/common/resourcecontrol.cpp b/common/resourcecontrol.cpp index 5c2cd06..7d092a4 100644 --- a/common/resourcecontrol.cpp +++ b/common/resourcecontrol.cpp | |||
@@ -30,14 +30,13 @@ | |||
30 | #include "log.h" | 30 | #include "log.h" |
31 | #include "notifier.h" | 31 | #include "notifier.h" |
32 | 32 | ||
33 | #undef DEBUG_AREA | 33 | SINK_DEBUG_AREA("resourcecontrol") |
34 | #define DEBUG_AREA "client.resourcecontrol" | ||
35 | 34 | ||
36 | namespace Sink { | 35 | namespace Sink { |
37 | 36 | ||
38 | KAsync::Job<void> ResourceControl::shutdown(const QByteArray &identifier) | 37 | KAsync::Job<void> ResourceControl::shutdown(const QByteArray &identifier) |
39 | { | 38 | { |
40 | Trace() << "shutdown " << identifier; | 39 | SinkTrace() << "shutdown " << identifier; |
41 | auto time = QSharedPointer<QTime>::create(); | 40 | auto time = QSharedPointer<QTime>::create(); |
42 | time->start(); | 41 | time->start(); |
43 | return ResourceAccess::connectToServer(identifier) | 42 | return ResourceAccess::connectToServer(identifier) |
@@ -50,33 +49,33 @@ KAsync::Job<void> ResourceControl::shutdown(const QByteArray &identifier) | |||
50 | resourceAccess->sendCommand(Sink::Commands::ShutdownCommand) | 49 | resourceAccess->sendCommand(Sink::Commands::ShutdownCommand) |
51 | .then<void>([&future, resourceAccess, time]() { | 50 | .then<void>([&future, resourceAccess, time]() { |
52 | resourceAccess->close(); | 51 | resourceAccess->close(); |
53 | Trace() << "Shutdown complete." << Log::TraceTime(time->elapsed()); | 52 | SinkTrace() << "Shutdown complete." << Log::TraceTime(time->elapsed()); |
54 | future.setFinished(); | 53 | future.setFinished(); |
55 | }) | 54 | }) |
56 | .exec(); | 55 | .exec(); |
57 | }, | 56 | }, |
58 | [](int, const QString &) { | 57 | [](int, const QString &) { |
59 | Trace() << "Resource is already closed."; | 58 | SinkTrace() << "Resource is already closed."; |
60 | // Resource isn't started, nothing to shutdown | 59 | // Resource isn't started, nothing to shutdown |
61 | }); | 60 | }); |
62 | } | 61 | } |
63 | 62 | ||
64 | KAsync::Job<void> ResourceControl::start(const QByteArray &identifier) | 63 | KAsync::Job<void> ResourceControl::start(const QByteArray &identifier) |
65 | { | 64 | { |
66 | Trace() << "start " << identifier; | 65 | SinkTrace() << "start " << identifier; |
67 | auto time = QSharedPointer<QTime>::create(); | 66 | auto time = QSharedPointer<QTime>::create(); |
68 | time->start(); | 67 | time->start(); |
69 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(identifier, ResourceConfig::getResourceType(identifier)); | 68 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(identifier, ResourceConfig::getResourceType(identifier)); |
70 | resourceAccess->open(); | 69 | resourceAccess->open(); |
71 | return resourceAccess->sendCommand(Sink::Commands::PingCommand).then<void>([resourceAccess, time]() { Trace() << "Start complete." << Log::TraceTime(time->elapsed()); }); | 70 | return resourceAccess->sendCommand(Sink::Commands::PingCommand).then<void>([resourceAccess, time]() { SinkTrace() << "Start complete." << Log::TraceTime(time->elapsed()); }); |
72 | } | 71 | } |
73 | 72 | ||
74 | KAsync::Job<void> ResourceControl::flushMessageQueue(const QByteArrayList &resourceIdentifier) | 73 | KAsync::Job<void> ResourceControl::flushMessageQueue(const QByteArrayList &resourceIdentifier) |
75 | { | 74 | { |
76 | Trace() << "flushMessageQueue" << resourceIdentifier; | 75 | SinkTrace() << "flushMessageQueue" << resourceIdentifier; |
77 | return KAsync::iterate(resourceIdentifier) | 76 | return KAsync::iterate(resourceIdentifier) |
78 | .template each<void, QByteArray>([](const QByteArray &resource, KAsync::Future<void> &future) { | 77 | .template each<void, QByteArray>([](const QByteArray &resource, KAsync::Future<void> &future) { |
79 | Trace() << "Flushing message queue " << resource; | 78 | SinkTrace() << "Flushing message queue " << resource; |
80 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); | 79 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); |
81 | resourceAccess->open(); | 80 | resourceAccess->open(); |
82 | resourceAccess->synchronizeResource(false, true).then<void>([&future, resourceAccess]() { future.setFinished(); }).exec(); | 81 | resourceAccess->synchronizeResource(false, true).then<void>([&future, resourceAccess]() { future.setFinished(); }).exec(); |
@@ -95,7 +94,7 @@ KAsync::Job<void> ResourceControl::inspect(const Inspection &inspectionCommand) | |||
95 | 94 | ||
96 | auto time = QSharedPointer<QTime>::create(); | 95 | auto time = QSharedPointer<QTime>::create(); |
97 | time->start(); | 96 | time->start(); |
98 | Trace() << "Sending inspection " << resource; | 97 | SinkTrace() << "Sending inspection " << resource; |
99 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); | 98 | auto resourceAccess = ResourceAccessFactory::instance().getAccess(resource, ResourceConfig::getResourceType(resource)); |
100 | resourceAccess->open(); | 99 | resourceAccess->open(); |
101 | auto notifier = QSharedPointer<Sink::Notifier>::create(resourceAccess); | 100 | auto notifier = QSharedPointer<Sink::Notifier>::create(resourceAccess); |
@@ -104,7 +103,7 @@ KAsync::Job<void> ResourceControl::inspect(const Inspection &inspectionCommand) | |||
104 | .template then<void>([resourceAccess, notifier, id, time](KAsync::Future<void> &future) { | 103 | .template then<void>([resourceAccess, notifier, id, time](KAsync::Future<void> &future) { |
105 | notifier->registerHandler([&future, id, time](const Notification ¬ification) { | 104 | notifier->registerHandler([&future, id, time](const Notification ¬ification) { |
106 | if (notification.id == id) { | 105 | if (notification.id == id) { |
107 | Trace() << "Inspection complete." << Log::TraceTime(time->elapsed()); | 106 | SinkTrace() << "Inspection complete." << Log::TraceTime(time->elapsed()); |
108 | if (notification.code) { | 107 | if (notification.code) { |
109 | future.setError(-1, "Inspection returned an error: " + notification.message); | 108 | future.setError(-1, "Inspection returned an error: " + notification.message); |
110 | } else { | 109 | } else { |