std::variant: Fix use of incompatible api
Refactors any uses of the mapbox variant specific api and converts them
to an api compatible with std::variant and mapbox variant.
Tested:
Built and run through the unit test suite.
Change-Id: Ie9b83fd638c495859fe98b5de86d9d3c7c1a27af
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/chassis_state_manager.cpp b/chassis_state_manager.cpp
index d721460..16cecec 100644
--- a/chassis_state_manager.cpp
+++ b/chassis_state_manager.cpp
@@ -89,7 +89,7 @@
goto fail;
}
- if (pgood == 1)
+ if (sdbusplus::message::variant_ns::get<int>(pgood) == 1)
{
log<level::INFO>("Initial Chassis State will be On",
entry("CHASSIS_CURRENT_POWER_STATE=%s",
@@ -204,14 +204,10 @@
}
result.read(currentState);
-
- if (currentState != ACTIVE_STATE && currentState != ACTIVATING_STATE)
- {
- // False - not active
- return false;
- }
- // True - active
- return true;
+ const auto& currentStateStr =
+ sdbusplus::message::variant_ns::get<std::string>(currentState);
+ return currentStateStr == ACTIVE_STATE ||
+ currentStateStr == ACTIVATING_STATE;
}
int Chassis::sysStateChange(sdbusplus::message::message& msg)
diff --git a/discover_system_state.cpp b/discover_system_state.cpp
index 5ce94b4..92d3416 100644
--- a/discover_system_state.cpp
+++ b/discover_system_state.cpp
@@ -157,7 +157,7 @@
sdbusplus::message::variant<std::string> result;
reply.read(result);
- auto powerPolicy = result.get<std::string>();
+ auto powerPolicy = sdbusplus::message::variant_ns::get<std::string>(result);
log<level::INFO>("Host power is off, checking power policy",
entry("POWER_POLICY=%s", powerPolicy.c_str()));
diff --git a/host_state_manager.cpp b/host_state_manager.cpp
index 38c9469..aaac46c 100644
--- a/host_state_manager.cpp
+++ b/host_state_manager.cpp
@@ -162,14 +162,10 @@
}
result.read(currentState);
-
- if (currentState != ACTIVE_STATE && currentState != ACTIVATING_STATE)
- {
- // False - not active
- return false;
- }
- // True - active
- return true;
+ const auto& currentStateStr =
+ sdbusplus::message::variant_ns::get<std::string>(currentState);
+ return currentStateStr == ACTIVE_STATE ||
+ currentStateStr == ACTIVATING_STATE;
}
bool Host::isAutoReboot()
@@ -189,7 +185,7 @@
sdbusplus::message::variant<bool> result;
reply.read(result);
- auto autoReboot = result.get<bool>();
+ auto autoReboot = sdbusplus::message::variant_ns::get<bool>(result);
auto rebootCounterParam = reboot::RebootAttempts::attemptsLeft();
if (autoReboot)