used sdbusplus::unpackPropertiesNoThrow part 2
used sdbusplus::unpackPropertiesNoThrow in managers.hpp, also replaced
all usages of "GetAll" with sdbusplus::asio::getAllProperties
bmcweb size: 2677080 -> 2672984 (-4096)
compressed size: 1128633 -> 1128611 (-22)
Tested:
Performed get on:
- /redfish/v1/Managers
- /redfish/v1/Managers/bmc
Get result before and after the change was the same
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Change-Id: If1a0227eda106361ed9dda74a5f13ada3ef07d69
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index dcd7876..a98ff22 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -21,10 +21,13 @@
#include "query.hpp"
#include "redfish_util.hpp"
#include "registries/privilege_registry.hpp"
+#include "utils/dbus_utils.hpp"
#include "utils/sw_utils.hpp"
#include "utils/systemd_utils.hpp"
#include <boost/date_time.hpp>
+#include <sdbusplus/asio/property.hpp>
+#include <sdbusplus/unpack_properties.hpp>
#include <algorithm>
#include <cstdint>
@@ -1219,7 +1222,9 @@
const std::string& path = subtreeLocal[0].first;
const std::string& owner = subtreeLocal[0].second[0].first;
- crow::connections::systemBus->async_method_call(
+
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, owner, path, thermalModeIface,
[path, owner,
self](const boost::system::error_code ec2,
const dbus::utility::DBusPropertiesMap& resp) {
@@ -1230,36 +1235,20 @@
messages::internalError(self->asyncResp->res);
return;
}
+
const std::string* current = nullptr;
const std::vector<std::string>* supported = nullptr;
- for (const auto& [key, value] : resp)
+
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), resp, "Current", current,
+ "Supported", supported);
+
+ if (!success)
{
- if (key == "Current")
- {
- current = std::get_if<std::string>(&value);
- if (current == nullptr)
- {
- BMCWEB_LOG_ERROR
- << "GetPIDValues: thermal mode iface invalid "
- << path;
- messages::internalError(self->asyncResp->res);
- return;
- }
- }
- if (key == "Supported")
- {
- supported =
- std::get_if<std::vector<std::string>>(&value);
- if (supported == nullptr)
- {
- BMCWEB_LOG_ERROR
- << "GetPIDValues: thermal mode iface invalid"
- << path;
- messages::internalError(self->asyncResp->res);
- return;
- }
- }
+ messages::internalError(self->asyncResp->res);
+ return;
}
+
if (current == nullptr || supported == nullptr)
{
BMCWEB_LOG_ERROR
@@ -1269,9 +1258,7 @@
}
self->currentProfile = *current;
self->supportedProfiles = *supported;
- },
- owner, path, "org.freedesktop.DBus.Properties", "GetAll",
- thermalModeIface);
+ });
},
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
@@ -1437,7 +1424,8 @@
const std::string& path = subtree[0].first;
const std::string& owner = subtree[0].second[0].first;
- crow::connections::systemBus->async_method_call(
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, owner, path, thermalModeIface,
[self, path, owner](const boost::system::error_code ec2,
const dbus::utility::DBusPropertiesMap& r) {
if (ec2)
@@ -1449,34 +1437,17 @@
}
const std::string* current = nullptr;
const std::vector<std::string>* supported = nullptr;
- for (const auto& [key, value] : r)
+
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), r, "Current", current,
+ "Supported", supported);
+
+ if (!success)
{
- if (key == "Current")
- {
- current = std::get_if<std::string>(&value);
- if (current == nullptr)
- {
- BMCWEB_LOG_ERROR
- << "SetPIDValues: thermal mode iface invalid "
- << path;
- messages::internalError(self->asyncResp->res);
- return;
- }
- }
- if (key == "Supported")
- {
- supported =
- std::get_if<std::vector<std::string>>(&value);
- if (supported == nullptr)
- {
- BMCWEB_LOG_ERROR
- << "SetPIDValues: thermal mode iface invalid"
- << path;
- messages::internalError(self->asyncResp->res);
- return;
- }
- }
+ messages::internalError(self->asyncResp->res);
+ return;
}
+
if (current == nullptr || supported == nullptr)
{
BMCWEB_LOG_ERROR
@@ -1488,9 +1459,7 @@
self->supportedProfiles = *supported;
self->profileConnection = owner;
self->profilePath = path;
- },
- owner, path, "org.freedesktop.DBus.Properties", "GetAll",
- thermalModeIface);
+ });
},
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
@@ -2144,7 +2113,10 @@
if (interfaceName ==
"xyz.openbmc_project.Inventory.Decorator.Asset")
{
- crow::connections::systemBus->async_method_call(
+
+ sdbusplus::asio::getAllProperties(
+ *crow::connections::systemBus, connectionName, path,
+ "xyz.openbmc_project.Inventory.Decorator.Asset",
[asyncResp](const boost::system::error_code ec2,
const dbus::utility::DBusPropertiesMap&
propertiesList) {
@@ -2153,33 +2125,54 @@
BMCWEB_LOG_DEBUG << "Can't get bmc asset!";
return;
}
- for (const std::pair<std::string,
- dbus::utility::DbusVariantType>&
- property : propertiesList)
- {
- const std::string& propertyName = property.first;
- if ((propertyName == "PartNumber") ||
- (propertyName == "SerialNumber") ||
- (propertyName == "Manufacturer") ||
- (propertyName == "Model") ||
- (propertyName == "SparePartNumber"))
- {
- const std::string* value =
- std::get_if<std::string>(&property.second);
- if (value == nullptr)
- {
- // illegal property
- messages::internalError(asyncResp->res);
- return;
- }
- asyncResp->res.jsonValue[propertyName] = *value;
- }
+ const std::string* partNumber = nullptr;
+ const std::string* serialNumber = nullptr;
+ const std::string* manufacturer = nullptr;
+ const std::string* model = nullptr;
+ const std::string* sparePartNumber = nullptr;
+
+ const bool success = sdbusplus::unpackPropertiesNoThrow(
+ dbus_utils::UnpackErrorPrinter(), propertiesList,
+ "PartNumber", partNumber, "SerialNumber",
+ serialNumber, "Manufacturer", manufacturer, "Model",
+ model, "SparePartNumber", sparePartNumber);
+
+ if (!success)
+ {
+ messages::internalError(asyncResp->res);
+ return;
}
- },
- connectionName, path, "org.freedesktop.DBus.Properties",
- "GetAll",
- "xyz.openbmc_project.Inventory.Decorator.Asset");
+
+ if (partNumber != nullptr)
+ {
+ asyncResp->res.jsonValue["PartNumber"] =
+ *partNumber;
+ }
+
+ if (serialNumber != nullptr)
+ {
+ asyncResp->res.jsonValue["SerialNumber"] =
+ *serialNumber;
+ }
+
+ if (manufacturer != nullptr)
+ {
+ asyncResp->res.jsonValue["Manufacturer"] =
+ *manufacturer;
+ }
+
+ if (model != nullptr)
+ {
+ asyncResp->res.jsonValue["Model"] = *model;
+ }
+
+ if (sparePartNumber != nullptr)
+ {
+ asyncResp->res.jsonValue["SparePartNumber"] =
+ *sparePartNumber;
+ }
+ });
}
else if (interfaceName ==
"xyz.openbmc_project.Inventory.Decorator.LocationCode")