#include "utils/conversion_trigger.hpp" #include "utils/transform.hpp" #include namespace utils { namespace ts = utils::tstring; LabeledTriggerThresholdParams ToLabeledThresholdParamConversion::operator()( const std::monostate& arg) const { throw sdbusplus::exception::SdBusError( static_cast(std::errc::invalid_argument), "Provided threshold parameter is invalid"); } LabeledTriggerThresholdParams ToLabeledThresholdParamConversion::operator()( const std::vector& arg) const { return utils::transform(arg, [](const auto& thresholdParam) { const auto& [type, dwellTime, direction, thresholdValue] = thresholdParam; return numeric::LabeledThresholdParam(numeric::toType(type), dwellTime, numeric::toDirection(direction), thresholdValue); }); } LabeledTriggerThresholdParams ToLabeledThresholdParamConversion::operator()( const std::vector& arg) const { return utils::transform(arg, [](const auto& thresholdParam) { const auto& [userId, severity, dwellTime, thresholdValue] = thresholdParam; return discrete::LabeledThresholdParam( userId, discrete::toSeverity(severity), dwellTime, thresholdValue); }); } TriggerThresholdParams FromLabeledThresholdParamConversion::operator()( const std::vector& arg) const { return utils::transform( arg, [](const numeric::LabeledThresholdParam& labeledThresholdParam) { return numeric::ThresholdParam( numeric::typeToString( labeledThresholdParam.at_label()), labeledThresholdParam.at_label(), numeric::directionToString( labeledThresholdParam.at_label()), labeledThresholdParam.at_label()); }); } TriggerThresholdParams FromLabeledThresholdParamConversion::operator()( const std::vector& arg) const { return utils::transform( arg, [](const discrete::LabeledThresholdParam& labeledThresholdParam) { return discrete::ThresholdParam( labeledThresholdParam.at_label(), discrete::severityToString( labeledThresholdParam.at_label()), labeledThresholdParam.at_label(), labeledThresholdParam.at_label()); }); } SensorsInfo fromLabeledSensorsInfo(const std::vector& infos) { return utils::transform(infos, [](const LabeledSensorInfo& val) { return SensorsInfo::value_type( sdbusplus::message::object_path(val.at_label()), val.at_label()); }); } nlohmann::json labeledThresholdParamsToJson( const LabeledTriggerThresholdParams& labeledThresholdParams) { return std::visit([](const auto& lt) { return nlohmann::json(lt); }, labeledThresholdParams); } } // namespace utils