Make trigger use common types
Trigger having its own variant causes us to duplicate code. This was
left out of the original refactoring because it was complex given
the variant of a variant status.
This commit finally does the port.
Tested: Unclear what tests exist for triggers that would use this code
```
curl -k --user "root:0penBmc" -H "Content-Type: application/json" -X POST https://192.168.7.2/redfish/v1/TelemetryService/Triggers -d '{"Name": "eds", "NumericThresholds": {"LowerCritical": {"Reading": 1.0, "Activation": "Increasing", "DwellTime": "P1S"}}}'
```
Succeeds. GET on the resource results in:
{
"@odata.id": "/redfish/v1/TelemetryService/Triggers/eds",
"@odata.type": "#Triggers.v1_2_0.Triggers",
"Id": "eds",
"Links": {
"MetricReportDefinitions": []
},
"MetricProperties": [],
"MetricType": "Numeric",
"Name": "eds",
"NumericThresholds": {
"LowerCritical": {
"Activation": "Increasing",
"DwellTime": "PT1.000S",
"Reading": 1.0
}
},
"TriggerActions": []
}
Change-Id: I8f683cc9423ee2ba111d3ca1889e78f7d33433c9
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/include/dbus_utility.hpp b/include/dbus_utility.hpp
index 68b3930..50d75c5 100644
--- a/include/dbus_utility.hpp
+++ b/include/dbus_utility.hpp
@@ -59,7 +59,6 @@
uint16_t,
uint8_t,
bool,
- sdbusplus::message::unix_fd,
std::vector<uint32_t>,
std::vector<uint16_t>,
sdbusplus::message::object_path,
@@ -70,7 +69,15 @@
std::vector<std::tuple<uint32_t, size_t>>,
std::vector<std::tuple<
std::vector<std::tuple<sdbusplus::message::object_path, std::string>>,
- std::string, std::string, uint64_t>>
+ std::string, std::string, uint64_t>>,
+ std::vector<std::pair<sdbusplus::message::object_path, std::string>>,
+
+ // TODO This needs looked at. It's used in the trigger system, but a
+ // variant of a variant seems really odd
+ std::variant<
+ std::vector<std::tuple<std::string, uint64_t, std::string, double>>,
+ std::vector<std::tuple<std::string, std::string, uint64_t, std::string>>
+ >
>;
// clang-format on
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 8a6830e..c35a2be 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -66,6 +66,19 @@
#include <variant>
#include <vector>
+namespace nlohmann
+{
+template <typename... Args>
+struct adl_serializer<std::variant<Args...>>
+{
+ // NOLINTNEXTLINE(readability-identifier-naming)
+ static void to_json(json& j, const std::variant<Args...>& args)
+ {
+ std::visit([&j](auto&& val) { j = val; }, args);
+ }
+};
+} // namespace nlohmann
+
namespace crow
{
namespace openbmc_mapper
@@ -204,20 +217,8 @@
for (const auto& [name, value] : propertiesList)
{
nlohmann::json& propertyJson = objectJson[name];
- std::visit(
- [&propertyJson](auto&& val) {
- if constexpr (std::is_same_v<
- std::decay_t<decltype(val)>,
- sdbusplus::message::unix_fd>)
- {
- propertyJson = val.fd;
- }
- else
- {
- propertyJson = val;
- }
- },
- value);
+ std::visit([&propertyJson](auto&& val) { propertyJson = val; },
+ value);
}
});
}
diff --git a/redfish-core/lib/trigger.hpp b/redfish-core/lib/trigger.hpp
index 306742a..047fbb7 100644
--- a/redfish-core/lib/trigger.hpp
+++ b/redfish-core/lib/trigger.hpp
@@ -41,18 +41,9 @@
std::variant<std::vector<NumericThresholdParams>,
std::vector<DiscreteThresholdParams>>;
-using TriggerThresholdParamsExt =
- std::variant<std::monostate, std::vector<NumericThresholdParams>,
- std::vector<DiscreteThresholdParams>>;
-
using TriggerSensorsParams =
std::vector<std::pair<sdbusplus::message::object_path, std::string>>;
-using TriggerGetParamsVariant =
- std::variant<std::monostate, bool, std::string, TriggerThresholdParamsExt,
- TriggerSensorsParams, std::vector<std::string>,
- std::vector<sdbusplus::message::object_path>>;
-
inline triggers::TriggerActionEnum
toRedfishTriggerAction(std::string_view dbusValue)
{
@@ -740,7 +731,7 @@
}
inline std::optional<nlohmann::json::array_t>
- getDiscreteTriggers(const TriggerThresholdParamsExt& thresholdParams)
+ getDiscreteTriggers(const TriggerThresholdParams& thresholdParams)
{
nlohmann::json::array_t triggers;
const std::vector<DiscreteThresholdParams>* discreteParams =
@@ -772,7 +763,7 @@
}
inline std::optional<nlohmann::json>
- getNumericThresholds(const TriggerThresholdParamsExt& thresholdParams)
+ getNumericThresholds(const TriggerThresholdParams& thresholdParams)
{
nlohmann::json::object_t thresholds;
const std::vector<NumericThresholdParams>* numericParams =
@@ -841,17 +832,15 @@
return metricProperties;
}
-inline bool fillTrigger(
- nlohmann::json& json, const std::string& id,
- const std::vector<std::pair<std::string, TriggerGetParamsVariant>>&
- properties)
+inline bool fillTrigger(nlohmann::json& json, const std::string& id,
+ const dbus::utility::DBusPropertiesMap& properties)
{
const std::string* name = nullptr;
const bool* discrete = nullptr;
const TriggerSensorsParams* sensors = nullptr;
const std::vector<sdbusplus::message::object_path>* reports = nullptr;
const std::vector<std::string>* triggerActions = nullptr;
- const TriggerThresholdParamsExt* thresholds = nullptr;
+ const TriggerThresholdParams* thresholds = nullptr;
const bool success = sdbusplus::unpackPropertiesNoThrow(
dbus_utils::UnpackErrorPrinter(), properties, "Name", name, "Discrete",
@@ -1021,9 +1010,7 @@
telemetry::triggerInterface,
[asyncResp,
id](const boost::system::error_code& ec,
- const std::vector<std::pair<
- std::string, telemetry::TriggerGetParamsVariant>>&
- ret) {
+ const dbus::utility::DBusPropertiesMap& ret) {
if (ec.value() == EBADR ||
ec == boost::system::errc::host_unreachable)
{
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index cd0d972..b033b66 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -482,7 +482,7 @@
});
}
- dbus::utility::DbusVariantType unixFd(
+ std::variant<sdbusplus::message::unix_fd> unixFd(
std::in_place_type<sdbusplus::message::unix_fd>, fd);
sdbusplus::message::object_path path(