Use std::variant
This change converts uses of sdbusplus::message::variant to
std::variant.
Tested:
Triggered a threshold sensor and confirmed that the event is
logged.
Change-Id: I7fe464ad68cde198b5ebbbeb28255c408c439371
Signed-off-by: Jason M. Bills <jason.m.bills@linux.intel.com>
diff --git a/include/threshold_event_monitor.hpp b/include/threshold_event_monitor.hpp
index 9352805..74cc86e 100644
--- a/include/threshold_event_monitor.hpp
+++ b/include/threshold_event_monitor.hpp
@@ -18,6 +18,7 @@
#include <sel_logger.hpp>
#include <sensorutils.hpp>
#include <string_view>
+#include <variant>
enum class thresholdEventOffsets : uint8_t
{
@@ -46,13 +47,11 @@
// Get the event type and assertion details from the message
std::string thresholdInterface;
- boost::container::flat_map<std::string,
- sdbusplus::message::variant<bool>>
+ boost::container::flat_map<std::string, std::variant<bool>>
propertiesChanged;
msg.read(thresholdInterface, propertiesChanged);
std::string event = propertiesChanged.begin()->first;
- bool *pval = sdbusplus::message::variant_ns::get_if<bool>(
- &propertiesChanged.begin()->second);
+ bool *pval = std::get_if<bool>(&propertiesChanged.begin()->second);
if (!pval)
{
std::cerr << "threshold event direction has invalid type\n";
@@ -114,8 +113,7 @@
conn->new_method_call(msg.get_sender(), msg.get_path(),
"org.freedesktop.DBus.Properties", "GetAll");
getSensorValue.append("xyz.openbmc_project.Sensor.Value");
- boost::container::flat_map<std::string,
- sdbusplus::message::variant<double>>
+ boost::container::flat_map<std::string, std::variant<double>>
sensorValue;
try
{
@@ -129,12 +127,12 @@
<< "\n";
return;
}
- double max = sdbusplus::message::variant_ns::visit(
- ipmi::VariantToDoubleVisitor(), sensorValue["MaxValue"]);
- double min = sdbusplus::message::variant_ns::visit(
- ipmi::VariantToDoubleVisitor(), sensorValue["MinValue"]);
- double sensorVal = sdbusplus::message::variant_ns::visit(
- ipmi::VariantToDoubleVisitor(), sensorValue["Value"]);
+ double max =
+ std::visit(ipmi::VariantToDoubleVisitor(), sensorValue["MaxValue"]);
+ double min =
+ std::visit(ipmi::VariantToDoubleVisitor(), sensorValue["MinValue"]);
+ double sensorVal =
+ std::visit(ipmi::VariantToDoubleVisitor(), sensorValue["Value"]);
try
{
eventData[1] = ipmi::getScaledIPMIValue(sensorVal, max, min);
@@ -158,7 +156,7 @@
conn->new_method_call(msg.get_sender(), msg.get_path(),
"org.freedesktop.DBus.Properties", "Get");
getThreshold.append(thresholdInterface, event);
- sdbusplus::message::variant<double> thresholdValue;
+ std::variant<double> thresholdValue;
try
{
sdbusplus::message::message getThresholdResp =
@@ -171,8 +169,8 @@
<< msg.get_path() << "\n";
return;
}
- double thresholdVal = sdbusplus::message::variant_ns::visit(
- ipmi::VariantToDoubleVisitor(), thresholdValue);
+ double thresholdVal =
+ std::visit(ipmi::VariantToDoubleVisitor(), thresholdValue);
try
{
eventData[2] = ipmi::getScaledIPMIValue(thresholdVal, max, min);