Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 3 | #include "interfaces/clock.hpp" |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 4 | #include "interfaces/sensor.hpp" |
| 5 | #include "interfaces/sensor_listener.hpp" |
| 6 | #include "interfaces/threshold.hpp" |
| 7 | #include "interfaces/trigger_action.hpp" |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 8 | #include "types/trigger_types.hpp" |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 9 | |
| 10 | #include <boost/asio/steady_timer.hpp> |
| 11 | |
| 12 | #include <chrono> |
| 13 | #include <memory> |
| 14 | #include <vector> |
| 15 | |
| 16 | class OnChangeThreshold : |
| 17 | public interfaces::Threshold, |
| 18 | public interfaces::SensorListener, |
| 19 | public std::enable_shared_from_this<OnChangeThreshold> |
| 20 | { |
| 21 | public: |
| 22 | OnChangeThreshold( |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 23 | const std::string& triggerId, Sensors sensors, |
| 24 | std::vector<std::unique_ptr<interfaces::TriggerAction>> actions, |
| 25 | std::unique_ptr<interfaces::Clock> clock); |
Krzysztof Grobelny | 41fa80d | 2022-06-09 13:27:16 +0200 | [diff] [blame] | 26 | OnChangeThreshold(const OnChangeThreshold&) = delete; |
| 27 | OnChangeThreshold(OnChangeThreshold&&) = delete; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 28 | |
| 29 | void initialize() override; |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 30 | void sensorUpdated(interfaces::Sensor&, Milliseconds, double) override; |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 31 | LabeledThresholdParam getThresholdParam() const override; |
| 32 | void updateSensors(Sensors newSensors) override; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 33 | |
| 34 | private: |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 35 | const std::string& triggerId; |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 36 | Sensors sensors; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 37 | const std::vector<std::unique_ptr<interfaces::TriggerAction>> actions; |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 38 | bool initialized = false; |
Szymon Dompke | 620c65a | 2022-03-23 21:09:27 +0100 | [diff] [blame] | 39 | bool isFirstReading = true; |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 40 | std::unique_ptr<interfaces::Clock> clock; |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 41 | |
Szymon Dompke | b7b7e1b | 2022-05-19 10:15:48 +0200 | [diff] [blame] | 42 | void commit(const std::string&, double); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 43 | }; |