diff --git a/server/message_parser.cpp b/server/message_parser.cpp index d660ab6..fd2f101 100644 --- a/server/message_parser.cpp +++ b/server/message_parser.cpp @@ -32,12 +32,22 @@ json Simulators::command_parser(json command) { case Command::get_UI_element: SPDLOG_INFO("Command {}: {}", type, (size_t)command.at("id")); + if (is_not_active()) + { + SPDLOG_ERROR("Command got called but there is no active simulator"); + return j; + } j["response"]["type"] = type; j["response"]["UI_item"] = invoke_active_simulator()->get_UI_item(command.at("id"))->to_json(command.at("id")); break; case Command::get_UI_elements: SPDLOG_INFO("Command {}", type); + if (is_not_active()) + { + SPDLOG_ERROR("Command got called but there is no active simulator"); + return j; + } j["response"]["type"] = type; j["response"]["UI_items"] = invoke_active_simulator()->get_UI_items()["UI_items"]; break; diff --git a/server/simulators.cpp b/server/simulators.cpp index 2c9f6f9..3b4add8 100644 --- a/server/simulators.cpp +++ b/server/simulators.cpp @@ -151,6 +151,11 @@ std::vector Simulators::list_simulators() const return names; } +bool Simulators::is_not_active() const +{ + return this->m_current_simulator.empty(); +} + Simulator_base *Simulators::invoke_active_simulator() { std::lock_guard lock(m_mutex); diff --git a/server/simulators.hpp b/server/simulators.hpp index 00b5a9e..f103806 100644 --- a/server/simulators.hpp +++ b/server/simulators.hpp @@ -52,6 +52,7 @@ class Simulators : public QObject void stop(); void switch_simulator(std::string name); std::vector list_simulators() const; + bool is_not_active() const; Simulator_base *invoke_active_simulator(); json changed_UI_items();