blob: c2b59aed50d48c017ca40cba2d7d02a737a8fc25 [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"
Tomáš Pecka261c8862020-11-05 11:23:08 +01008#include "health/State.h"
Tomáš Pecka74b885f2020-06-06 20:02:41 +02009#include "utils/log-fwd.h"
10
Tomáš Pecka261c8862020-11-05 11:23:08 +010011namespace velia::health {
Tomáš Pecka74b885f2020-06-06 20:02:41 +020012
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}