Tomáš Pecka | 74b885f | 2020-06-06 20:02:41 +0200 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <functional> |
| 4 | #include <map> |
| 5 | #include <memory> |
| 6 | #include <mutex> |
| 7 | #include "AbstractManager.h" |
| 8 | #include "State.h" |
| 9 | #include "utils/log-fwd.h" |
| 10 | |
| 11 | namespace velia { |
| 12 | |
| 13 | class AbstractInput; |
| 14 | |
| 15 | /** |
| 16 | * @short Stores registered inputs, output signal and also states of all currently registered inputs. |
| 17 | */ |
| 18 | class StateManager : public AbstractManager { |
| 19 | public: |
| 20 | StateManager(); |
| 21 | ~StateManager() override; |
| 22 | |
| 23 | void registerInput(void* input, State value) override; |
| 24 | void unregisterInput(void* input) override; |
| 25 | |
| 26 | void updateState(void* input, State value) override; |
| 27 | |
| 28 | private: |
| 29 | velia::Log m_log; |
Jan Kundrát | d208f3b | 2020-11-02 15:16:52 +0100 | [diff] [blame^] | 30 | std::optional<State> m_oldState; |
Tomáš Pecka | 74b885f | 2020-06-06 20:02:41 +0200 | [diff] [blame] | 31 | |
| 32 | /** Registered inputs are identified by their memory location. The pointer only serves as an ID, this class does not manage the input pointers lifetime */ |
| 33 | std::map<void*, State> m_inputs; |
| 34 | |
| 35 | /** @brief Recompute output and fire output signal. Should be called on every input change. */ |
| 36 | void computeOutput(); |
| 37 | }; |
Jan Kundrát | d208f3b | 2020-11-02 15:16:52 +0100 | [diff] [blame^] | 38 | } |