Removed redundant string parsing
Newer sdbusplus builds support the converting of enumerations
to read directly as an std::string which eliminates the need
to unnecessarily parse them as strings.
Signed-off-by: Corey Hardesty <corey.hardesty@icloud.com>
Change-Id: Ic58b0ebac9c4769cc6aff291e9a1a48dcb16ed18
diff --git a/host_check.cpp b/host_check.cpp
index f834c42..2bdcb1f 100644
--- a/host_check.cpp
+++ b/host_check.cpp
@@ -9,6 +9,7 @@
#include <sdbusplus/bus.hpp>
#include <sdbusplus/exception.hpp>
#include <xyz/openbmc_project/Condition/HostFirmware/server.hpp>
+#include <xyz/openbmc_project/State/Chassis/server.hpp>
#include <cstdio>
#include <cstdlib>
@@ -47,6 +48,7 @@
// running over it
bool checkFirmwareConditionRunning(sdbusplus::bus::bus& bus)
{
+ using FirmwareCondition = HostFirmware::FirmwareCondition;
// Find all implementations of host firmware condition interface
auto mapper = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
MAPPER_INTERFACE, "GetSubTree");
@@ -100,13 +102,12 @@
auto response = bus.call(method);
- std::variant<std::string> currentFwCond;
- response.read(currentFwCond);
+ std::variant<FirmwareCondition> currentFwCondV;
+ response.read(currentFwCondV);
+ auto currentFwCond =
+ std::get<FirmwareCondition>(currentFwCondV);
- if (std::get<std::string>(currentFwCond) ==
- "xyz.openbmc_project.Condition.HostFirmware."
- "FirmwareCondition."
- "Running")
+ if (currentFwCond == FirmwareCondition::Running)
{
return true;
}
@@ -131,17 +132,19 @@
try
{
+ using PowerState =
+ sdbusplus::xyz::openbmc_project::State::server::Chassis::PowerState;
auto method = bus.new_method_call(svcname.c_str(), objpath.c_str(),
PROPERTY_INTERFACE, "Get");
method.append(CHASSIS_STATE_INTF, CHASSIS_STATE_POWER_PROP);
auto response = bus.call(method);
- std::variant<std::string> currentPowerState;
- response.read(currentPowerState);
+ std::variant<PowerState> currentPowerStateV;
+ response.read(currentPowerStateV);
+ auto currentPowerState = std::get<PowerState>(currentPowerStateV);
- if (std::get<std::string>(currentPowerState) ==
- "xyz.openbmc_project.State.Chassis.PowerState.On")
+ if (currentPowerState == PowerState::On)
{
return true;
}