blob: e278c7f5c5530e83af2e4ff30cb5acaef6d475be [file] [log] [blame]
Szymon Dompkef763c9e2021-03-12 09:19:22 +01001#include "on_change_threshold.hpp"
2
3#include <phosphor-logging/log.hpp>
4
5OnChangeThreshold::OnChangeThreshold(
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +00006 Sensors sensorsIn, std::vector<std::string> sensorNamesIn,
Szymon Dompkef763c9e2021-03-12 09:19:22 +01007 std::vector<std::unique_ptr<interfaces::TriggerAction>> actionsIn) :
8 sensors(std::move(sensorsIn)),
9 sensorNames(std::move(sensorNamesIn)), actions(std::move(actionsIn))
10{}
11
12void OnChangeThreshold::initialize()
13{
14 for (auto& sensor : sensors)
15 {
16 sensor->registerForUpdates(weak_from_this());
17 }
18}
19
20void OnChangeThreshold::sensorUpdated(interfaces::Sensor& sensor,
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010021 Milliseconds timestamp)
Szymon Dompkef763c9e2021-03-12 09:19:22 +010022{}
23
24void OnChangeThreshold::sensorUpdated(interfaces::Sensor& sensor,
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010025 Milliseconds timestamp, double value)
Szymon Dompkef763c9e2021-03-12 09:19:22 +010026{
27 auto it =
28 std::find_if(sensors.begin(), sensors.end(),
29 [&sensor](const auto& x) { return &sensor == x.get(); });
30 auto index = std::distance(sensors.begin(), it);
31 commit(sensorNames.at(index), timestamp, value);
32}
33
34void OnChangeThreshold::commit(const std::string& sensorName,
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010035 Milliseconds timestamp, double value)
Szymon Dompkef763c9e2021-03-12 09:19:22 +010036{
37 for (const auto& action : actions)
38 {
39 action->commit(sensorName, timestamp, value);
40 }
41}