diff --git a/fairmq/Plugin.h b/fairmq/Plugin.h index e7fee6374..587212829 100644 --- a/fairmq/Plugin.h +++ b/fairmq/Plugin.h @@ -79,7 +79,12 @@ class Plugin auto GetCurrentDeviceState() const -> DeviceState { return fPluginServices->GetCurrentDeviceState(); } auto TakeDeviceControl() -> void { fPluginServices->TakeDeviceControl(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 SubscribeToDeviceStateChange(std::function callback) -> void { fPluginServices->SubscribeToDeviceStateChange(fkName, callback); } auto UnsubscribeFromDeviceStateChange() -> void { fPluginServices->UnsubscribeFromDeviceStateChange(fkName); } diff --git a/fairmq/PluginServices.cxx b/fairmq/PluginServices.cxx index ba039d413..44368c72e 100644 --- a/fairmq/PluginServices.cxx +++ b/fairmq/PluginServices.cxx @@ -6,6 +6,7 @@ * copied verbatim in the file "LICENSE" * ********************************************************************************/ +#include #include #include @@ -34,8 +35,10 @@ auto PluginServices::TakeDeviceControl(const string& controller) -> void if (!fDeviceController) { fDeviceController = controller; + LOG(trace) << "Plugin '" << controller << "' took over control."; } else if (fDeviceController == controller) { // nothing to do + LOG(trace) << "Plugin '" << controller << "' is already in control."; } else { throw DeviceControlError{tools::ToString( "Plugin '", controller, "' is not allowed to take over control. ", @@ -49,6 +52,7 @@ auto PluginServices::StealDeviceControl(const string& controller) -> void lock_guard lock{fDeviceControllerMutex}; fDeviceController = controller; + LOG(trace) << "Plugin '" << controller << "' steals control!"; } auto PluginServices::ReleaseDeviceControl(const string& controller) -> void @@ -58,6 +62,7 @@ auto PluginServices::ReleaseDeviceControl(const string& controller) -> void if (fDeviceController == controller) { fDeviceController = boost::none; + LOG(trace) << "Plugin '" << controller << "' releases control."; } else { LOG(debug) << "Plugin '" << controller << "' cannot release control " << "because it has no control.";