Using sdbusplus::asio::getProperty
It simplifies a lot of code and after changing sdbusplus implementation
slightly reduces binary size if used together with:
https://gerrit.openbmc-project.xyz/c/openbmc/sdbusplus/+/49467
* Uncompressed size: 3033148 -> 3012164, -20984 B
* gzip compressed size: 1220586 -> 1214625, -5961 B
Tested:
- Redfish validator output is the same before and after the change
Change-Id: Ibe3227d3f4230de2363ba3d9396e51130c8240a5
Signed-off-by: Jonathan Doman <jonathan.doman@intel.com>
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index b3094df..a21b6a0 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -15,6 +15,7 @@
*/
#pragma once
+#include "dbus_singleton.hpp"
#include "health.hpp"
#include "led.hpp"
#include "pcie.hpp"
@@ -24,6 +25,7 @@
#include <boost/container/flat_map.hpp>
#include <dbus_utility.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
#include <utils/fw_utils.hpp>
#include <utils/json_utils.hpp>
@@ -42,15 +44,9 @@
*/
inline void
updateDimmProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
- const dbus::utility::DbusVariantType& dimmState)
+ bool isDimmFunctional)
{
- const bool* isDimmFunctional = std::get_if<bool>(&dimmState);
- if (isDimmFunctional == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- BMCWEB_LOG_DEBUG << "Dimm Functional: " << *isDimmFunctional;
+ BMCWEB_LOG_DEBUG << "Dimm Functional: " << isDimmFunctional;
// Set it as Enabled if at least one DIMM is functional
// Update STATE only if previous State was DISABLED and current Dimm is
@@ -59,7 +55,7 @@
aResp->res.jsonValue["MemorySummary"]["Status"]["State"];
if (prevMemSummary == "Disabled")
{
- if (*isDimmFunctional == true)
+ if (isDimmFunctional == true)
{
aResp->res.jsonValue["MemorySummary"]["Status"]["State"] =
"Enabled";
@@ -75,20 +71,13 @@
*
* @return None.
*/
-inline void modifyCpuPresenceState(
- const std::shared_ptr<bmcweb::AsyncResp>& aResp,
- const dbus::utility::DbusVariantType& cpuPresenceState)
+inline void
+ modifyCpuPresenceState(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
+ bool isCpuPresent)
{
- const bool* isCpuPresent = std::get_if<bool>(&cpuPresenceState);
+ BMCWEB_LOG_DEBUG << "Cpu Present: " << isCpuPresent;
- if (isCpuPresent == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- BMCWEB_LOG_DEBUG << "Cpu Present: " << *isCpuPresent;
-
- if (*isCpuPresent == true)
+ if (isCpuPresent == true)
{
nlohmann::json& procCount =
aResp->res.jsonValue["ProcessorSummary"]["Count"];
@@ -111,18 +100,11 @@
*
* @return None.
*/
-inline void modifyCpuFunctionalState(
- const std::shared_ptr<bmcweb::AsyncResp>& aResp,
- const dbus::utility::DbusVariantType& cpuFunctionalState)
+inline void
+ modifyCpuFunctionalState(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
+ bool isCpuFunctional)
{
- const bool* isCpuFunctional = std::get_if<bool>(&cpuFunctionalState);
-
- if (isCpuFunctional == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- BMCWEB_LOG_DEBUG << "Cpu Functional: " << *isCpuFunctional;
+ BMCWEB_LOG_DEBUG << "Cpu Functional: " << isCpuFunctional;
nlohmann::json& prevProcState =
aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"];
@@ -132,7 +114,7 @@
// Functional.
if (prevProcState == "Disabled")
{
- if (*isCpuFunctional == true)
+ if (isCpuFunctional == true)
{
aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] =
"Enabled";
@@ -149,39 +131,37 @@
BMCWEB_LOG_DEBUG << "Got " << properties.size() << " Cpu properties.";
- auto getCpuPresenceState =
- [aResp](const boost::system::error_code ec3,
- const dbus::utility::DbusVariantType& cpuPresenceCheck) {
- if (ec3)
- {
- BMCWEB_LOG_ERROR << "DBUS response error " << ec3;
- return;
- }
- modifyCpuPresenceState(aResp, cpuPresenceCheck);
- };
+ auto getCpuPresenceState = [aResp](const boost::system::error_code ec3,
+ const bool cpuPresenceCheck) {
+ if (ec3)
+ {
+ BMCWEB_LOG_ERROR << "DBUS response error " << ec3;
+ return;
+ }
+ modifyCpuPresenceState(aResp, cpuPresenceCheck);
+ };
- auto getCpuFunctionalState =
- [aResp](const boost::system::error_code ec3,
- const dbus::utility::DbusVariantType& cpuFunctionalCheck) {
- if (ec3)
- {
- BMCWEB_LOG_ERROR << "DBUS response error " << ec3;
- return;
- }
- modifyCpuFunctionalState(aResp, cpuFunctionalCheck);
- };
+ auto getCpuFunctionalState = [aResp](const boost::system::error_code ec3,
+ const bool cpuFunctionalCheck) {
+ if (ec3)
+ {
+ BMCWEB_LOG_ERROR << "DBUS response error " << ec3;
+ return;
+ }
+ modifyCpuFunctionalState(aResp, cpuFunctionalCheck);
+ };
// Get the Presence of CPU
- crow::connections::systemBus->async_method_call(
- std::move(getCpuPresenceState), service, path,
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Inventory.Item", "Present");
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus, service, path,
+ "xyz.openbmc_project.Inventory.Item", "Present",
+ std::move(getCpuPresenceState));
// Get the Functional State
- crow::connections::systemBus->async_method_call(
- std::move(getCpuFunctionalState), service, path,
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional");
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus, service, path,
+ "xyz.openbmc_project.State.Decorator.OperationalStatus", "Functional",
+ std::move(getCpuFunctionalState));
for (const auto& property : properties)
{
@@ -377,13 +357,16 @@
}
else
{
- auto getDimmProperties =
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus,
+ service, path,
+ "xyz.openbmc_project.State."
+ "Decorator.OperationalStatus",
+ "Functional",
[aResp](
const boost::system::error_code
ec3,
- const dbus::utility::
- DbusVariantType&
- dimmState) {
+ bool dimmState) {
if (ec3)
{
BMCWEB_LOG_ERROR
@@ -393,15 +376,7 @@
}
updateDimmProperties(aResp,
dimmState);
- };
- crow::connections::systemBus
- ->async_method_call(
- std::move(getDimmProperties),
- service, path,
- "org.freedesktop.DBus.Properties",
- "Get",
- "xyz.openbmc_project.State.Decorator.OperationalStatus",
- "Functional");
+ });
}
},
connection.first, path,
@@ -526,10 +501,14 @@
"org.freedesktop.DBus.Properties", "GetAll",
"xyz.openbmc_project.Inventory.Decorator.Asset");
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, connection.first,
+ path,
+ "xyz.openbmc_project.Inventory.Decorator."
+ "AssetTag",
+ "AssetTag",
[aResp](const boost::system::error_code ec2,
- const dbus::utility::DbusVariantType&
- property) {
+ const std::string& value) {
if (ec2)
{
// doesn't have to include this
@@ -537,18 +516,8 @@
return;
}
- const std::string* value =
- std::get_if<std::string>(&property);
- if (value != nullptr)
- {
- aResp->res.jsonValue["AssetTag"] =
- *value;
- }
- },
- connection.first, path,
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Inventory.Decorator.AssetTag",
- "AssetTag");
+ aResp->res.jsonValue["AssetTag"] = value;
+ });
}
}
}
@@ -577,9 +546,12 @@
inline void getHostState(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{
BMCWEB_LOG_DEBUG << "Get host information.";
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, "xyz.openbmc_project.State.Host",
+ "/xyz/openbmc_project/state/host0", "xyz.openbmc_project.State.Host",
+ "CurrentHostState",
[aResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& hostState) {
+ const std::string& hostState) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
@@ -587,53 +559,45 @@
return;
}
- const std::string* s = std::get_if<std::string>(&hostState);
- BMCWEB_LOG_DEBUG << "Host state: " << *s;
- if (s != nullptr)
+ BMCWEB_LOG_DEBUG << "Host state: " << hostState;
+ // Verify Host State
+ if (hostState == "xyz.openbmc_project.State.Host.HostState.Running")
{
- // Verify Host State
- if (*s == "xyz.openbmc_project.State.Host.HostState.Running")
- {
- aResp->res.jsonValue["PowerState"] = "On";
- aResp->res.jsonValue["Status"]["State"] = "Enabled";
- }
- else if (*s ==
- "xyz.openbmc_project.State.Host.HostState.Quiesced")
- {
- aResp->res.jsonValue["PowerState"] = "On";
- aResp->res.jsonValue["Status"]["State"] = "Quiesced";
- }
- else if (
- *s ==
- "xyz.openbmc_project.State.Host.HostState.DiagnosticMode")
- {
- aResp->res.jsonValue["PowerState"] = "On";
- aResp->res.jsonValue["Status"]["State"] = "InTest";
- }
- else if (
- *s ==
- "xyz.openbmc_project.State.Host.HostState.TransitioningToRunning")
- {
- aResp->res.jsonValue["PowerState"] = "PoweringOn";
- aResp->res.jsonValue["Status"]["State"] = "Starting";
- }
- else if (
- *s ==
- "xyz.openbmc_project.State.Host.HostState.TransitioningToOff")
- {
- aResp->res.jsonValue["PowerState"] = "PoweringOff";
- aResp->res.jsonValue["Status"]["State"] = "Disabled";
- }
- else
- {
- aResp->res.jsonValue["PowerState"] = "Off";
- aResp->res.jsonValue["Status"]["State"] = "Disabled";
- }
+ aResp->res.jsonValue["PowerState"] = "On";
+ aResp->res.jsonValue["Status"]["State"] = "Enabled";
}
- },
- "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.State.Host", "CurrentHostState");
+ else if (hostState ==
+ "xyz.openbmc_project.State.Host.HostState.Quiesced")
+ {
+ aResp->res.jsonValue["PowerState"] = "On";
+ aResp->res.jsonValue["Status"]["State"] = "Quiesced";
+ }
+ else if (hostState ==
+ "xyz.openbmc_project.State.Host.HostState.DiagnosticMode")
+ {
+ aResp->res.jsonValue["PowerState"] = "On";
+ aResp->res.jsonValue["Status"]["State"] = "InTest";
+ }
+ else if (
+ hostState ==
+ "xyz.openbmc_project.State.Host.HostState.TransitioningToRunning")
+ {
+ aResp->res.jsonValue["PowerState"] = "PoweringOn";
+ aResp->res.jsonValue["Status"]["State"] = "Starting";
+ }
+ else if (
+ hostState ==
+ "xyz.openbmc_project.State.Host.HostState.TransitioningToOff")
+ {
+ aResp->res.jsonValue["PowerState"] = "PoweringOff";
+ aResp->res.jsonValue["Status"]["State"] = "Disabled";
+ }
+ else
+ {
+ aResp->res.jsonValue["PowerState"] = "Off";
+ aResp->res.jsonValue["Status"]["State"] = "Disabled";
+ }
+ });
}
/**
@@ -784,9 +748,12 @@
*/
inline void getBootProgress(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, "xyz.openbmc_project.State.Host",
+ "/xyz/openbmc_project/state/host0",
+ "xyz.openbmc_project.State.Boot.Progress", "BootProgress",
[aResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& bootProgress) {
+ const std::string& bootProgressStr) {
if (ec)
{
// BootProgress is an optional object so just do nothing if
@@ -794,71 +761,60 @@
return;
}
- const std::string* bootProgressStr =
- std::get_if<std::string>(&bootProgress);
-
- if (!bootProgressStr)
- {
- // Interface implemented but property not found, return error
- // for that
- messages::internalError(aResp->res);
- return;
- }
-
- BMCWEB_LOG_DEBUG << "Boot Progress: " << *bootProgressStr;
+ BMCWEB_LOG_DEBUG << "Boot Progress: " << bootProgressStr;
// Now convert the D-Bus BootProgress to the appropriate Redfish
// enum
std::string rfBpLastState = "None";
- if (*bootProgressStr ==
+ if (bootProgressStr ==
"xyz.openbmc_project.State.Boot.Progress.ProgressStages.Unspecified")
{
rfBpLastState = "None";
}
else if (
- *bootProgressStr ==
+ bootProgressStr ==
"xyz.openbmc_project.State.Boot.Progress.ProgressStages.PrimaryProcInit")
{
rfBpLastState = "PrimaryProcessorInitializationStarted";
}
else if (
- *bootProgressStr ==
+ bootProgressStr ==
"xyz.openbmc_project.State.Boot.Progress.ProgressStages.BusInit")
{
rfBpLastState = "BusInitializationStarted";
}
else if (
- *bootProgressStr ==
+ bootProgressStr ==
"xyz.openbmc_project.State.Boot.Progress.ProgressStages.MemoryInit")
{
rfBpLastState = "MemoryInitializationStarted";
}
else if (
- *bootProgressStr ==
+ bootProgressStr ==
"xyz.openbmc_project.State.Boot.Progress.ProgressStages.SecondaryProcInit")
{
rfBpLastState = "SecondaryProcessorInitializationStarted";
}
else if (
- *bootProgressStr ==
+ bootProgressStr ==
"xyz.openbmc_project.State.Boot.Progress.ProgressStages.PCIInit")
{
rfBpLastState = "PCIResourceConfigStarted";
}
else if (
- *bootProgressStr ==
+ bootProgressStr ==
"xyz.openbmc_project.State.Boot.Progress.ProgressStages.SystemInitComplete")
{
rfBpLastState = "SystemHardwareInitializationComplete";
}
else if (
- *bootProgressStr ==
+ bootProgressStr ==
"xyz.openbmc_project.State.Boot.Progress.ProgressStages.OSStart")
{
rfBpLastState = "OSBootStarted";
}
else if (
- *bootProgressStr ==
+ bootProgressStr ==
"xyz.openbmc_project.State.Boot.Progress.ProgressStages.OSRunning")
{
rfBpLastState = "OSRunning";
@@ -866,15 +822,12 @@
else
{
BMCWEB_LOG_DEBUG << "Unsupported D-Bus BootProgress "
- << *bootProgressStr;
+ << bootProgressStr;
// Just return the default
}
aResp->res.jsonValue["BootProgress"]["LastState"] = rfBpLastState;
- },
- "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.State.Boot.Progress", "BootProgress");
+ });
}
/**
@@ -887,32 +840,26 @@
inline void getBootOverrideType(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, "xyz.openbmc_project.Settings",
+ "/xyz/openbmc_project/control/host0/boot",
+ "xyz.openbmc_project.Control.Boot.Type", "BootType",
[aResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& bootType) {
+ const std::string& bootType) {
if (ec)
{
// not an error, don't have to have the interface
return;
}
- const std::string* bootTypeStr =
- std::get_if<std::string>(&bootType);
-
- if (!bootTypeStr)
- {
- messages::internalError(aResp->res);
- return;
- }
-
- BMCWEB_LOG_DEBUG << "Boot type: " << *bootTypeStr;
+ BMCWEB_LOG_DEBUG << "Boot type: " << bootType;
aResp->res
.jsonValue["Boot"]
["BootSourceOverrideMode@Redfish.AllowableValues"] = {
"Legacy", "UEFI"};
- auto rfType = dbusToRfBootType(*bootTypeStr);
+ auto rfType = dbusToRfBootType(bootType);
if (rfType.empty())
{
messages::internalError(aResp->res);
@@ -920,11 +867,7 @@
}
aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = rfType;
- },
- "xyz.openbmc_project.Settings",
- "/xyz/openbmc_project/control/host0/boot",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Control.Boot.Type", "BootType");
+ });
}
/**
@@ -937,9 +880,12 @@
inline void getBootOverrideMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, "xyz.openbmc_project.Settings",
+ "/xyz/openbmc_project/control/host0/boot",
+ "xyz.openbmc_project.Control.Boot.Mode", "BootMode",
[aResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& bootMode) {
+ const std::string& bootModeStr) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
@@ -947,37 +893,24 @@
return;
}
- const std::string* bootModeStr =
- std::get_if<std::string>(&bootMode);
-
- if (!bootModeStr)
- {
- messages::internalError(aResp->res);
- return;
- }
-
- BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr;
+ BMCWEB_LOG_DEBUG << "Boot mode: " << bootModeStr;
aResp->res
.jsonValue["Boot"]
["BootSourceOverrideTarget@Redfish.AllowableValues"] =
{"None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"};
- if (*bootModeStr !=
+ if (bootModeStr !=
"xyz.openbmc_project.Control.Boot.Mode.Modes.Regular")
{
- auto rfMode = dbusToRfBootMode(*bootModeStr);
+ auto rfMode = dbusToRfBootMode(bootModeStr);
if (!rfMode.empty())
{
aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] =
rfMode;
}
}
- },
- "xyz.openbmc_project.Settings",
- "/xyz/openbmc_project/control/host0/boot",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Control.Boot.Mode", "BootMode");
+ });
}
/**
@@ -991,9 +924,12 @@
inline void
getBootOverrideSource(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, "xyz.openbmc_project.Settings",
+ "/xyz/openbmc_project/control/host0/boot",
+ "xyz.openbmc_project.Control.Boot.Source", "BootSource",
[aResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& bootSource) {
+ const std::string& bootSourceStr) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
@@ -1001,17 +937,9 @@
return;
}
- const std::string* bootSourceStr =
- std::get_if<std::string>(&bootSource);
+ BMCWEB_LOG_DEBUG << "Boot source: " << bootSourceStr;
- if (!bootSourceStr)
- {
- messages::internalError(aResp->res);
- return;
- }
- BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr;
-
- auto rfSource = dbusToRfBootSource(*bootSourceStr);
+ auto rfSource = dbusToRfBootSource(bootSourceStr);
if (!rfSource.empty())
{
aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] =
@@ -1021,11 +949,7 @@
// Get BootMode as BootSourceOverrideTarget is constructed
// from both BootSource and BootMode
getBootOverrideMode(aResp);
- },
- "xyz.openbmc_project.Settings",
- "/xyz/openbmc_project/control/host0/boot",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Control.Boot.Source", "BootSource");
+ });
}
/**
@@ -1050,9 +974,11 @@
// If boot source override is enabled, we need to check 'one_time'
// property to set a correct value for the "BootSourceOverrideEnabled"
- crow::connections::systemBus->async_method_call(
- [aResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& oneTime) {
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus, "xyz.openbmc_project.Settings",
+ "/xyz/openbmc_project/control/host0/boot/one_time",
+ "xyz.openbmc_project.Object.Enable", "Enabled",
+ [aResp](const boost::system::error_code ec, bool oneTimeSetting) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
@@ -1060,16 +986,6 @@
return;
}
- const bool* oneTimePtr = std::get_if<bool>(&oneTime);
-
- if (!oneTimePtr)
- {
- messages::internalError(aResp->res);
- return;
- }
-
- bool oneTimeSetting = *oneTimePtr;
-
if (oneTimeSetting)
{
aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
@@ -1080,11 +996,7 @@
aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] =
"Continuous";
}
- },
- "xyz.openbmc_project.Settings",
- "/xyz/openbmc_project/control/host0/boot/one_time",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Object.Enable", "Enabled");
+ });
}
/**
@@ -1098,9 +1010,12 @@
inline void
getBootOverrideEnable(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus, "xyz.openbmc_project.Settings",
+ "/xyz/openbmc_project/control/host0/boot",
+ "xyz.openbmc_project.Object.Enable", "Enabled",
[aResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& bootOverrideEnable) {
+ const bool bootOverrideEnable) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
@@ -1108,21 +1023,8 @@
return;
}
- const bool* bootOverrideEnablePtr =
- std::get_if<bool>(&bootOverrideEnable);
-
- if (!bootOverrideEnablePtr)
- {
- messages::internalError(aResp->res);
- return;
- }
-
- processBootOverrideEnable(aResp, *bootOverrideEnablePtr);
- },
- "xyz.openbmc_project.Settings",
- "/xyz/openbmc_project/control/host0/boot",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Object.Enable", "Enabled");
+ processBootOverrideEnable(aResp, bootOverrideEnable);
+ });
}
/**
@@ -1157,35 +1059,25 @@
{
BMCWEB_LOG_DEBUG << "Getting System Last Reset Time";
- crow::connections::systemBus->async_method_call(
- [aResp](const boost::system::error_code ec,
- dbus::utility::DbusVariantType& lastResetTime) {
+ sdbusplus::asio::getProperty<uint64_t>(
+ *crow::connections::systemBus, "xyz.openbmc_project.State.Chassis",
+ "/xyz/openbmc_project/state/chassis0",
+ "xyz.openbmc_project.State.Chassis", "LastStateChangeTime",
+ [aResp](const boost::system::error_code ec, uint64_t lastResetTime) {
if (ec)
{
BMCWEB_LOG_DEBUG << "D-BUS response error " << ec;
return;
}
- const uint64_t* lastResetTimePtr =
- std::get_if<uint64_t>(&lastResetTime);
-
- if (!lastResetTimePtr)
- {
- messages::internalError(aResp->res);
- return;
- }
// LastStateChangeTime is epoch time, in milliseconds
// https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19
- uint64_t lastResetTimeStamp = *lastResetTimePtr / 1000;
+ uint64_t lastResetTimeStamp = lastResetTime / 1000;
// Convert to ISO 8601 standard
aResp->res.jsonValue["LastResetTime"] =
crow::utility::getDateTimeUint(lastResetTimeStamp);
- },
- "xyz.openbmc_project.State.Chassis",
- "/xyz/openbmc_project/state/chassis0",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.State.Chassis", "LastStateChangeTime");
+ });
}
/**
@@ -1199,63 +1091,46 @@
{
BMCWEB_LOG_DEBUG << "Get Automatic Retry policy";
- crow::connections::systemBus->async_method_call(
- [aResp](const boost::system::error_code ec,
- dbus::utility::DbusVariantType& autoRebootEnabled) {
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus, "xyz.openbmc_project.Settings",
+ "/xyz/openbmc_project/control/host0/auto_reboot",
+ "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot",
+ [aResp](const boost::system::error_code ec, bool autoRebootEnabled) {
if (ec)
{
BMCWEB_LOG_DEBUG << "D-BUS response error " << ec;
return;
}
- const bool* autoRebootEnabledPtr =
- std::get_if<bool>(&autoRebootEnabled);
-
- if (!autoRebootEnabledPtr)
- {
- messages::internalError(aResp->res);
- return;
- }
-
- BMCWEB_LOG_DEBUG << "Auto Reboot: " << *autoRebootEnabledPtr;
- if (*autoRebootEnabledPtr == true)
+ BMCWEB_LOG_DEBUG << "Auto Reboot: " << autoRebootEnabled;
+ if (autoRebootEnabled == true)
{
aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] =
"RetryAttempts";
// If AutomaticRetry (AutoReboot) is enabled see how many
// attempts are left
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<uint32_t>(
+ *crow::connections::systemBus,
+ "xyz.openbmc_project.State.Host",
+ "/xyz/openbmc_project/state/host0",
+ "xyz.openbmc_project.Control.Boot.RebootAttempts",
+ "AttemptsLeft",
[aResp](const boost::system::error_code ec2,
- dbus::utility::DbusVariantType&
- autoRebootAttemptsLeft) {
+ uint32_t autoRebootAttemptsLeft) {
if (ec2)
{
BMCWEB_LOG_DEBUG << "D-BUS response error " << ec2;
return;
}
- const uint32_t* autoRebootAttemptsLeftPtr =
- std::get_if<uint32_t>(&autoRebootAttemptsLeft);
-
- if (!autoRebootAttemptsLeftPtr)
- {
- messages::internalError(aResp->res);
- return;
- }
-
BMCWEB_LOG_DEBUG << "Auto Reboot Attempts Left: "
- << *autoRebootAttemptsLeftPtr;
+ << autoRebootAttemptsLeft;
aResp->res
.jsonValue["Boot"]
["RemainingAutomaticRetryAttempts"] =
- *autoRebootAttemptsLeftPtr;
- },
- "xyz.openbmc_project.State.Host",
- "/xyz/openbmc_project/state/host0",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Control.Boot.RebootAttempts",
- "AttemptsLeft");
+ autoRebootAttemptsLeft;
+ });
}
else
{
@@ -1274,11 +1149,7 @@
.jsonValue["Boot"]
["AutomaticRetryConfig@Redfish.AllowableValues"] = {
"Disabled", "RetryAttempts"};
- },
- "xyz.openbmc_project.Settings",
- "/xyz/openbmc_project/control/host0/auto_reboot",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot");
+ });
}
/**
@@ -1293,9 +1164,11 @@
{
BMCWEB_LOG_DEBUG << "Get power restore policy";
- crow::connections::systemBus->async_method_call(
- [aResp](const boost::system::error_code ec,
- dbus::utility::DbusVariantType& policy) {
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, "xyz.openbmc_project.Settings",
+ "/xyz/openbmc_project/control/host0/power_restore_policy",
+ "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy",
+ [aResp](const boost::system::error_code ec, const std::string& policy) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
@@ -1310,15 +1183,7 @@
{"xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore",
"LastState"}};
- const std::string* policyPtr = std::get_if<std::string>(&policy);
-
- if (!policyPtr)
- {
- messages::internalError(aResp->res);
- return;
- }
-
- auto policyMapsIt = policyMaps.find(*policyPtr);
+ auto policyMapsIt = policyMaps.find(policy);
if (policyMapsIt == policyMaps.end())
{
messages::internalError(aResp->res);
@@ -1326,12 +1191,7 @@
}
aResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second;
- },
- "xyz.openbmc_project.Settings",
- "/xyz/openbmc_project/control/host0/power_restore_policy",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Control.Power.RestorePolicy",
- "PowerRestorePolicy");
+ });
}
/**
@@ -1393,9 +1253,10 @@
const std::string& serv = subtree[0].second.begin()->first;
// Valid TPM Enable object found, now reading the current value
- crow::connections::systemBus->async_method_call(
- [aResp](const boost::system::error_code ec,
- dbus::utility::DbusVariantType& tpmRequired) {
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus, serv, path,
+ "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable",
+ [aResp](const boost::system::error_code ec, bool tpmRequired) {
if (ec)
{
BMCWEB_LOG_DEBUG
@@ -1404,16 +1265,7 @@
return;
}
- const bool* tpmRequiredVal =
- std::get_if<bool>(&tpmRequired);
-
- if (!tpmRequiredVal)
- {
- messages::internalError(aResp->res);
- return;
- }
-
- if (*tpmRequiredVal == true)
+ if (tpmRequired)
{
aResp->res
.jsonValue["Boot"]["TrustedModuleRequiredToBoot"] =
@@ -1425,9 +1277,7 @@
.jsonValue["Boot"]["TrustedModuleRequiredToBoot"] =
"Disabled";
}
- },
- serv, path, "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable");
+ });
},
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
@@ -2114,9 +1964,11 @@
return;
}
// Valid Power Mode object found, now read the current value
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, service, path,
+ "xyz.openbmc_project.Control.Power.Mode", "PowerMode",
[aResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& pmode) {
+ const std::string& pmode) {
if (ec)
{
BMCWEB_LOG_DEBUG
@@ -2125,22 +1977,12 @@
return;
}
- const std::string* s = std::get_if<std::string>(&pmode);
- if (s == nullptr)
- {
- BMCWEB_LOG_DEBUG << "Unable to get PowerMode value";
- messages::internalError(aResp->res);
- return;
- }
-
aResp->res.jsonValue["PowerMode@Redfish.AllowableValues"] =
{"Static", "MaximumPerformance", "PowerSaving"};
- BMCWEB_LOG_DEBUG << "Current power mode: " << *s;
- translatePowerMode(aResp, *s);
- },
- service, path, "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Control.Power.Mode", "PowerMode");
+ BMCWEB_LOG_DEBUG << "Current power mode: " << pmode;
+ translatePowerMode(aResp, pmode);
+ });
},
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
@@ -2825,10 +2667,14 @@
asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems";
asyncResp->res.jsonValue["Name"] = "Computer System Collection";
- crow::connections::systemBus->async_method_call(
- [asyncResp](
- const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& /*hostName*/) {
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus,
+ "xyz.openbmc_project.Settings",
+ "/xyz/openbmc_project/network/hypervisor",
+ "xyz.openbmc_project.Network.SystemConfiguration",
+ "HostName",
+ [asyncResp](const boost::system::error_code ec,
+ const std::string& /*hostName*/) {
nlohmann::json& ifaceArray =
asyncResp->res.jsonValue["Members"];
ifaceArray = nlohmann::json::array();
@@ -2845,12 +2691,7 @@
"/redfish/v1/Systems/hypervisor"}});
count = ifaceArray.size();
}
- },
- "xyz.openbmc_project.Settings",
- "/xyz/openbmc_project/network/hypervisor",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Network.SystemConfiguration",
- "HostName");
+ });
});
}