1 #include "on_change_threshold.hpp" 2 3 #include <phosphor-logging/log.hpp> 4 5 OnChangeThreshold::OnChangeThreshold( 6 Sensors sensorsIn, std::vector<std::string> sensorNamesIn, 7 std::vector<std::unique_ptr<interfaces::TriggerAction>> actionsIn) : 8 sensors(std::move(sensorsIn)), 9 sensorNames(std::move(sensorNamesIn)), actions(std::move(actionsIn)) 10 {} 11 12 void OnChangeThreshold::initialize() 13 { 14 for (auto& sensor : sensors) 15 { 16 sensor->registerForUpdates(weak_from_this()); 17 } 18 } 19 20 void OnChangeThreshold::sensorUpdated(interfaces::Sensor& sensor, 21 Milliseconds timestamp) 22 {} 23 24 void OnChangeThreshold::sensorUpdated(interfaces::Sensor& sensor, 25 Milliseconds timestamp, double value) 26 { 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 34 void OnChangeThreshold::commit(const std::string& sensorName, 35 Milliseconds timestamp, double value) 36 { 37 for (const auto& action : actions) 38 { 39 action->commit(sensorName, timestamp, value); 40 } 41 } 42