fix(plugins): Avoid double device control releases

This was not really broken, but it generated a debug log message
containing the keyword 'error' consistently, which is convoluting any
debugging session.

This commit also adds some trace log message on plugin device control
API calls.
This commit is contained in:
Dennis Klein 2021-07-05 20:43:45 +02:00
parent 70fedb3a92
commit 9a2551f984
2 changed files with 11 additions and 1 deletions

View File

@ -79,7 +79,12 @@ class Plugin
auto GetCurrentDeviceState() const -> DeviceState { return fPluginServices->GetCurrentDeviceState(); } auto GetCurrentDeviceState() const -> DeviceState { return fPluginServices->GetCurrentDeviceState(); }
auto TakeDeviceControl() -> void { fPluginServices->TakeDeviceControl(fkName); }; auto TakeDeviceControl() -> void { fPluginServices->TakeDeviceControl(fkName); };
auto StealDeviceControl() -> void { fPluginServices->StealDeviceControl(fkName); }; auto StealDeviceControl() -> void { fPluginServices->StealDeviceControl(fkName); };
auto ReleaseDeviceControl() -> void { fPluginServices->ReleaseDeviceControl(fkName); }; auto ReleaseDeviceControl() -> void
{
if (fPluginServices->GetDeviceController() == fkName) {
fPluginServices->ReleaseDeviceControl(fkName);
}
};
auto ChangeDeviceState(const DeviceStateTransition next) -> bool { return fPluginServices->ChangeDeviceState(fkName, next); } auto ChangeDeviceState(const DeviceStateTransition next) -> bool { return fPluginServices->ChangeDeviceState(fkName, next); }
auto SubscribeToDeviceStateChange(std::function<void(DeviceState)> callback) -> void { fPluginServices->SubscribeToDeviceStateChange(fkName, callback); } auto SubscribeToDeviceStateChange(std::function<void(DeviceState)> callback) -> void { fPluginServices->SubscribeToDeviceStateChange(fkName, callback); }
auto UnsubscribeFromDeviceStateChange() -> void { fPluginServices->UnsubscribeFromDeviceStateChange(fkName); } auto UnsubscribeFromDeviceStateChange() -> void { fPluginServices->UnsubscribeFromDeviceStateChange(fkName); }

View File

@ -6,6 +6,7 @@
* copied verbatim in the file "LICENSE" * * copied verbatim in the file "LICENSE" *
********************************************************************************/ ********************************************************************************/
#include <fairlogger/Logger.h>
#include <fairmq/PluginServices.h> #include <fairmq/PluginServices.h>
#include <fairmq/tools/Strings.h> #include <fairmq/tools/Strings.h>
@ -34,8 +35,10 @@ auto PluginServices::TakeDeviceControl(const string& controller) -> void
if (!fDeviceController) { if (!fDeviceController) {
fDeviceController = controller; fDeviceController = controller;
LOG(trace) << "Plugin '" << controller << "' took over control.";
} else if (fDeviceController == controller) { } else if (fDeviceController == controller) {
// nothing to do // nothing to do
LOG(trace) << "Plugin '" << controller << "' is already in control.";
} else { } else {
throw DeviceControlError{tools::ToString( throw DeviceControlError{tools::ToString(
"Plugin '", controller, "' is not allowed to take over control. ", "Plugin '", controller, "' is not allowed to take over control. ",
@ -49,6 +52,7 @@ auto PluginServices::StealDeviceControl(const string& controller) -> void
lock_guard<mutex> lock{fDeviceControllerMutex}; lock_guard<mutex> lock{fDeviceControllerMutex};
fDeviceController = controller; fDeviceController = controller;
LOG(trace) << "Plugin '" << controller << "' steals control!";
} }
auto PluginServices::ReleaseDeviceControl(const string& controller) -> void auto PluginServices::ReleaseDeviceControl(const string& controller) -> void
@ -58,6 +62,7 @@ auto PluginServices::ReleaseDeviceControl(const string& controller) -> void
if (fDeviceController == controller) { if (fDeviceController == controller) {
fDeviceController = boost::none; fDeviceController = boost::none;
LOG(trace) << "Plugin '" << controller << "' releases control.";
} else { } else {
LOG(debug) << "Plugin '" << controller << "' cannot release control " LOG(debug) << "Plugin '" << controller << "' cannot release control "
<< "because it has no control."; << "because it has no control.";