Trigger: make dbus properties writable
This change allows to modify 'Sensors', 'ReportNames' and 'Thresholds'
dbus properties of Trigger interface. They are required by Redfish to
implement PATCH functionality for Trigger schema.
Some backend changes were required to enable this functionality, and as
such few improvements were made for existing code:
- NumericThreshold and DiscreteThreshold now have common implementation
where it was possible.
- Internal sensor info structure for Trigger is now the same as the one
used for Report. This resulted in breaking compatibility with previous
Trigger persistency data.
- Added getInfo / getParams methods for Sensor and Threshold interfaces.
They are used by Trigger dbus getters and persistency mechanism now,
instead of storing this data in Trigger object.
Testing done:
- Unit tests were expanded and are passing
- dbus setters for Sensors and Thresholds are working and modifications
are reflected by calling appropriate getters.
Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: I7a14c15a30d78ce872342b5f938aba43c77be9c0
diff --git a/src/utils/conversion_trigger.cpp b/src/utils/conversion_trigger.cpp
index ab06a48..e1b835a 100644
--- a/src/utils/conversion_trigger.cpp
+++ b/src/utils/conversion_trigger.cpp
@@ -1,6 +1,7 @@
#include "utils/conversion_trigger.hpp"
#include "utils/transform.hpp"
+#include "utils/tstring.hpp"
#include <sdbusplus/exception.hpp>
@@ -72,11 +73,61 @@
{
return utils::transform(infos, [](const LabeledSensorInfo& val) {
return SensorsInfo::value_type(
- sdbusplus::message::object_path(val.at_label<ts::SensorPath>()),
+ sdbusplus::message::object_path(val.at_label<ts::Path>()),
val.at_label<ts::Metadata>());
});
}
+TriggerThresholdParams
+ fromLabeledThresholdParam(const std::vector<LabeledThresholdParam>& params)
+{
+ namespace ts = utils::tstring;
+ if (isFirstElementOfType<std::monostate>(params))
+ {
+ return std::vector<discrete::ThresholdParam>();
+ }
+
+ if (isFirstElementOfType<discrete::LabeledThresholdParam>(params))
+ {
+ return utils::transform(params, [](const auto& param) {
+ const discrete::LabeledThresholdParam* paramUnpacked =
+ std::get_if<discrete::LabeledThresholdParam>(¶m);
+ if (!paramUnpacked)
+ {
+ throw std::runtime_error(
+ "Mixing threshold types is not allowed");
+ }
+ return discrete::ThresholdParam(
+ paramUnpacked->at_label<ts::UserId>(),
+ discrete::severityToString(
+ paramUnpacked->at_label<ts::Severity>()),
+ paramUnpacked->at_label<ts::DwellTime>(),
+ paramUnpacked->at_label<ts::ThresholdValue>());
+ });
+ }
+
+ if (isFirstElementOfType<numeric::LabeledThresholdParam>(params))
+ {
+ return utils::transform(params, [](const auto& param) {
+ const numeric::LabeledThresholdParam* paramUnpacked =
+ std::get_if<numeric::LabeledThresholdParam>(¶m);
+ if (!paramUnpacked)
+ {
+ throw std::runtime_error(
+ "Mixing threshold types is not allowed");
+ }
+ return numeric::ThresholdParam(
+ numeric::typeToString(paramUnpacked->at_label<ts::Type>()),
+ paramUnpacked->at_label<ts::DwellTime>(),
+ numeric::directionToString(
+ paramUnpacked->at_label<ts::Direction>()),
+ paramUnpacked->at_label<ts::ThresholdValue>());
+ });
+ }
+
+ throw std::runtime_error("Incorrect threshold params");
+}
+
nlohmann::json labeledThresholdParamsToJson(
const LabeledTriggerThresholdParams& labeledThresholdParams)
{