1 #include "on_change_threshold.hpp" 2 3 #include <phosphor-logging/log.hpp> 4 5 OnChangeThreshold::OnChangeThreshold( 6 std::vector<std::shared_ptr<interfaces::Sensor>> sensorsIn, 7 std::vector<std::string> sensorNamesIn, 8 std::vector<std::unique_ptr<interfaces::TriggerAction>> actionsIn) : 9 sensors(std::move(sensorsIn)), 10 sensorNames(std::move(sensorNamesIn)), actions(std::move(actionsIn)) 11 {} 12 13 void OnChangeThreshold::initialize() 14 { 15 for (auto& sensor : sensors) 16 { 17 sensor->registerForUpdates(weak_from_this()); 18 } 19 } 20 21 void OnChangeThreshold::sensorUpdated(interfaces::Sensor& sensor, 22 uint64_t timestamp) 23 {} 24 25 void OnChangeThreshold::sensorUpdated(interfaces::Sensor& sensor, 26 uint64_t timestamp, double value) 27 { 28 auto it = 29 std::find_if(sensors.begin(), sensors.end(), 30 [&sensor](const auto& x) { return &sensor == x.get(); }); 31 auto index = std::distance(sensors.begin(), it); 32 commit(sensorNames.at(index), timestamp, value); 33 } 34 35 void OnChangeThreshold::commit(const std::string& sensorName, 36 uint64_t timestamp, double value) 37 { 38 for (const auto& action : actions) 39 { 40 action->commit(sensorName, timestamp, value); 41 } 42 } 43