use sdbusplus unpack syntax
Rather than defining a variable and then reading it from a message,
sdbusplus also supports directly unpack-ing from the message. Use
this syntax instead as it is more efficient and succinct.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I5ff2aa545ba88d06ea6ac95b83a329c7dfe8594e
diff --git a/chassis_state_manager.cpp b/chassis_state_manager.cpp
index 0215535..9e298e9 100644
--- a/chassis_state_manager.cpp
+++ b/chassis_state_manager.cpp
@@ -270,8 +270,7 @@
using Property = std::string;
using Value = std::variant<bool, uint>;
using PropertyMap = std::map<Property, Value>;
- PropertyMap properties;
- response.read(properties);
+ auto properties = response.unpack<PropertyMap>();
if (std::get<uint>(properties["Type"]) != TYPE_UPS)
{
@@ -374,8 +373,7 @@
using Property = std::string;
using Value = std::variant<std::string>;
using PropertyMap = std::map<Property, Value>;
- PropertyMap properties;
- response.read(properties);
+ auto properties = response.unpack<PropertyMap>();
auto statusStr = std::get<std::string>(properties["Status"]);
auto status =
diff --git a/host_check.cpp b/host_check.cpp
index bc1ade1..436bd92 100644
--- a/host_check.cpp
+++ b/host_check.cpp
@@ -98,8 +98,9 @@
HostFirmware::property_names::current_firmware_condition);
auto response = bus.call(method);
- std::variant<HostFirmware::FirmwareCondition> currentFwCondV;
- response.read(currentFwCondV);
+ auto currentFwCondV = response.unpack<
+ std::variant<HostFirmware::FirmwareCondition>>();
+
auto currentFwCond =
std::get<HostFirmware::FirmwareCondition>(currentFwCondV);
@@ -141,8 +142,8 @@
Chassis::property_names::current_power_state);
auto response = bus.call(method);
- std::variant<Chassis::PowerState> currentPowerStateV;
- response.read(currentPowerStateV);
+ auto currentPowerStateV =
+ response.unpack<std::variant<Chassis::PowerState>>();
auto currentPowerState =
std::get<Chassis::PowerState>(currentPowerStateV);
diff --git a/host_reset_recovery.cpp b/host_reset_recovery.cpp
index 6faf77e..7eff420 100644
--- a/host_reset_recovery.cpp
+++ b/host_reset_recovery.cpp
@@ -52,8 +52,8 @@
auto response = bus.call(method);
- std::variant<ProgressStages> bootProgressV;
- response.read(bootProgressV);
+ auto bootProgressV = response.unpack<std::variant<ProgressStages>>();
+
auto bootProgress = std::get<ProgressStages>(bootProgressV);
if (bootProgress == ProgressStages::Unspecified)
diff --git a/host_state_manager.cpp b/host_state_manager.cpp
index 7637816..59b900f 100644
--- a/host_state_manager.cpp
+++ b/host_state_manager.cpp
@@ -219,8 +219,8 @@
try
{
auto reply = bus.call(methodOneTime);
- std::variant<bool> result;
- reply.read(result);
+ auto result = reply.unpack<std::variant<bool>>();
+
auto autoReboot = std::get<bool>(result);
if (!autoReboot)