diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-07 22:23:49 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-07-07 22:23:49 +0200 |
commit | da2b049e248c1ad7efeb53685158a205335e4e36 (patch) | |
tree | 1e7e5e940e9b760b2108081b1d2f3879cebdb0ff /common/resourcecontrol.cpp | |
parent | 9bcb822963fc96c94dbe7dcc4134dcd2dac454ff (diff) | |
download | sink-da2b049e248c1ad7efeb53685158a205335e4e36.tar.gz sink-da2b049e248c1ad7efeb53685158a205335e4e36.zip |
A new debug system.
Instead of a single #define as debug area the new system allows for an
identifier for each debug message with the structure component.area.
The component is a dot separated identifier of the runtime component,
such as the process or the plugin.
The area is the code component, and can be as such defined at
compiletime.
The idea of this system is that it becomes possible to i.e. look at the
output of all messages in the query subsystem of a specific resource
(something that happens in the client process, but in the
resource-specific subcomponent).
The new macros are supposed to be less likely to clash with other names,
hence the new names.
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 { |