blob: 32a5f657d9b4b79c4de454f24d53f4a985dee654 [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) override;
29 void sensorUpdated(interfaces::Sensor&, Milliseconds, double) override;
Szymon Dompke94f71c52021-12-10 07:16:33 +010030 LabeledThresholdParam getThresholdParam() const override;
31 void updateSensors(Sensors newSensors) override;
Szymon Dompkef763c9e2021-03-12 09:19:22 +010032
33 private:
Szymon Dompke94f71c52021-12-10 07:16:33 +010034 Sensors sensors;
Szymon Dompkef763c9e2021-03-12 09:19:22 +010035 const std::vector<std::unique_ptr<interfaces::TriggerAction>> actions;
Szymon Dompke94f71c52021-12-10 07:16:33 +010036 bool initialized = false;
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};