Remove variant from Thresholds interface
The Thresholds property on the Trigger interface is currently defined as
a relatively complex type:
variant<
array<discrete struct>
array<numeric struct>
>
This causes some oddities in unpacking given that Dbus properties are
already a variant, applications consuming this interface have to double
wrap the variant. This was confusing enough that bmcweb has to keep the
trigger types separate, and cannot use the common typing.
This commit changes by adding two new parameters
NumericThresholds: array<numeric struct>
DiscreteThresholds: array<discrete struct>
Which deduplicates the double wrapped variant.
The intent is that this duplicated interface will exist for a transition
period of a week or two, while bmcweb (the only user of this)
transitions the code to use the new properties, then a followup common
will drop the thresholds properly.
Tested: WIP
Change-Id: I6717d4075de53c91aa179a90c7a844c4a13534cc
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/src/trigger.cpp b/src/trigger.cpp
index ca6804c..0b94711 100644
--- a/src/trigger.cpp
+++ b/src/trigger.cpp
@@ -85,6 +85,61 @@
});
dbusIface.register_property_rw(
+ "DiscreteThresholds", std::vector<discrete::ThresholdParam>{},
+ sdbusplus::vtable::property_::emits_change,
+ [this, &triggerFactory](
+ const std::vector<discrete::ThresholdParam>& newVal,
+ std::vector<discrete::ThresholdParam>& oldVal) {
+ LabeledTriggerThresholdParams newThresholdParams =
+ utils::ToLabeledThresholdParamConversion()(newVal);
+ TriggerManager::verifyThresholdParams(newThresholdParams);
+ triggerFactory.updateThresholds(thresholds, *id, triggerActions,
+ reportIds, sensors,
+ newThresholdParams);
+ oldVal = std::move(newVal);
+ return 1;
+ },
+ [this](const auto&) {
+ TriggerThresholdParams unlabeled =
+ fromLabeledThresholdParam(getLabeledThresholds());
+ auto* ptr =
+ std::get_if<std::vector<discrete::ThresholdParam>>(&unlabeled);
+ if (ptr == nullptr)
+ {
+ // If internal type doesn't match, return empty set
+ return std::vector<discrete::ThresholdParam>{};
+ }
+ return *ptr;
+ });
+
+ dbusIface.register_property_rw(
+ "NumericThresholds", std::vector<numeric::ThresholdParam>{},
+ sdbusplus::vtable::property_::emits_change,
+ [this, &triggerFactory](
+ const std::vector<numeric::ThresholdParam>& newVal,
+ std::vector<numeric::ThresholdParam>& oldVal) {
+ LabeledTriggerThresholdParams newThresholdParams =
+ utils::ToLabeledThresholdParamConversion()(newVal);
+ TriggerManager::verifyThresholdParams(newThresholdParams);
+ triggerFactory.updateThresholds(thresholds, *id, triggerActions,
+ reportIds, sensors,
+ newThresholdParams);
+ oldVal = std::move(newVal);
+ return 1;
+ },
+ [this](const auto&) {
+ TriggerThresholdParams unlabeled =
+ fromLabeledThresholdParam(getLabeledThresholds());
+ auto* ptr =
+ std::get_if<std::vector<numeric::ThresholdParam>>(&unlabeled);
+ if (ptr == nullptr)
+ {
+ // If internal type doesn't match, return empty set
+ return std::vector<numeric::ThresholdParam>{};
+ }
+ return *ptr;
+ });
+ dbusIface.register_property_rw(
"Sensors", SensorsInfo{},
sdbusplus::vtable::property_::emits_change,
[this, &triggerFactory](auto newVal, auto& oldVal) {