blob: 1d4a4d0ddbc6a0f15f7164decbcea6b15099e9e1 [file] [log] [blame]
Szymon Dompkef763c9e2021-03-12 09:19:22 +01001#pragma once
2
3#include "interfaces/sensor.hpp"
4#include "interfaces/sensor_listener.hpp"
5#include "interfaces/threshold.hpp"
6#include "interfaces/trigger_action.hpp"
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +00007#include "types/trigger_types.hpp"
Szymon Dompkef763c9e2021-03-12 09:19:22 +01008
9#include <boost/asio/steady_timer.hpp>
10
11#include <chrono>
12#include <memory>
13#include <vector>
14
15class OnChangeThreshold :
16 public interfaces::Threshold,
17 public interfaces::SensorListener,
18 public std::enable_shared_from_this<OnChangeThreshold>
19{
20 public:
21 OnChangeThreshold(
Szymon Dompke94f71c52021-12-10 07:16:33 +010022 Sensors sensors,
Szymon Dompkef763c9e2021-03-12 09:19:22 +010023 std::vector<std::unique_ptr<interfaces::TriggerAction>> actions);
24 ~OnChangeThreshold()
25 {}
26
27 void initialize() override;
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010028 void sensorUpdated(interfaces::Sensor&, Milliseconds, double) override;
Szymon Dompke94f71c52021-12-10 07:16:33 +010029 LabeledThresholdParam getThresholdParam() const override;
30 void updateSensors(Sensors newSensors) override;
Szymon Dompkef763c9e2021-03-12 09:19:22 +010031
32 private:
Szymon Dompke94f71c52021-12-10 07:16:33 +010033 Sensors sensors;
Szymon Dompkef763c9e2021-03-12 09:19:22 +010034 const std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
Szymon Dompke94f71c52021-12-10 07:16:33 +010035 bool initialized = false;
Szymon Dompke620c65a2022-03-23 21:09:27 +010036 bool isFirstReading = true;
Szymon Dompkef763c9e2021-03-12 09:19:22 +010037
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010038 void commit(const std::string&, Milliseconds, double);
Szymon Dompkef763c9e2021-03-12 09:19:22 +010039};