1 #pragma once
2 
3 #include "interfaces/clock.hpp"
4 #include "interfaces/sensor.hpp"
5 #include "interfaces/sensor_listener.hpp"
6 #include "interfaces/threshold.hpp"
7 #include "interfaces/trigger_action.hpp"
8 #include "types/trigger_types.hpp"
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(
23         const std::string& triggerId, Sensors sensors,
24         std::vector<std::unique_ptr<interfaces::TriggerAction>> actions,
25         std::unique_ptr<interfaces::Clock> clock);
26     OnChangeThreshold(const OnChangeThreshold&) = delete;
27     OnChangeThreshold(OnChangeThreshold&&) = delete;
28 
29     void initialize() override;
30     void sensorUpdated(interfaces::Sensor&, Milliseconds, double) override;
31     LabeledThresholdParam getThresholdParam() const override;
32     void updateSensors(Sensors newSensors) override;
33 
34   private:
35     const std::string& triggerId;
36     Sensors sensors;
37     const std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
38     bool initialized = false;
39     bool isFirstReading = true;
40     std::unique_ptr<interfaces::Clock> clock;
41 
42     void commit(const std::string&, double);
43 };
44