blob: 91a595fa71de04a098087daed75bd5cd191d38b5 [file] [log] [blame]
Szymon Dompkef763c9e2021-03-12 09:19:22 +01001#pragma once
2
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +02003#include "interfaces/clock.hpp"
Szymon Dompkef763c9e2021-03-12 09:19:22 +01004#include "interfaces/sensor.hpp"
5#include "interfaces/sensor_listener.hpp"
6#include "interfaces/threshold.hpp"
7#include "interfaces/trigger_action.hpp"
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +00008#include "types/trigger_types.hpp"
Szymon Dompkef763c9e2021-03-12 09:19:22 +01009
10#include <boost/asio/steady_timer.hpp>
11
12#include <chrono>
13#include <memory>
14#include <vector>
15
16class OnChangeThreshold :
17 public interfaces::Threshold,
18 public interfaces::SensorListener,
19 public std::enable_shared_from_this<OnChangeThreshold>
20{
21 public:
22 OnChangeThreshold(
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020023 const std::string& triggerId, Sensors sensors,
24 std::vector<std::unique_ptr<interfaces::TriggerAction>> actions,
25 std::unique_ptr<interfaces::Clock> clock);
Krzysztof Grobelny41fa80d2022-06-09 13:27:16 +020026 OnChangeThreshold(const OnChangeThreshold&) = delete;
27 OnChangeThreshold(OnChangeThreshold&&) = delete;
Szymon Dompkef763c9e2021-03-12 09:19:22 +010028
29 void initialize() override;
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010030 void sensorUpdated(interfaces::Sensor&, Milliseconds, double) override;
Szymon Dompke94f71c52021-12-10 07:16:33 +010031 LabeledThresholdParam getThresholdParam() const override;
32 void updateSensors(Sensors newSensors) override;
Szymon Dompkef763c9e2021-03-12 09:19:22 +010033
34 private:
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020035 const std::string& triggerId;
Szymon Dompke94f71c52021-12-10 07:16:33 +010036 Sensors sensors;
Szymon Dompkef763c9e2021-03-12 09:19:22 +010037 const std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
Szymon Dompke94f71c52021-12-10 07:16:33 +010038 bool initialized = false;
Szymon Dompke620c65a2022-03-23 21:09:27 +010039 bool isFirstReading = true;
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020040 std::unique_ptr<interfaces::Clock> clock;
Szymon Dompkef763c9e2021-03-12 09:19:22 +010041
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020042 void commit(const std::string&, double);
Szymon Dompkef763c9e2021-03-12 09:19:22 +010043};