blob: e278c7f5c5530e83af2e4ff30cb5acaef6d475be [file] [log] [blame]
#include "on_change_threshold.hpp"
#include <phosphor-logging/log.hpp>
OnChangeThreshold::OnChangeThreshold(
Sensors sensorsIn, std::vector<std::string> sensorNamesIn,
std::vector<std::unique_ptr<interfaces::TriggerAction>> actionsIn) :
sensors(std::move(sensorsIn)),
sensorNames(std::move(sensorNamesIn)), actions(std::move(actionsIn))
{}
void OnChangeThreshold::initialize()
{
for (auto& sensor : sensors)
{
sensor->registerForUpdates(weak_from_this());
}
}
void OnChangeThreshold::sensorUpdated(interfaces::Sensor& sensor,
Milliseconds timestamp)
{}
void OnChangeThreshold::sensorUpdated(interfaces::Sensor& sensor,
Milliseconds timestamp, double value)
{
auto it =
std::find_if(sensors.begin(), sensors.end(),
[&sensor](const auto& x) { return &sensor == x.get(); });
auto index = std::distance(sensors.begin(), it);
commit(sensorNames.at(index), timestamp, value);
}
void OnChangeThreshold::commit(const std::string& sensorName,
Milliseconds timestamp, double value)
{
for (const auto& action : actions)
{
action->commit(sensorName, timestamp, value);
}
}