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/managers.hpp b/redfish-core/lib/managers.hpp
index 7e5b272..39b0f88 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -1687,9 +1687,11 @@
{
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 @@
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 @@
{
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 @@
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(