storage: simplify dbus call types
|connectionNames| can use MapperServiceMap, which is defined in
dbus_utility.hpp for GetSubTree response.
This commit also uses Structured binding declaration, which simplifies a
lot of for loops.
Tested:
1. code compiles. Strong type guarantees the correctness.
2. no Redfish Validator failures on Storage resource
Signed-off-by: Nan Zhou <nanzhoumails@gmail.com>
Change-Id: I50601e7551b0de49c2891b81789e97550bead6e3
diff --git a/redfish-core/lib/storage.hpp b/redfish-core/lib/storage.hpp
index 9cb172b..ecdf8b2 100644
--- a/redfish-core/lib/storage.hpp
+++ b/redfish-core/lib/storage.hpp
@@ -523,10 +523,8 @@
auto drive = std::find_if(
subtree.begin(), subtree.end(),
[&driveId](
- const std::pair<
- std::string,
- std::vector<std::pair<
- std::string, std::vector<std::string>>>>& object) {
+ const std::pair<std::string,
+ dbus::utility::MapperServiceMap>& object) {
return sdbusplus::message::object_path(object.first)
.filename() == driveId;
});
@@ -538,8 +536,8 @@
}
const std::string& path = drive->first;
- const std::vector<std::pair<std::string, std::vector<std::string>>>&
- connectionNames = drive->second;
+ const dbus::utility::MapperServiceMap& connectionNames =
+ drive->second;
asyncResp->res.jsonValue["@odata.type"] = "#Drive.v1_7_0.Drive";
asyncResp->res.jsonValue["@odata.id"] =
@@ -613,15 +611,8 @@
}
// Iterate over all retrieved ObjectPaths.
- for (const std::pair<
- std::string,
- std::vector<std::pair<std::string, std::vector<std::string>>>>&
- object : subtree)
+ for (const auto& [path, connectionNames] : subtree)
{
- const std::string& path = object.first;
- const dbus::utility::MapperGetObject& connectionNames =
- object.second;
-
sdbusplus::message::object_path objPath(path);
if (objPath.filename() != chassisId)
{
@@ -712,15 +703,8 @@
}
// Iterate over all retrieved ObjectPaths.
- for (const std::pair<
- std::string,
- std::vector<std::pair<std::string, std::vector<std::string>>>>&
- object : subtree)
+ for (const auto& [path, connectionNames] : subtree)
{
- const std::string& path = object.first;
- const std::vector<std::pair<std::string, std::vector<std::string>>>&
- connectionNames = object.second;
-
sdbusplus::message::object_path objPath(path);
if (objPath.filename() != driveName)
{
@@ -810,15 +794,8 @@
}
// Iterate over all retrieved ObjectPaths.
- for (const std::pair<
- std::string,
- std::vector<std::pair<std::string, std::vector<std::string>>>>&
- object : subtree)
+ for (const auto& [path, connectionNames] : subtree)
{
- const std::string& path = object.first;
- const std::vector<std::pair<std::string, std::vector<std::string>>>&
- connectionNames = object.second;
-
sdbusplus::message::object_path objPath(path);
if (objPath.filename() != chassisId)
{