blob: 2fe6912bef9284d592d881520f14c700d89ab1c9 [file] [log] [blame]
Tomáš Pecka74b885f2020-06-06 20:02:41 +02001#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
11namespace velia {
12
13class AbstractInput;
14
15/**
16 * @short Stores registered inputs, output signal and also states of all currently registered inputs.
17 */
18class StateManager : public AbstractManager {
19public:
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
28private:
29 velia::Log m_log;
Jan Kundrátd208f3b2020-11-02 15:16:52 +010030 std::optional<State> m_oldState;
Tomáš Pecka74b885f2020-06-06 20:02:41 +020031
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átd208f3b2020-11-02 15:16:52 +010038}