summaryrefslogtreecommitdiff
path: root/redfish-core/lib
diff options
context:
space:
mode:
authorJonathan Doman <jonathan.doman@intel.com>2021-06-11 19:36:17 +0300
committerKrzysztof Grobelny <krzysztof.grobelny@intel.com>2021-12-28 15:23:02 +0300
commit1e1e598df6d1d9530dde6e92d8f74f8143f60e50 (patch)
treeb71aee4a4c50c79332e14d6e74094693888855a6 /redfish-core/lib
parent168e20c1306e3e689907ba43e14ea679e2328611 (diff)
downloadbmcweb-1e1e598df6d1d9530dde6e92d8f74f8143f60e50.tar.xz
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>
Diffstat (limited to 'redfish-core/lib')
-rw-r--r--redfish-core/lib/account_service.hpp20
-rw-r--r--redfish-core/lib/chassis.hpp151
-rw-r--r--redfish-core/lib/health.hpp1
-rw-r--r--redfish-core/lib/hypervisor_system.hpp60
-rw-r--r--redfish-core/lib/led.hpp180
-rw-r--r--redfish-core/lib/log_services.hpp27
-rw-r--r--redfish-core/lib/managers.hpp65
-rw-r--r--redfish-core/lib/metric_report.hpp32
-rw-r--r--redfish-core/lib/network_protocol.hpp23
-rw-r--r--redfish-core/lib/power.hpp91
-rw-r--r--redfish-core/lib/processor.hpp98
-rw-r--r--redfish-core/lib/redfish_util.hpp20
-rw-r--r--redfish-core/lib/roles.hpp25
-rw-r--r--redfish-core/lib/sensors.hpp157
-rw-r--r--redfish-core/lib/storage.hpp67
-rw-r--r--redfish-core/lib/systems.hpp577
-rw-r--r--redfish-core/lib/update_service.hpp29
17 files changed, 614 insertions, 1009 deletions
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index 46f6a93b72..b746cef297 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -21,6 +21,7 @@
#include <openbmc_dbus_rest.hpp>
#include <persistent_data.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
#include <utils/json_utils.hpp>
namespace redfish
@@ -1600,10 +1601,13 @@ inline void requestAccountServiceRoutes(App& app)
}
// Reading AllGroups property
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::vector<std::string>>(
+ *crow::connections::systemBus,
+ "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
+ "xyz.openbmc_project.User.Manager", "AllGroups",
[asyncResp, username, password{std::move(password)}, roleId,
enabled](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& allGroups) {
+ const std::vector<std::string>& allGroupsList) {
if (ec)
{
BMCWEB_LOG_DEBUG << "ERROR with async_method_call";
@@ -1611,10 +1615,7 @@ inline void requestAccountServiceRoutes(App& app)
return;
}
- const std::vector<std::string>* allGroupsList =
- std::get_if<std::vector<std::string>>(&allGroups);
-
- if (allGroupsList == nullptr || allGroupsList->empty())
+ if (allGroupsList.empty())
{
messages::internalError(asyncResp->res);
return;
@@ -1676,11 +1677,8 @@ inline void requestAccountServiceRoutes(App& app)
"xyz.openbmc_project.User.Manager",
"/xyz/openbmc_project/user",
"xyz.openbmc_project.User.Manager", "CreateUser",
- username, *allGroupsList, *roleId, *enabled);
- },
- "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.User.Manager", "AllGroups");
+ username, allGroupsList, *roleId, *enabled);
+ });
});
BMCWEB_ROUTE(app, "/redfish/v1/AccountService/Accounts/<str>/")
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
index df7e205686..935bbe6f67 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -22,6 +22,7 @@
#include <boost/container/flat_map.hpp>
#include <dbus_utility.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
#include <utils/collection.hpp>
namespace redfish
@@ -36,10 +37,13 @@ namespace redfish
*/
inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> aResp)
{
- crow::connections::systemBus->async_method_call(
- [aResp{std::move(aResp)}](
- const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& chassisState) {
+ // crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, "xyz.openbmc_project.State.Chassis",
+ "/xyz/openbmc_project/state/chassis0",
+ "xyz.openbmc_project.State.Chassis", "CurrentPowerState",
+ [aResp{std::move(aResp)}](const boost::system::error_code ec,
+ const std::string& chassisState) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
@@ -47,28 +51,21 @@ inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> aResp)
return;
}
- const std::string* s = std::get_if<std::string>(&chassisState);
- BMCWEB_LOG_DEBUG << "Chassis state: " << *s;
- if (s != nullptr)
+ BMCWEB_LOG_DEBUG << "Chassis state: " << chassisState;
+ // Verify Chassis State
+ if (chassisState ==
+ "xyz.openbmc_project.State.Chassis.PowerState.On")
{
- // Verify Chassis State
- if (*s == "xyz.openbmc_project.State.Chassis.PowerState.On")
- {
- aResp->res.jsonValue["PowerState"] = "On";
- aResp->res.jsonValue["Status"]["State"] = "Enabled";
- }
- else if (*s ==
- "xyz.openbmc_project.State.Chassis.PowerState.Off")
- {
- aResp->res.jsonValue["PowerState"] = "Off";
- aResp->res.jsonValue["Status"]["State"] = "StandbyOffline";
- }
+ aResp->res.jsonValue["PowerState"] = "On";
+ aResp->res.jsonValue["Status"]["State"] = "Enabled";
}
- },
- "xyz.openbmc_project.State.Chassis",
- "/xyz/openbmc_project/state/chassis0",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.State.Chassis", "CurrentPowerState");
+ else if (chassisState ==
+ "xyz.openbmc_project.State.Chassis.PowerState.Off")
+ {
+ aResp->res.jsonValue["PowerState"] = "Off";
+ aResp->res.jsonValue["Status"]["State"] = "StandbyOffline";
+ }
+ });
}
/**
@@ -90,9 +87,11 @@ inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> aResp,
{
BMCWEB_LOG_DEBUG << "Get intrusion status by service \n";
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, service, objPath,
+ "xyz.openbmc_project.Chassis.Intrusion", "Status",
[aResp{std::move(aResp)}](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& value) {
+ const std::string& value) {
if (ec)
{
// do not add err msg in redfish response, because this is not
@@ -101,19 +100,9 @@ inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> aResp,
return;
}
- const std::string* status = std::get_if<std::string>(&value);
-
- if (status == nullptr)
- {
- BMCWEB_LOG_ERROR << "intrusion status read error \n";
- return;
- }
-
aResp->res.jsonValue["PhysicalSecurity"] = {
- {"IntrusionSensorNumber", 1}, {"IntrusionSensor", *status}};
- },
- service, objPath, "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Chassis.Intrusion", "Status");
+ {"IntrusionSensorNumber", 1}, {"IntrusionSensor", value}};
+ });
}
/**
@@ -181,9 +170,11 @@ inline void
const std::string& connectionName,
const std::string& path)
{
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, connectionName, path,
+ "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
[asyncResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& property) {
+ const std::string& property) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error for Location";
@@ -191,44 +182,29 @@ inline void
return;
}
- const std::string* value = std::get_if<std::string>(&property);
- if (value == nullptr)
- {
- BMCWEB_LOG_DEBUG << "Null value returned for locaton code";
- messages::internalError(asyncResp->res);
- return;
- }
asyncResp->res
- .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = *value;
- },
- connectionName, path, "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode");
+ .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
+ property;
+ });
}
inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& connectionName,
const std::string& path)
{
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, connectionName, path,
+ "xyz.openbmc_project.Common.UUID", "UUID",
[asyncResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& chassisUUID) {
+ const std::string& chassisUUID) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error for UUID";
messages::internalError(asyncResp->res);
return;
}
- const std::string* value = std::get_if<std::string>(&chassisUUID);
- if (value == nullptr)
- {
- BMCWEB_LOG_DEBUG << "Null value returned for UUID";
- messages::internalError(asyncResp->res);
- return;
- }
- asyncResp->res.jsonValue["UUID"] = *value;
- },
- connectionName, path, "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Common.UUID", "UUID");
+ asyncResp->res.jsonValue["UUID"] = chassisUUID;
+ });
}
/**
@@ -278,26 +254,19 @@ inline void requestRoutesChassis(App& app)
auto health =
std::make_shared<HealthPopulate>(asyncResp);
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::vector<std::string>>(
+ *crow::connections::systemBus,
+ "xyz.openbmc_project.ObjectMapper",
+ path + "/all_sensors",
+ "xyz.openbmc_project.Association", "endpoints",
[health](const boost::system::error_code ec2,
- dbus::utility::DbusVariantType& resp) {
+ const std::vector<std::string>& resp) {
if (ec2)
{
return; // no sensors = no failures
}
- std::vector<std::string>* data =
- std::get_if<std::vector<std::string>>(
- &resp);
- if (data == nullptr)
- {
- return;
- }
- health->inventory = std::move(*data);
- },
- "xyz.openbmc_project.ObjectMapper",
- path + "/all_sensors",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Association", "endpoints");
+ health->inventory = resp;
+ });
health->populate();
@@ -337,11 +306,12 @@ inline void requestRoutesChassis(App& app)
if (std::find(interfaces2.begin(), interfaces2.end(),
assetTagInterface) != interfaces2.end())
{
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, connectionName,
+ path, assetTagInterface, "AssetTag",
[asyncResp, chassisId(std::string(chassisId))](
const boost::system::error_code ec,
- const dbus::utility::DbusVariantType&
- property) {
+ const std::string& property) {
if (ec)
{
BMCWEB_LOG_DEBUG
@@ -349,22 +319,9 @@ inline void requestRoutesChassis(App& app)
messages::internalError(asyncResp->res);
return;
}
-
- const std::string* assetTag =
- std::get_if<std::string>(&property);
- if (assetTag == nullptr)
- {
- BMCWEB_LOG_DEBUG
- << "Null value returned for Chassis AssetTag";
- messages::internalError(asyncResp->res);
- return;
- }
asyncResp->res.jsonValue["AssetTag"] =
- *assetTag;
- },
- connectionName, path,
- "org.freedesktop.DBus.Properties", "Get",
- assetTagInterface, "AssetTag");
+ property;
+ });
}
for (const char* interface : hasIndicatorLed)
diff --git a/redfish-core/lib/health.hpp b/redfish-core/lib/health.hpp
index 510b8954ca..41352da366 100644
--- a/redfish-core/lib/health.hpp
+++ b/redfish-core/lib/health.hpp
@@ -21,6 +21,7 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/container/flat_set.hpp>
#include <dbus_singleton.hpp>
+#include <dbus_utility.hpp>
#include <variant>
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp
index 5089206286..d308a9a5b1 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -7,6 +7,7 @@
#include <dbus_utility.hpp>
#include <error_messages.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
#include <utils/json_utils.hpp>
#include <optional>
@@ -33,9 +34,12 @@ namespace redfish::hypervisor
inline void getHypervisorState(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{
BMCWEB_LOG_DEBUG << "Get hypervisor state information.";
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, "xyz.openbmc_project.State.Hypervisor",
+ "/xyz/openbmc_project/state/hypervisor0",
+ "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;
@@ -44,45 +48,39 @@ inline void getHypervisorState(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
return;
}
- const std::string* s = std::get_if<std::string>(&hostState);
- if (s == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
-
- BMCWEB_LOG_DEBUG << "Hypervisor state: " << *s;
+ BMCWEB_LOG_DEBUG << "Hypervisor state: " << hostState;
// Verify Host State
- if (*s == "xyz.openbmc_project.State.Host.HostState.Running")
+ if (hostState == "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")
+ else if (hostState == "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.Standby")
+ else if (hostState == "xyz.openbmc_project.State.Host.HostState."
+ "Standby")
{
aResp->res.jsonValue["PowerState"] = "On";
aResp->res.jsonValue["Status"]["State"] = "StandbyOffline";
}
- else if (
- *s ==
- "xyz.openbmc_project.State.Host.HostState.TransitioningToRunning")
+ else if (hostState == "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")
+ else if (hostState == "xyz.openbmc_project.State.Host.HostState."
+ "TransitioningToOff")
{
aResp->res.jsonValue["PowerState"] = "PoweringOff";
aResp->res.jsonValue["Status"]["State"] = "Enabled";
}
- else if (*s == "xyz.openbmc_project.State.Host.HostState.Off")
+ else if (hostState ==
+ "xyz.openbmc_project.State.Host.HostState.Off")
{
aResp->res.jsonValue["PowerState"] = "Off";
aResp->res.jsonValue["Status"]["State"] = "Disabled";
@@ -92,11 +90,7 @@ inline void getHypervisorState(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
messages::internalError(aResp->res);
return;
}
- },
- "xyz.openbmc_project.State.Hypervisor",
- "/xyz/openbmc_project/state/hypervisor0",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.State.Host", "CurrentHostState");
+ });
}
/**
@@ -737,10 +731,12 @@ inline void requestRoutesHypervisorSystems(App& app)
boost::beast::http::verb::
get)([](const crow::Request&,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
- 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*/) {
if (ec)
{
messages::resourceNotFound(asyncResp->res, "System",
@@ -765,11 +761,7 @@ inline void requestRoutesHypervisorSystems(App& app)
getHypervisorState(asyncResp);
getHypervisorActions(asyncResp);
// TODO: Add "SystemType" : "hypervisor"
- },
- "xyz.openbmc_project.Settings",
- "/xyz/openbmc_project/network/hypervisor",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Network.SystemConfiguration", "HostName");
+ });
});
/**
diff --git a/redfish-core/lib/led.hpp b/redfish-core/lib/led.hpp
index c4a7ed8805..6f5f5f121b 100644
--- a/redfish-core/lib/led.hpp
+++ b/redfish-core/lib/led.hpp
@@ -20,6 +20,7 @@
#include "redfish_util.hpp"
#include <app.hpp>
+#include <sdbusplus/asio/property.hpp>
namespace redfish
{
@@ -35,61 +36,57 @@ inline void
getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{
BMCWEB_LOG_DEBUG << "Get led groups";
- crow::connections::systemBus->async_method_call(
- [aResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType asserted) {
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
+ "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
+ "xyz.openbmc_project.Led.Group", "Asserted",
+ [aResp](const boost::system::error_code ec, const bool blinking) {
// Some systems may not have enclosure_identify_blink object so
// proceed to get enclosure_identify state.
- if (!ec)
+ if (ec == boost::system::errc::invalid_argument)
{
- const bool* blinking = std::get_if<bool>(&asserted);
- if (!blinking)
- {
- BMCWEB_LOG_DEBUG << "Get identity blinking LED failed";
- messages::internalError(aResp->res);
- return;
- }
- // Blinking ON, no need to check enclosure_identify assert.
- if (*blinking)
- {
- aResp->res.jsonValue["IndicatorLED"] = "Blinking";
- return;
- }
+ BMCWEB_LOG_DEBUG
+ << "Get identity blinking LED failed, missmatch in property type";
+ messages::internalError(aResp->res);
+ return;
}
- crow::connections::systemBus->async_method_call(
- [aResp](const boost::system::error_code ec2,
- const dbus::utility::DbusVariantType asserted2) {
- if (!ec2)
- {
- const bool* ledOn = std::get_if<bool>(&asserted2);
- if (!ledOn)
- {
- BMCWEB_LOG_DEBUG
- << "Get enclosure identity led failed";
- messages::internalError(aResp->res);
- return;
- }
- if (*ledOn)
- {
- aResp->res.jsonValue["IndicatorLED"] = "Lit";
- }
- else
- {
- aResp->res.jsonValue["IndicatorLED"] = "Off";
- }
- }
- return;
- },
+ // Blinking ON, no need to check enclosure_identify assert.
+ if (!ec && blinking)
+ {
+ aResp->res.jsonValue["IndicatorLED"] = "Blinking";
+ return;
+ }
+
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus,
"xyz.openbmc_project.LED.GroupManager",
"/xyz/openbmc_project/led/groups/enclosure_identify",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Led.Group", "Asserted");
- },
- "xyz.openbmc_project.LED.GroupManager",
- "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Led.Group", "Asserted");
+ "xyz.openbmc_project.Led.Group", "Asserted",
+ [aResp](const boost::system::error_code ec2, const bool ledOn) {
+ if (ec2 == boost::system::errc::invalid_argument)
+ {
+ BMCWEB_LOG_DEBUG
+ << "Get enclosure identity led failed, missmatch in property type";
+ messages::internalError(aResp->res);
+ return;
+ }
+
+ if (ec2)
+ {
+ return;
+ }
+
+ if (ledOn)
+ {
+ aResp->res.jsonValue["IndicatorLED"] = "Lit";
+ }
+ else
+ {
+ aResp->res.jsonValue["IndicatorLED"] = "Off";
+ }
+ });
+ });
}
/**
@@ -169,63 +166,50 @@ inline void
getLocationIndicatorActive(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{
BMCWEB_LOG_DEBUG << "Get LocationIndicatorActive";
- crow::connections::systemBus->async_method_call(
- [aResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType asserted) {
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
+ "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
+ "xyz.openbmc_project.Led.Group", "Asserted",
+ [aResp](const boost::system::error_code ec, const bool blinking) {
// Some systems may not have enclosure_identify_blink object so
// proceed to get enclosure_identify state.
- if (!ec)
+ if (ec == boost::system::errc::invalid_argument)
{
- const bool* blinking = std::get_if<bool>(&asserted);
- if (!blinking)
- {
- BMCWEB_LOG_DEBUG << "Get identity blinking LED failed";
- messages::internalError(aResp->res);
- return;
- }
- // Blinking ON, no need to check enclosure_identify assert.
- if (*blinking)
- {
- aResp->res.jsonValue["LocationIndicatorActive"] = true;
- return;
- }
+ BMCWEB_LOG_DEBUG
+ << "Get identity blinking LED failed, missmatch in property type";
+ messages::internalError(aResp->res);
+ return;
}
- crow::connections::systemBus->async_method_call(
- [aResp](const boost::system::error_code ec2,
- const dbus::utility::DbusVariantType asserted2) {
- if (!ec2)
- {
- const bool* ledOn = std::get_if<bool>(&asserted2);
- if (!ledOn)
- {
- BMCWEB_LOG_DEBUG
- << "Get enclosure identity led failed";
- messages::internalError(aResp->res);
- return;
- }
- if (*ledOn)
- {
- aResp->res.jsonValue["LocationIndicatorActive"] =
- true;
- }
- else
- {
- aResp->res.jsonValue["LocationIndicatorActive"] =
- false;
- }
- }
- return;
- },
+ // Blinking ON, no need to check enclosure_identify assert.
+ if (!ec && blinking)
+ {
+ aResp->res.jsonValue["LocationIndicatorActive"] = true;
+ return;
+ }
+
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus,
"xyz.openbmc_project.LED.GroupManager",
"/xyz/openbmc_project/led/groups/enclosure_identify",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Led.Group", "Asserted");
- },
- "xyz.openbmc_project.LED.GroupManager",
- "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Led.Group", "Asserted");
+ "xyz.openbmc_project.Led.Group", "Asserted",
+ [aResp](const boost::system::error_code ec2, const bool ledOn) {
+ if (ec2 == boost::system::errc::invalid_argument)
+ {
+ BMCWEB_LOG_DEBUG
+ << "Get enclosure identity led failed, missmatch in property type";
+ messages::internalError(aResp->res);
+ return;
+ }
+
+ if (ec2)
+ {
+ return;
+ }
+
+ aResp->res.jsonValue["LocationIndicatorActive"] = ledOn;
+ });
+ });
}
/**
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index d632552986..b908da5ded 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -3319,30 +3319,21 @@ static void
const uint64_t skip, const uint64_t top)
{
uint64_t entryCount = 0;
- crow::connections::systemBus->async_method_call(
- [aResp, entryCount, skip,
- top](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& bootCount) {
+ sdbusplus::asio::getProperty<uint16_t>(
+ *crow::connections::systemBus,
+ "xyz.openbmc_project.State.Boot.PostCode0",
+ "/xyz/openbmc_project/State/Boot/PostCode0",
+ "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount",
+ [aResp, entryCount, skip, top](const boost::system::error_code ec,
+ const uint16_t bootCount) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
messages::internalError(aResp->res);
return;
}
- auto pVal = std::get_if<uint16_t>(&bootCount);
- if (pVal)
- {
- getPostCodeForBoot(aResp, 1, *pVal, entryCount, skip, top);
- }
- else
- {
- BMCWEB_LOG_DEBUG << "Post code boot index failed.";
- }
- },
- "xyz.openbmc_project.State.Boot.PostCode0",
- "/xyz/openbmc_project/State/Boot/PostCode0",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount");
+ getPostCodeForBoot(aResp, 1, bootCount, entryCount, skip, top);
+ });
}
inline void requestRoutesPostCodesEntryCollection(App& app)
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index 7e5b272d72..39b0f8864b 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -1687,9 +1687,11 @@ inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
{
BMCWEB_LOG_DEBUG << "Get BMC manager Location data.";
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, connectionName, path,
+ "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
[aResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& property) {
+ const std::string& property) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error for "
@@ -1698,20 +1700,9 @@ inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
return;
}
- const std::string* value = std::get_if<std::string>(&property);
-
- if (value == nullptr)
- {
- // illegal value
- messages::internalError(aResp->res);
- return;
- }
-
aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
- *value;
- },
- connectionName, path, "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode");
+ property;
+ });
}
// avoid name collision systems.hpp
inline void
@@ -1719,34 +1710,26 @@ inline void
{
BMCWEB_LOG_DEBUG << "Getting Manager Last Reset Time";
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<uint64_t>(
+ *crow::connections::systemBus, "xyz.openbmc_project.State.BMC",
+ "/xyz/openbmc_project/state/bmc0", "xyz.openbmc_project.State.BMC",
+ "LastRebootTime",
[aResp](const boost::system::error_code ec,
- dbus::utility::DbusVariantType& lastResetTime) {
+ const 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;
- }
// LastRebootTime is epoch time, in milliseconds
// https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.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.BMC", "/xyz/openbmc_project/state/bmc0",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.State.BMC", "LastRebootTime");
+ });
}
/**
@@ -2034,33 +2017,25 @@ inline void requestRoutesManager(App& app)
if (!started)
{
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<double>(
+ *crow::connections::systemBus, "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1.Manager", "Progress",
[asyncResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& resp) {
+ const double& val) {
if (ec)
{
BMCWEB_LOG_ERROR << "Error while getting progress";
messages::internalError(asyncResp->res);
return;
}
- const double* val = std::get_if<double>(&resp);
- if (val == nullptr)
- {
- BMCWEB_LOG_ERROR
- << "Invalid response while getting progress";
- messages::internalError(asyncResp->res);
- return;
- }
- if (*val < 1.0)
+ if (val < 1.0)
{
asyncResp->res.jsonValue["Status"]["State"] =
"Starting";
started = true;
}
- },
- "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
- "org.freedesktop.DBus.Properties", "Get",
- "org.freedesktop.systemd1.Manager", "Progress");
+ });
}
crow::connections::systemBus->async_method_call(
diff --git a/redfish-core/lib/metric_report.hpp b/redfish-core/lib/metric_report.hpp
index c36f719a56..b7ebb9902e 100644
--- a/redfish-core/lib/metric_report.hpp
+++ b/redfish-core/lib/metric_report.hpp
@@ -6,6 +6,7 @@
#include <app.hpp>
#include <dbus_utility.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
namespace redfish
{
@@ -35,7 +36,7 @@ inline nlohmann::json toMetricValues(const Readings& readings)
}
inline bool fillReport(nlohmann::json& json, const std::string& id,
- const dbus::utility::DbusVariantType& var)
+ const TimestampReadings& timestampReadings)
{
json["@odata.type"] = "#MetricReport.v1_3_0.MetricReport";
json["@odata.id"] = telemetry::metricReportUri + std::string("/") + id;
@@ -44,15 +45,7 @@ inline bool fillReport(nlohmann::json& json, const std::string& id,
json["MetricReportDefinition"]["@odata.id"] =
telemetry::metricReportDefinitionUri + std::string("/") + id;
- const TimestampReadings* timestampReadings =
- std::get_if<TimestampReadings>(&var);
- if (!timestampReadings)
- {
- BMCWEB_LOG_ERROR << "Property type mismatch or property is missing";
- return false;
- }
-
- const auto& [timestamp, readings] = *timestampReadings;
+ const auto& [timestamp, readings] = timestampReadings;
json["Timestamp"] = crow::utility::getDateTimeUint(timestamp);
json["MetricValues"] = toMetricValues(readings);
return true;
@@ -105,10 +98,13 @@ inline void requestRoutesMetricReport(App& app)
return;
}
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<
+ telemetry::TimestampReadings>(
+ *crow::connections::systemBus, telemetry::service,
+ reportPath, telemetry::reportInterface, "Readings",
[asyncResp,
id](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& ret) {
+ const telemetry::TimestampReadings& ret) {
if (ec)
{
BMCWEB_LOG_ERROR
@@ -117,15 +113,9 @@ inline void requestRoutesMetricReport(App& app)
return;
}
- if (!telemetry::fillReport(
- asyncResp->res.jsonValue, id, ret))
- {
- messages::internalError(asyncResp->res);
- }
- },
- telemetry::service, reportPath,
- "org.freedesktop.DBus.Properties", "Get",
- telemetry::reportInterface, "Readings");
+ telemetry::fillReport(asyncResp->res.jsonValue,
+ id, ret);
+ });
},
telemetry::service, reportPath, telemetry::reportInterface,
"Update");
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index e7411ac00b..a0ecdf9d32 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -22,6 +22,7 @@
#include <app.hpp>
#include <dbus_utility.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
#include <utils/json_utils.hpp>
#include <utils/stl_utils.hpp>
@@ -369,29 +370,29 @@ inline std::string getHostName()
inline void
getNTPProtocolEnabled(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, "xyz.openbmc_project.Settings",
+ "/xyz/openbmc_project/time/sync_method",
+ "xyz.openbmc_project.Time.Synchronization", "TimeSyncMethod",
[asyncResp](const boost::system::error_code errorCode,
- const dbus::utility::DbusVariantType& timeSyncMethod) {
+ const std::string& timeSyncMethod) {
if (errorCode)
{
return;
}
- const std::string* s = std::get_if<std::string>(&timeSyncMethod);
-
- if (*s == "xyz.openbmc_project.Time.Synchronization.Method.NTP")
+ if (timeSyncMethod ==
+ "xyz.openbmc_project.Time.Synchronization.Method.NTP")
{
asyncResp->res.jsonValue["NTP"]["ProtocolEnabled"] = true;
}
- else if (*s ==
- "xyz.openbmc_project.Time.Synchronization.Method.Manual")
+ else if (timeSyncMethod ==
+ "xyz.openbmc_project.Time.Synchronization."
+ "Method.Manual")
{
asyncResp->res.jsonValue["NTP"]["ProtocolEnabled"] = false;
}
- },
- "xyz.openbmc_project.Settings", "/xyz/openbmc_project/time/sync_method",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Time.Synchronization", "TimeSyncMethod");
+ });
}
inline void requestRoutesNetworkProtocol(App& app)
diff --git a/redfish-core/lib/power.hpp b/redfish-core/lib/power.hpp
index dea6be3dc1..ad3ca8ec12 100644
--- a/redfish-core/lib/power.hpp
+++ b/redfish-core/lib/power.hpp
@@ -69,58 +69,47 @@ inline void setPowerCapOverride(
{
return;
}
- auto valueHandler = [value, sensorsAsyncResp](
- const boost::system::error_code ec,
- const dbus::utility::DbusVariantType&
- powerCapEnable) {
- if (ec)
- {
- messages::internalError(sensorsAsyncResp->asyncResp->res);
- BMCWEB_LOG_ERROR << "powerCapEnable Get handler: Dbus error "
- << ec;
- return;
- }
- // Check PowerCapEnable
- const bool* b = std::get_if<bool>(&powerCapEnable);
- if (b == nullptr)
- {
- messages::internalError(sensorsAsyncResp->asyncResp->res);
- BMCWEB_LOG_ERROR << "Fail to get PowerCapEnable status ";
- return;
- }
- if (!(*b))
- {
- messages::actionNotSupported(
- sensorsAsyncResp->asyncResp->res,
- "Setting LimitInWatts when PowerLimit feature is disabled");
- BMCWEB_LOG_ERROR << "PowerLimit feature is disabled ";
- return;
- }
-
- crow::connections::systemBus->async_method_call(
- [sensorsAsyncResp](const boost::system::error_code ec2) {
- if (ec2)
- {
- BMCWEB_LOG_DEBUG << "Power Limit Set: Dbus error: "
- << ec2;
- messages::internalError(
- sensorsAsyncResp->asyncResp->res);
- return;
- }
- sensorsAsyncResp->asyncResp->res.result(
- boost::beast::http::status::no_content);
- },
- "xyz.openbmc_project.Settings",
- "/xyz/openbmc_project/control/host0/power_cap",
- "org.freedesktop.DBus.Properties", "Set",
- "xyz.openbmc_project.Control.Power.Cap", "PowerCap",
- dbus::utility::DbusVariantType(*value));
- };
- crow::connections::systemBus->async_method_call(
- std::move(valueHandler), "xyz.openbmc_project.Settings",
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus, "xyz.openbmc_project.Settings",
"/xyz/openbmc_project/control/host0/power_cap",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Control.Power.Cap", "PowerCapEnable");
+ "xyz.openbmc_project.Control.Power.Cap", "PowerCapEnable",
+ [value, sensorsAsyncResp](const boost::system::error_code ec,
+ bool powerCapEnable) {
+ if (ec)
+ {
+ messages::internalError(sensorsAsyncResp->asyncResp->res);
+ BMCWEB_LOG_ERROR
+ << "powerCapEnable Get handler: Dbus error " << ec;
+ return;
+ }
+ if (!powerCapEnable)
+ {
+ messages::actionNotSupported(
+ sensorsAsyncResp->asyncResp->res,
+ "Setting LimitInWatts when PowerLimit feature is disabled");
+ BMCWEB_LOG_ERROR << "PowerLimit feature is disabled ";
+ return;
+ }
+
+ crow::connections::systemBus->async_method_call(
+ [sensorsAsyncResp](const boost::system::error_code ec2) {
+ if (ec2)
+ {
+ BMCWEB_LOG_DEBUG << "Power Limit Set: Dbus error: "
+ << ec2;
+ messages::internalError(
+ sensorsAsyncResp->asyncResp->res);
+ return;
+ }
+ sensorsAsyncResp->asyncResp->res.result(
+ boost::beast::http::status::no_content);
+ },
+ "xyz.openbmc_project.Settings",
+ "/xyz/openbmc_project/control/host0/power_cap",
+ "org.freedesktop.DBus.Properties", "Set",
+ "xyz.openbmc_project.Control.Power.Cap", "PowerCap",
+ std::variant<uint32_t>(*value));
+ });
};
getValidChassisPath(sensorsAsyncResp, std::move(getChassisPath));
}
diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp
index df0d0bb65f..b33f9120a3 100644
--- a/redfish-core/lib/processor.hpp
+++ b/redfish-core/lib/processor.hpp
@@ -15,12 +15,15 @@
*/
#pragma once
+#include "dbus_singleton.hpp"
+#include "error_messages.hpp"
#include "health.hpp"
#include <app.hpp>
#include <boost/container/flat_map.hpp>
#include <dbus_utility.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
#include <sdbusplus/message/native_types.hpp>
#include <sdbusplus/utility/dedup_variant.hpp>
#include <utils/collection.hpp>
@@ -59,28 +62,19 @@ inline void getProcessorUUID(std::shared_ptr<bmcweb::AsyncResp> aResp,
const std::string& objPath)
{
BMCWEB_LOG_DEBUG << "Get Processor UUID";
- crow::connections::systemBus->async_method_call(
- [objPath, aResp{std::move(aResp)}](
- const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& property) {
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, service, objPath,
+ "xyz.openbmc_project.Common.UUID", "UUID",
+ [objPath, aResp{std::move(aResp)}](const boost::system::error_code ec,
+ const std::string& property) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error";
messages::internalError(aResp->res);
return;
}
- const std::string* value = std::get_if<std::string>(&property);
- if (value == nullptr)
- {
- BMCWEB_LOG_DEBUG << "Null value returned "
- "for UUID";
- messages::internalError(aResp->res);
- return;
- }
- aResp->res.jsonValue["UUID"] = *value;
- },
- service, objPath, "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Common.UUID", "UUID");
+ aResp->res.jsonValue["UUID"] = property;
+ });
}
inline void
@@ -595,10 +589,15 @@ inline void getCpuConfigData(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
// Once we found the current applied config, queue another
// request to read the base freq core ids out of that
// config.
- crow::connections::systemBus->async_method_call(
- [aResp](
- const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& property) {
+ sdbusplus::asio::getProperty<
+ BaseSpeedPrioritySettingsProperty>(
+ *crow::connections::systemBus, service, dbusPath,
+ "xyz.openbmc_project.Inventory.Item.Cpu."
+ "OperatingConfig",
+ "BaseSpeedPrioritySettings",
+ [aResp](const boost::system::error_code ec,
+ const BaseSpeedPrioritySettingsProperty&
+ baseSpeedList) {
if (ec)
{
BMCWEB_LOG_WARNING
@@ -606,18 +605,9 @@ inline void getCpuConfigData(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
messages::internalError(aResp->res);
return;
}
- auto baseSpeedList =
- std::get_if<BaseSpeedPrioritySettingsProperty>(
- &property);
- if (baseSpeedList != nullptr)
- {
- highSpeedCoreIdsHandler(aResp, *baseSpeedList);
- }
- },
- service, dbusPath, "org.freedesktop.DBus.Properties",
- "Get",
- "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig",
- "BaseSpeedPrioritySettings");
+
+ highSpeedCoreIdsHandler(aResp, baseSpeedList);
+ });
}
else if (dbusPropName == "BaseSpeedPriorityEnabled")
{
@@ -647,10 +637,11 @@ inline void getCpuLocationCode(std::shared_ptr<bmcweb::AsyncResp> aResp,
const std::string& objPath)
{
BMCWEB_LOG_DEBUG << "Get Cpu Location Data";
- crow::connections::systemBus->async_method_call(
- [objPath, aResp{std::move(aResp)}](
- const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& property) {
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, service, objPath,
+ "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
+ [objPath, aResp{std::move(aResp)}](const boost::system::error_code ec,
+ const std::string& property) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error";
@@ -658,21 +649,9 @@ inline void getCpuLocationCode(std::shared_ptr<bmcweb::AsyncResp> aResp,
return;
}
- const std::string* value = std::get_if<std::string>(&property);
-
- if (value == nullptr)
- {
- // illegal value
- BMCWEB_LOG_DEBUG << "Location code value error";
- messages::internalError(aResp->res);
- return;
- }
-
aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
- *value;
- },
- service, objPath, "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode");
+ property;
+ });
}
/**
@@ -688,23 +667,20 @@ inline void getCpuUniqueId(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
const std::string& objectPath)
{
BMCWEB_LOG_DEBUG << "Get CPU UniqueIdentifier";
- crow::connections::systemBus->async_method_call(
- [aResp](boost::system::error_code ec,
- const dbus::utility::DbusVariantType& property) {
- const std::string* id = std::get_if<std::string>(&property);
- if (ec || id == nullptr)
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, service, objectPath,
+ "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier",
+ "UniqueIdentifier",
+ [aResp](boost::system::error_code ec, const std::string& id) {
+ if (ec)
{
BMCWEB_LOG_ERROR << "Failed to read cpu unique id: " << ec;
messages::internalError(aResp->res);
return;
}
aResp->res
- .jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] =
- *id;
- },
- service, objectPath, "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier",
- "UniqueIdentifier");
+ .jsonValue["ProcessorId"]["ProtectedIdentificationNumber"] = id;
+ });
}
/**
diff --git a/redfish-core/lib/redfish_util.hpp b/redfish-core/lib/redfish_util.hpp
index c0835b3563..b631f91ec8 100644
--- a/redfish-core/lib/redfish_util.hpp
+++ b/redfish-core/lib/redfish_util.hpp
@@ -170,21 +170,20 @@ void getPortStatusAndPath(const std::string& serviceName,
template <typename CallbackFunc>
void getPortNumber(const std::string& socketPath, CallbackFunc&& callback)
{
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<
+ std::vector<std::tuple<std::string, std::string>>>(
+ *crow::connections::systemBus, "org.freedesktop.systemd1", socketPath,
+ "org.freedesktop.systemd1.Socket", "Listen",
[callback{std::move(callback)}](
const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& resp) {
+ const std::vector<std::tuple<std::string, std::string>>& resp) {
if (ec)
{
BMCWEB_LOG_ERROR << ec;
callback(ec, 0);
return;
}
- const std::vector<
- std::tuple<std::string, std::string>>* responsePtr =
- std::get_if<std::vector<std::tuple<std::string, std::string>>>(
- &resp);
- if (responsePtr == nullptr || responsePtr->size() < 1)
+ if (resp.size() < 1)
{
// Network Protocol Listen Response Elements is empty
boost::system::error_code ec1 =
@@ -196,7 +195,7 @@ void getPortNumber(const std::string& socketPath, CallbackFunc&& callback)
return;
}
const std::string& listenStream =
- std::get<NET_PROTO_LISTEN_STREAM>((*responsePtr)[0]);
+ std::get<NET_PROTO_LISTEN_STREAM>(resp[0]);
const char* pa = &listenStream[listenStream.rfind(':') + 1];
int port{0};
if (auto [p, ec2] = std::from_chars(pa, nullptr, port);
@@ -217,10 +216,7 @@ void getPortNumber(const std::string& socketPath, CallbackFunc&& callback)
BMCWEB_LOG_ERROR << ec3;
}
callback(ec, port);
- },
- "org.freedesktop.systemd1", socketPath,
- "org.freedesktop.DBus.Properties", "Get",
- "org.freedesktop.systemd1.Socket", "Listen");
+ });
}
} // namespace redfish
diff --git a/redfish-core/lib/roles.hpp b/redfish-core/lib/roles.hpp
index 5aa1a22bfd..c18942f5b0 100644
--- a/redfish-core/lib/roles.hpp
+++ b/redfish-core/lib/roles.hpp
@@ -18,9 +18,9 @@
#include <app.hpp>
#include <dbus_utility.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
#include <variant>
-
namespace redfish
{
@@ -114,9 +114,13 @@ inline void requestRoutesRoleCollection(App& app)
{"Name", "Roles Collection"},
{"Description", "BMC User Roles"}};
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::vector<std::string>>(
+ *crow::connections::systemBus,
+ "xyz.openbmc_project.User.Manager",
+ "/xyz/openbmc_project/user",
+ "xyz.openbmc_project.User.Manager", "AllPrivileges",
[asyncResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& resp) {
+ const std::vector<std::string>& privList) {
if (ec)
{
messages::internalError(asyncResp->res);
@@ -125,14 +129,7 @@ inline void requestRoutesRoleCollection(App& app)
nlohmann::json& memberArray =
asyncResp->res.jsonValue["Members"];
memberArray = nlohmann::json::array();
- const std::vector<std::string>* privList =
- std::get_if<std::vector<std::string>>(&resp);
- if (privList == nullptr)
- {
- messages::internalError(asyncResp->res);
- return;
- }
- for (const std::string& priv : *privList)
+ for (const std::string& priv : privList)
{
std::string role = getRoleFromPrivileges(priv);
if (!role.empty())
@@ -145,11 +142,7 @@ inline void requestRoutesRoleCollection(App& app)
}
asyncResp->res.jsonValue["Members@odata.count"] =
memberArray.size();
- },
- "xyz.openbmc_project.User.Manager",
- "/xyz/openbmc_project/user",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.User.Manager", "AllPrivileges");
+ });
});
}
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 2f04c25058..5c86579c48 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -23,6 +23,7 @@
#include <dbus_singleton.hpp>
#include <dbus_utility.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
#include <utils/json_utils.hpp>
#include <cmath>
@@ -592,10 +593,12 @@ void getChassis(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
sensorsAsyncResp->asyncResp->res.jsonValue["Name"] = chassisSubNode;
// Get the list of all sensors for this Chassis element
std::string sensorPath = *chassisPath + "/all_sensors";
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::vector<std::string>>(
+ *crow::connections::systemBus, "xyz.openbmc_project.ObjectMapper",
+ sensorPath, "xyz.openbmc_project.Association", "endpoints",
[sensorsAsyncResp, callback{std::move(callback)}](
const boost::system::error_code& e,
- const dbus::utility::DbusVariantType& variantEndpoints) {
+ const std::vector<std::string>& nodeSensorList) {
if (e)
{
if (e.value() != EBADR)
@@ -605,32 +608,13 @@ void getChassis(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp,
return;
}
}
- const std::vector<std::string>* nodeSensorList =
- std::get_if<std::vector<std::string>>(&(variantEndpoints));
- if (nodeSensorList == nullptr)
- {
- messages::resourceNotFound(
- sensorsAsyncResp->asyncResp->res,
- sensorsAsyncResp->chassisSubNode,
- sensorsAsyncResp->chassisSubNode ==
- sensors::node::thermal
- ? "Temperatures"
- : sensorsAsyncResp->chassisSubNode ==
- sensors::node::power
- ? "Voltages"
- : "Sensors");
- return;
- }
const std::shared_ptr<boost::container::flat_set<std::string>>
culledSensorList = std::make_shared<
boost::container::flat_set<std::string>>();
- reduceSensorList(sensorsAsyncResp, nodeSensorList,
+ reduceSensorList(sensorsAsyncResp, &nodeSensorList,
culledSensorList);
callback(culledSensorList);
- },
- "xyz.openbmc_project.ObjectMapper", sensorPath,
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Association", "endpoints");
+ });
};
// Get the Chassis Collection
@@ -1177,37 +1161,27 @@ inline void populateFanRedundancy(
}
const std::string& owner = objDict.begin()->first;
- crow::connections::systemBus->async_method_call(
- [path, owner,
- sensorsAsyncResp](const boost::system::error_code e,
- const dbus::utility::DbusVariantType&
- variantEndpoints) {
+ sdbusplus::asio::getProperty<std::vector<std::string>>(
+ *crow::connections::systemBus,
+ "xyz.openbmc_project.ObjectMapper", path + "/chassis",
+ "xyz.openbmc_project.Association", "endpoints",
+ [path, owner, sensorsAsyncResp](
+ const boost::system::error_code e,
+ const std::vector<std::string>& endpoints) {
if (e)
{
return; // if they don't have an association we
// can't tell what chassis is
}
- // verify part of the right chassis
- auto endpoints = std::get_if<std::vector<std::string>>(
- &variantEndpoints);
-
- if (endpoints == nullptr)
- {
- BMCWEB_LOG_ERROR << "Invalid association interface";
- messages::internalError(
- sensorsAsyncResp->asyncResp->res);
- return;
- }
-
auto found = std::find_if(
- endpoints->begin(), endpoints->end(),
+ endpoints.begin(), endpoints.end(),
[sensorsAsyncResp](const std::string& entry) {
return entry.find(
sensorsAsyncResp->chassisId) !=
std::string::npos;
});
- if (found == endpoints->end())
+ if (found == endpoints.end())
{
return;
}
@@ -1347,10 +1321,7 @@ inline void populateFanRedundancy(
owner, path, "org.freedesktop.DBus.Properties",
"GetAll",
"xyz.openbmc_project.Control.FanRedundancy");
- },
- "xyz.openbmc_project.ObjectMapper", path + "/chassis",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Association", "endpoints");
+ });
}
},
"xyz.openbmc_project.ObjectMapper",
@@ -2013,39 +1984,35 @@ void getInventoryLedData(
const std::string& ledPath = (*it).first;
const std::string& ledConnection = (*it).second;
// Response handler for Get State property
- auto respHandler = [sensorsAsyncResp, inventoryItems, ledConnections,
- ledPath, callback{std::move(callback)},
- ledConnectionsIndex](
- const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& ledState) {
- BMCWEB_LOG_DEBUG << "getInventoryLedData respHandler enter";
- if (ec)
- {
- BMCWEB_LOG_ERROR
- << "getInventoryLedData respHandler DBus error " << ec;
- messages::internalError(sensorsAsyncResp->asyncResp->res);
- return;
- }
+ auto respHandler =
+ [sensorsAsyncResp, inventoryItems, ledConnections, ledPath,
+ callback{std::move(callback)}, ledConnectionsIndex](
+ const boost::system::error_code ec, const std::string& state) {
+ BMCWEB_LOG_DEBUG << "getInventoryLedData respHandler enter";
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR
+ << "getInventoryLedData respHandler DBus error " << ec;
+ messages::internalError(sensorsAsyncResp->asyncResp->res);
+ return;
+ }
- const std::string* state = std::get_if<std::string>(&ledState);
- if (state != nullptr)
- {
- BMCWEB_LOG_DEBUG << "Led state: " << *state;
+ BMCWEB_LOG_DEBUG << "Led state: " << state;
// Find inventory item with this LED object path
InventoryItem* inventoryItem =
findInventoryItemForLed(*inventoryItems, ledPath);
if (inventoryItem != nullptr)
{
// Store LED state in InventoryItem
- if (boost::ends_with(*state, "On"))
+ if (boost::ends_with(state, "On"))
{
inventoryItem->ledState = LedState::ON;
}
- else if (boost::ends_with(*state, "Blink"))
+ else if (boost::ends_with(state, "Blink"))
{
inventoryItem->ledState = LedState::BLINK;
}
- else if (boost::ends_with(*state, "Off"))
+ else if (boost::ends_with(state, "Off"))
{
inventoryItem->ledState = LedState::OFF;
}
@@ -2054,26 +2021,20 @@ void getInventoryLedData(
inventoryItem->ledState = LedState::UNKNOWN;
}
}
- }
- else
- {
- BMCWEB_LOG_DEBUG << "Failed to find State data for LED: "
- << ledPath;
- }
- // Recurse to get LED data from next connection
- getInventoryLedData(sensorsAsyncResp, inventoryItems,
- ledConnections, std::move(callback),
- ledConnectionsIndex + 1);
+ // Recurse to get LED data from next connection
+ getInventoryLedData(sensorsAsyncResp, inventoryItems,
+ ledConnections, std::move(callback),
+ ledConnectionsIndex + 1);
- BMCWEB_LOG_DEBUG << "getInventoryLedData respHandler exit";
- };
+ BMCWEB_LOG_DEBUG << "getInventoryLedData respHandler exit";
+ };
// Get the State property for the current LED
- crow::connections::systemBus->async_method_call(
- std::move(respHandler), ledConnection, ledPath,
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Led.Physical", "State");
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, ledConnection, ledPath,
+ "xyz.openbmc_project.Led.Physical", "State",
+ std::move(respHandler));
}
BMCWEB_LOG_DEBUG << "getInventoryLedData exit";
@@ -2213,8 +2174,7 @@ void getPowerSupplyAttributesData(
auto respHandler = [sensorsAsyncResp, inventoryItems,
callback{std::move(callback)}](
const boost::system::error_code ec,
- const dbus::utility::DbusVariantType&
- deratingFactor) {
+ const uint32_t value) {
BMCWEB_LOG_DEBUG << "getPowerSupplyAttributesData respHandler enter";
if (ec)
{
@@ -2224,25 +2184,16 @@ void getPowerSupplyAttributesData(
return;
}
- const uint32_t* value = std::get_if<uint32_t>(&deratingFactor);
- if (value != nullptr)
+ BMCWEB_LOG_DEBUG << "PS EfficiencyPercent value: " << value;
+ // Store value in Power Supply Inventory Items
+ for (InventoryItem& inventoryItem : *inventoryItems)
{
- BMCWEB_LOG_DEBUG << "PS EfficiencyPercent value: " << *value;
- // Store value in Power Supply Inventory Items
- for (InventoryItem& inventoryItem : *inventoryItems)
+ if (inventoryItem.isPowerSupply == true)
{
- if (inventoryItem.isPowerSupply == true)
- {
- inventoryItem.powerSupplyEfficiencyPercent =
- static_cast<int>(*value);
- }
+ inventoryItem.powerSupplyEfficiencyPercent =
+ static_cast<int>(value);
}
}
- else
- {
- BMCWEB_LOG_DEBUG
- << "Failed to find EfficiencyPercent value for PowerSupplies";
- }
BMCWEB_LOG_DEBUG << "getPowerSupplyAttributesData respHandler exit";
callback(inventoryItems);
@@ -2250,10 +2201,10 @@ void getPowerSupplyAttributesData(
// Get the DeratingFactor property for the PowerSupplyAttributes
// Currently only property on the interface/only one we care about
- crow::connections::systemBus->async_method_call(
- std::move(respHandler), psAttributesConnection, psAttributesPath,
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Control.PowerSupplyAttributes", "DeratingFactor");
+ sdbusplus::asio::getProperty<uint32_t>(
+ *crow::connections::systemBus, psAttributesConnection, psAttributesPath,
+ "xyz.openbmc_project.Control.PowerSupplyAttributes", "DeratingFactor",
+ std::move(respHandler));
BMCWEB_LOG_DEBUG << "getPowerSupplyAttributesData exit";
}
diff --git a/redfish-core/lib/storage.hpp b/redfish-core/lib/storage.hpp
index 4ad3040bcc..f5e75e5269 100644
--- a/redfish-core/lib/storage.hpp
+++ b/redfish-core/lib/storage.hpp
@@ -21,6 +21,7 @@
#include <app.hpp>
#include <dbus_utility.hpp>
#include <registries/privilege_registry.hpp>
+#include <sdbusplus/asio/property.hpp>
namespace redfish
{
@@ -159,36 +160,26 @@ inline void requestRoutesStorage(App& app)
storageController["MemberId"] = id;
storageController["Status"]["State"] = "Enabled";
- crow::connections::systemBus->async_method_call(
- [asyncResp, index](
- const boost::system::error_code ec2,
- const dbus::utility::DbusVariantType present) {
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus, connectionName, path,
+ "xyz.openbmc_project.Inventory.Item", "Present",
+ [asyncResp,
+ index](const boost::system::error_code ec2,
+ bool enabled) {
// this interface isn't necessary, only check it
// if we get a good return
if (ec2)
{
return;
}
- const bool* enabled =
- std::get_if<bool>(&present);
- if (enabled == nullptr)
- {
- BMCWEB_LOG_DEBUG
- << "Illegal property present";
- messages::internalError(asyncResp->res);
- return;
- }
- if (!(*enabled))
+ if (!enabled)
{
asyncResp->res
.jsonValue["StorageControllers"][index]
["Status"]["State"] =
"Disabled";
}
- },
- connectionName, path,
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Inventory.Item", "Present");
+ });
crow::connections::systemBus->async_method_call(
[asyncResp, index](
@@ -309,9 +300,11 @@ inline void getDrivePresent(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& connectionName,
const std::string& path)
{
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus, connectionName, path,
+ "xyz.openbmc_project.Inventory.Item", "Present",
[asyncResp, path](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType present) {
+ const bool enabled) {
// this interface isn't necessary, only check it if
// we get a good return
if (ec)
@@ -319,29 +312,21 @@ inline void getDrivePresent(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
return;
}
- const bool* enabled = std::get_if<bool>(&present);
- if (enabled == nullptr)
- {
- BMCWEB_LOG_DEBUG << "Illegal property present";
- messages::internalError(asyncResp->res);
- return;
- }
- if (!(*enabled))
+ if (!enabled)
{
asyncResp->res.jsonValue["Status"]["State"] = "Disabled";
}
- },
- connectionName, path, "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Inventory.Item", "Present");
+ });
}
inline void getDriveState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& connectionName,
const std::string& path)
{
- crow::connections::systemBus->async_method_call(
- [asyncResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType rebuilding) {
+ sdbusplus::asio::getProperty<bool>(
+ *crow::connections::systemBus, connectionName, path,
+ "xyz.openbmc_project.State.Drive", "Rebuilding",
+ [asyncResp](const boost::system::error_code ec, const bool updating) {
// this interface isn't necessary, only check it
// if we get a good return
if (ec)
@@ -349,25 +334,15 @@ inline void getDriveState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
return;
}
- const bool* updating = std::get_if<bool>(&rebuilding);
- if (updating == nullptr)
- {
- BMCWEB_LOG_DEBUG << "Illegal property present";
- messages::internalError(asyncResp->res);
- return;
- }
-
// updating and disabled in the backend shouldn't be
// able to be set at the same time, so we don't need
// to check for the race condition of these two
// calls
- if (*updating)
+ if (updating)
{
asyncResp->res.jsonValue["Status"]["State"] = "Updating";
}
- },
- connectionName, path, "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.State.Drive", "Rebuilding");
+ });
}
inline void requestRoutesDrive(App& app)
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index b3094df431..a21b6a0f4a 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 @@ namespace redfish
*/
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 @@ inline void
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 @@ inline void
*
* @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);
-
- if (isCpuPresent == nullptr)
- {
- messages::internalError(aResp->res);
- return;
- }
- BMCWEB_LOG_DEBUG << "Cpu Present: " << *isCpuPresent;
+ BMCWEB_LOG_DEBUG << "Cpu Present: " << isCpuPresent;
- if (*isCpuPresent == true)
+ if (isCpuPresent == true)
{
nlohmann::json& procCount =
aResp->res.jsonValue["ProcessorSummary"]["Count"];
@@ -111,18 +100,11 @@ inline void modifyCpuPresenceState(
*
* @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 @@ inline void modifyCpuFunctionalState(
// Functional.
if (prevProcState == "Disabled")
{
- if (*isCpuFunctional == true)
+ if (isCpuFunctional == true)
{
aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] =
"Enabled";
@@ -149,39 +131,37 @@ inline void getProcessorProperties(
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 @@ inline void
}
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 @@ inline void
}
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 @@ inline void
"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 @@ inline void
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
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 @@ inline void getHostState(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
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 int assignBootParameters(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
*/
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 @@ inline void getBootProgress(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
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 @@ inline void getBootProgress(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
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 getBootProgress(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
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 @@ inline void getBootOverrideType(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
}
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 getBootOverrideType(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
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 @@ inline void getBootOverrideMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
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 getBootOverrideMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
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 @@ inline void
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 @@ inline void
// 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 @@ inline void
// 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 @@ inline void
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 @@ inline void
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
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 @@ inline void
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 @@ inline void getLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{
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 @@ inline void getAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
{
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 @@ inline void getAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
.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 @@ inline void
{
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 @@ inline void
{"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 @@ inline void
}
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 @@ inline void getTrustedModuleRequiredToBoot(
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 @@ inline void getTrustedModuleRequiredToBoot(
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 @@ inline void getTrustedModuleRequiredToBoot(
.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 @@ inline void getPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
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 @@ inline void getPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
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 @@ inline void requestRoutesSystemsCollection(App& app)
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 @@ inline void requestRoutesSystemsCollection(App& app)
"/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");
+ });
});
}
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index f5528e1a70..fde878e4aa 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -21,6 +21,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>
namespace redfish
@@ -542,9 +543,12 @@ inline void requestRoutesUpdateService(App& app)
{"TFTP"};
#endif
// Get the current ApplyTime value
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getProperty<std::string>(
+ *crow::connections::systemBus, "xyz.openbmc_project.Settings",
+ "/xyz/openbmc_project/software/apply_time",
+ "xyz.openbmc_project.Software.ApplyTime", "RequestedApplyTime",
[asyncResp](const boost::system::error_code ec,
- const dbus::utility::DbusVariantType& applyTime) {
+ const std::string& applyTime) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
@@ -552,34 +556,25 @@ inline void requestRoutesUpdateService(App& app)
return;
}
- const std::string* s = std::get_if<std::string>(&applyTime);
- if (s == nullptr)
- {
- return;
- }
// Store the ApplyTime Value
- if (*s ==
- "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.Immediate")
+ if (applyTime == "xyz.openbmc_project.Software.ApplyTime."
+ "RequestedApplyTimes.Immediate")
{
asyncResp->res
.jsonValue["HttpPushUriOptions"]
["HttpPushUriApplyTime"]["ApplyTime"] =
"Immediate";
}
- else if (
- *s ==
- "xyz.openbmc_project.Software.ApplyTime.RequestedApplyTimes.OnReset")
+ else if (applyTime ==
+ "xyz.openbmc_project.Software.ApplyTime."
+ "RequestedApplyTimes.OnReset")
{
asyncResp->res
.jsonValue["HttpPushUriOptions"]
["HttpPushUriApplyTime"]["ApplyTime"] =
"OnReset";
}
- },
- "xyz.openbmc_project.Settings",
- "/xyz/openbmc_project/software/apply_time",
- "org.freedesktop.DBus.Properties", "Get",
- "xyz.openbmc_project.Software.ApplyTime", "RequestedApplyTime");
+ });
});
BMCWEB_ROUTE(app, "/redfish/v1/UpdateService/")
.privileges(redfish::privileges::patchUpdateService)