From 06012af3aadca88f76bcc9d8b51d25386e771bea Mon Sep 17 00:00:00 2001 From: patrick96 Date: Mon, 2 Dec 2019 19:15:40 +0100 Subject: [PATCH] controller: Deliver inputs to all input handlers This is more natural, especially if the same module appears twice in the module list --- include/components/controller.hpp | 2 +- src/components/controller.cpp | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/components/controller.hpp b/include/components/controller.hpp index 2067a4ec..d6755bc7 100644 --- a/include/components/controller.hpp +++ b/include/components/controller.hpp @@ -122,7 +122,7 @@ class controller * Maps the name of the input handler (module name) to the corresponding input * handler */ - std::map> m_inputhandlers; + std::vector> m_inputhandlers; /** * \brief Maximum number of subsequent events to swallow diff --git a/src/components/controller.cpp b/src/components/controller.cpp index 2929a4f3..795ec825 100644 --- a/src/components/controller.cpp +++ b/src/components/controller.cpp @@ -148,7 +148,7 @@ bool controller::run(bool writeback, string snapshot_dst) { if (inp_handler) { m_log.trace("Registering module %s as input handler", module->name_raw()); - m_inputhandlers.emplace(module->name_raw(), inp_handler); + m_inputhandlers.push_back(inp_handler); } if (evt_handler != nullptr) { @@ -415,17 +415,26 @@ void controller::process_inputdata() { auto handler_name = cmd.substr(1, end_pos - 1); auto action = cmd.substr(end_pos + 1); - m_log.info("Forwarding data to input handler (name: %s, action: %s) ", handler_name, action); + m_log.info("Forwarding data to input handlers (name: %s, action: %s) ", handler_name, action); - auto handler = m_inputhandlers.find(handler_name); + int num_delivered = 0; - if (handler == m_inputhandlers.end()) { - m_log.err("The input handler with name '%s' doesn't exist (input: %s)", handler_name, cmd); - return; + // Forwards the action to all input handlers that match the name + for (auto&& handler : m_inputhandlers) { + if (handler->input_handler_name() == handler_name) { + if(!handler->input(string{action})) { + m_log.warn("The '%s' module does not support the '%s' action.", handler_name, action); + } + + num_delivered++; + } } - if(!handler->second->input(string{action})) { - m_log.warn("The '%s' module does not support the '%s' action.", handler_name, action); + if (num_delivered == 0) { + m_log.err("There exists no input handler with name '%s' (input: %s)", handler_name, cmd); + } + else { + m_log.info("Delivered input to %d input handler%s", num_delivered, num_delivered > 1? "s": ""); } return;