From 94c3a090542ab273db6fa0bdf234a4f7468406ed Mon Sep 17 00:00:00 2001 From: Giulio Eulisse <10544+ktf@users.noreply.github.com> Date: Tue, 25 Jan 2022 17:27:54 +0100 Subject: [PATCH] GUI Controller provide a controller which can be used to control state transitions from an external GUI. --- fairmq/plugins/control/Control.cxx | 25 +++++++++++++++++++++++++ fairmq/plugins/control/Control.h | 1 + 2 files changed, 26 insertions(+) diff --git a/fairmq/plugins/control/Control.cxx b/fairmq/plugins/control/Control.cxx index cd5204cf..61090a25 100644 --- a/fairmq/plugins/control/Control.cxx +++ b/fairmq/plugins/control/Control.cxx @@ -72,6 +72,9 @@ Control::Control(const string& name, Plugin::Version version, const string& main if (control == "static") { LOG(debug) << "Running builtin controller: static"; fControllerThread = thread(&Control::StaticMode, this); + } else if (control == "gui") { + LOG(debug) << "Running builtin controller: gui"; + fControllerThread = thread(&Control::GUIMode, this); } else if (control == "dynamic" || control == "external" || control == "interactive") { LOG(debug) << "Running builtin controller: interactive"; fControllerThread = thread(&Control::InteractiveMode, this); @@ -380,6 +383,28 @@ try { ReleaseDeviceControl(); } +auto Control::GUIMode() -> void +try { + RunStartupSequence(); + + { + // Wait for next state, which is DeviceState::Ready, + // or for device shutdown request (Ctrl-C) + pair result; + do { + result = fStateQueue.WaitForNext(chrono::milliseconds(50)); + } while (!fDeviceShutdownRequested); + } + + RunShutdownSequence(); +} catch (PluginServices::DeviceControlError& e) { + // If we are here, it means another plugin has taken control. That's fine, just print the + // exception message and do nothing else. + LOG(debug) << e.what(); +} catch (DeviceErrorState&) { + ReleaseDeviceControl(); +} + auto Control::SignalHandler() -> void { while (gSignalCount == 0 && !fPluginShutdownRequested) { diff --git a/fairmq/plugins/control/Control.h b/fairmq/plugins/control/Control.h index 61439d9f..b1c7d24d 100644 --- a/fairmq/plugins/control/Control.h +++ b/fairmq/plugins/control/Control.h @@ -43,6 +43,7 @@ class Control : public Plugin static auto PrintStateMachine() -> void; auto PrintNumberOfConnectedPeers() -> void; auto StaticMode() -> void; + auto GUIMode() -> void; auto SignalHandler() -> void; auto RunShutdownSequence() -> void; auto RunStartupSequence() -> void;