summaryrefslogtreecommitdiff
path: root/redfish-core/include
diff options
context:
space:
mode:
authorLakshmi Yadlapati <lakshmiy@us.ibm.com>2023-09-27 07:53:28 +0300
committerLakshmi Yadlapati <lakshmiy@us.ibm.com>2023-09-28 09:24:41 +0300
commit36b5f1ed97fe5806c53e0eb5b2f9a07e9a8acd5f (patch)
treec9275c091aa3811c28de4f02b51d5f96d25f871a /redfish-core/include
parentf42e859032d9a28752108b327f02340be4de8de2 (diff)
downloadbmcweb-36b5f1ed97fe5806c53e0eb5b2f9a07e9a8acd5f.tar.xz
Refactor getCollectionMembers
This commit refactors the getCollectionMembers function into smaller functions. Additionally, the 'subtree' parameter is no longer a default parameter but is explicitly required in the function. All calls to getCollectionMembers have been updated to pass the 'subtree' parameter. Tested: Validator passed ''' curl -k https://$bmc/redfish/v1/Systems/system/Storage { "@odata.id": "/redfish/v1/Systems/system/Storage", "@odata.type": "#StorageCollection.StorageCollection", "Members": [ { "@odata.id": "/redfish/v1/Systems/system/Storage/1" } ], "Members@odata.count": 1, "Name": "Storage Collection" } curl -k https://$bmc/redfish/v1/Cables { "@odata.id": "/redfish/v1/Cables", "@odata.type": "#CableCollection.CableCollection", "Description": "Collection of Cable Entries", "Members": [ { "@odata.id": "/redfish/v1/Cables/dp0_cable0" }, { "@odata.id": "/redfish/v1/Cables/dp0_cable1" }, { "@odata.id": "/redfish/v1/Cables/dp0_cable2" }, { "@odata.id": "/redfish/v1/Cables/dp0_cable3" } ], "Members@odata.count": 4, "Name": "Cable Collection" } curl -k https://$bmc/redfish/v1/Chassis { "@odata.id": "/redfish/v1/Chassis", "@odata.type": "#ChassisCollection.ChassisCollection", "Members": [ { "@odata.id": "/redfish/v1/Chassis/chassis" } ], "Members@odata.count": 1, "Name": "Chassis Collection" } curl -k https://$bmc/redfish/v1/Systems/system/Memory { "@odata.id": "/redfish/v1/Systems/system/Memory", "@odata.type": "#MemoryCollection.MemoryCollection", "Members": [ { "@odata.id": "/redfish/v1/Systems/system/Memory/dimm0" }, { "@odata.id": "/redfish/v1/Systems/system/Memory/dimm1" }, ...... { "@odata.id": "/redfish/v1/Systems/system/Memory/dimm31" } ], "Members@odata.count": 32, "Name": "Memory Module Collection" } ''' Change-Id: If5091431b548f371bff03b2897fd0aaf8b0ef203 Signed-off-by: Lakshmi Yadlapati <lakshmiy@us.ibm.com>
Diffstat (limited to 'redfish-core/include')
-rw-r--r--redfish-core/include/utils/collection.hpp92
1 files changed, 48 insertions, 44 deletions
diff --git a/redfish-core/include/utils/collection.hpp b/redfish-core/include/utils/collection.hpp
index 0801cd5f4a..7d28c0f72b 100644
--- a/redfish-core/include/utils/collection.hpp
+++ b/redfish-core/include/utils/collection.hpp
@@ -20,6 +20,51 @@ namespace redfish
namespace collection_util
{
+inline void handleCollectionMembers(
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const boost::urls::url& collectionPath, const boost::system::error_code& ec,
+ const dbus::utility::MapperGetSubTreePathsResponse& objects)
+{
+ if (ec == boost::system::errc::io_error)
+ {
+ asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
+ asyncResp->res.jsonValue["Members@odata.count"] = 0;
+ return;
+ }
+
+ if (ec)
+ {
+ BMCWEB_LOG_DEBUG("DBUS response error {}", ec.value());
+ messages::internalError(asyncResp->res);
+ return;
+ }
+
+ std::vector<std::string> pathNames;
+ for (const auto& object : objects)
+ {
+ sdbusplus::message::object_path path(object);
+ std::string leaf = path.filename();
+ if (leaf.empty())
+ {
+ continue;
+ }
+ pathNames.push_back(leaf);
+ }
+ std::ranges::sort(pathNames, AlphanumLess<std::string>());
+
+ nlohmann::json& members = asyncResp->res.jsonValue["Members"];
+ members = nlohmann::json::array();
+ for (const std::string& leaf : pathNames)
+ {
+ boost::urls::url url = collectionPath;
+ crow::utility::appendUrlPieces(url, leaf);
+ nlohmann::json::object_t member;
+ member["@odata.id"] = std::move(url);
+ members.emplace_back(std::move(member));
+ }
+ asyncResp->res.jsonValue["Members@odata.count"] = members.size();
+}
+
/**
* @brief Populate the collection "Members" from a GetSubTreePaths search of
* inventory
@@ -33,56 +78,15 @@ namespace collection_util
* @return void
*/
inline void
- getCollectionMembers(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
+ getCollectionMembers(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const boost::urls::url& collectionPath,
std::span<const std::string_view> interfaces,
- const char* subtree = "/xyz/openbmc_project/inventory")
+ const std::string& subtree)
{
BMCWEB_LOG_DEBUG("Get collection members for: {}", collectionPath.buffer());
dbus::utility::getSubTreePaths(
subtree, 0, interfaces,
- [collectionPath, asyncResp{std::move(asyncResp)}](
- const boost::system::error_code& ec,
- const dbus::utility::MapperGetSubTreePathsResponse& objects) {
- if (ec == boost::system::errc::io_error)
- {
- asyncResp->res.jsonValue["Members"] = nlohmann::json::array();
- asyncResp->res.jsonValue["Members@odata.count"] = 0;
- return;
- }
-
- if (ec)
- {
- BMCWEB_LOG_DEBUG("DBUS response error {}", ec.value());
- messages::internalError(asyncResp->res);
- return;
- }
-
- std::vector<std::string> pathNames;
- for (const auto& object : objects)
- {
- sdbusplus::message::object_path path(object);
- std::string leaf = path.filename();
- if (leaf.empty())
- {
- continue;
- }
- pathNames.push_back(leaf);
- }
- std::ranges::sort(pathNames, AlphanumLess<std::string>());
-
- nlohmann::json& members = asyncResp->res.jsonValue["Members"];
- members = nlohmann::json::array();
- for (const std::string& leaf : pathNames)
- {
- boost::urls::url url = collectionPath;
- crow::utility::appendUrlPieces(url, leaf);
- nlohmann::json::object_t member;
- member["@odata.id"] = std::move(url);
- members.emplace_back(std::move(member));
- }
- asyncResp->res.jsonValue["Members@odata.count"] = members.size();
- });
+ std::bind_front(handleCollectionMembers, asyncResp, collectionPath));
}
} // namespace collection_util