GUI Controller

provide a controller which can be used to control state
transitions from an external GUI.
This commit is contained in:
Giulio Eulisse 2022-01-25 17:27:54 +01:00 committed by Dennis Klein
parent 5f33401d41
commit 3d2ad3fd3e
2 changed files with 26 additions and 0 deletions

View File

@ -72,6 +72,9 @@ Control::Control(const string& name, Plugin::Version version, const string& main
if (control == "static") { if (control == "static") {
LOG(debug) << "Running builtin controller: static"; LOG(debug) << "Running builtin controller: static";
fControllerThread = thread(&Control::StaticMode, this); 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") { } else if (control == "dynamic" || control == "external" || control == "interactive") {
LOG(debug) << "Running builtin controller: interactive"; LOG(debug) << "Running builtin controller: interactive";
fControllerThread = thread(&Control::InteractiveMode, this); fControllerThread = thread(&Control::InteractiveMode, this);
@ -380,6 +383,28 @@ try {
ReleaseDeviceControl(); ReleaseDeviceControl();
} }
auto Control::GUIMode() -> void
try {
RunStartupSequence();
{
// Wait for next state, which is DeviceState::Ready,
// or for device shutdown request (Ctrl-C)
pair<bool, fair::mq::State> 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 auto Control::SignalHandler() -> void
{ {
while (gSignalCount == 0 && !fPluginShutdownRequested) { while (gSignalCount == 0 && !fPluginShutdownRequested) {

View File

@ -43,6 +43,7 @@ class Control : public Plugin
static auto PrintStateMachine() -> void; static auto PrintStateMachine() -> void;
auto PrintNumberOfConnectedPeers() -> void; auto PrintNumberOfConnectedPeers() -> void;
auto StaticMode() -> void; auto StaticMode() -> void;
auto GUIMode() -> void;
auto SignalHandler() -> void; auto SignalHandler() -> void;
auto RunShutdownSequence() -> void; auto RunShutdownSequence() -> void;
auto RunStartupSequence() -> void; auto RunStartupSequence() -> void;