From b38fa2abdb1f5f732d1a759cb13209682f7fd4df Mon Sep 17 00:00:00 2001 From: Lakshmi Yadlapati Date: Fri, 10 Mar 2023 16:19:46 -0600 Subject: Move PCIeDeviceCollection to separate method Similar to the code we've been building elsewhere, move PCIeDeviceCollection system to a separate method, and use getCollectionMembers. Tested: Validator passed ``` { "@odata.id": "/redfish/v1/Systems/system/PCIeDevices", "@odata.type": "#PCIeDeviceCollection.PCIeDeviceCollection", "Description": "Collection of PCIe Devices", "Members": [ { "@odata.id": "/redfish/v1/Systems/system/PCIeDevices/dp0_drive2" }, { "@odata.id": "/redfish/v1/Systems/system/PCIeDevices/dp0_drive3" }, { "@odata.id": "/redfish/v1/Systems/system/PCIeDevices/pcie_card0" }, { "@odata.id": "/redfish/v1/Systems/system/PCIeDevices/pcie_card1" }, ..... ..... ], "Members@odata.count": 20, "Name": "PCIe Device Collection" } ``` Change-Id: Ib8d468f9163e49fc3767dd92b81e70b4d48e8867 Signed-off-by: Lakshmi Yadlapati --- redfish-core/lib/pcie.hpp | 59 ++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 24 deletions(-) (limited to 'redfish-core/lib/pcie.hpp') diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp index c3b7546ef2..97f1e24525 100644 --- a/redfish-core/lib/pcie.hpp +++ b/redfish-core/lib/pcie.hpp @@ -21,6 +21,7 @@ #include "generated/enums/pcie_device.hpp" #include "query.hpp" #include "registries/privilege_registry.hpp" +#include "utils/collection.hpp" #include "utils/dbus_utils.hpp" #include @@ -75,6 +76,39 @@ static inline void }); } +static inline void handlePCIeDeviceCollectionGet( + crow::App& app, const crow::Request& req, + const std::shared_ptr& aResp, + const std::string& systemName) +{ + if (!redfish::setUpRedfishRoute(app, req, aResp)) + { + return; + } + if (systemName != "system") + { + messages::resourceNotFound(aResp->res, "ComputerSystem", systemName); + return; + } + aResp->res.addHeader(boost::beast::http::field::link, + "; rel=describedby"); + aResp->res.jsonValue["@odata.type"] = + "#PCIeDeviceCollection.PCIeDeviceCollection"; + aResp->res.jsonValue["@odata.id"] = + "/redfish/v1/Systems/system/PCIeDevices"; + aResp->res.jsonValue["Name"] = "PCIe Device Collection"; + aResp->res.jsonValue["Description"] = "Collection of PCIe Devices"; + aResp->res.jsonValue["Members"] = nlohmann::json::array(); + aResp->res.jsonValue["Members@odata.count"] = 0; + + constexpr std::array interfaces{ + "xyz.openbmc_project.Inventory.Item.PCIeDevice"}; + collection_util::getCollectionMembers( + aResp, boost::urls::url("/redfish/v1/Systems/system/PCIeDevices"), + interfaces); +} + inline void requestRoutesSystemPCIeDeviceCollection(App& app) { /** @@ -83,30 +117,7 @@ inline void requestRoutesSystemPCIeDeviceCollection(App& app) BMCWEB_ROUTE(app, "/redfish/v1/Systems//PCIeDevices/") .privileges(redfish::privileges::getPCIeDeviceCollection) .methods(boost::beast::http::verb::get)( - [&app](const crow::Request& req, - const std::shared_ptr& asyncResp, - const std::string& systemName) { - if (!redfish::setUpRedfishRoute(app, req, asyncResp)) - { - return; - } - if (systemName != "system") - { - messages::resourceNotFound(asyncResp->res, "ComputerSystem", - systemName); - return; - } - - asyncResp->res.jsonValue["@odata.type"] = - "#PCIeDeviceCollection.PCIeDeviceCollection"; - asyncResp->res.jsonValue["@odata.id"] = - "/redfish/v1/Systems/system/PCIeDevices"; - asyncResp->res.jsonValue["Name"] = "PCIe Device Collection"; - asyncResp->res.jsonValue["Description"] = "Collection of PCIe Devices"; - asyncResp->res.jsonValue["Members"] = nlohmann::json::array(); - asyncResp->res.jsonValue["Members@odata.count"] = 0; - getPCIeDeviceList(asyncResp, "Members"); - }); + std::bind_front(handlePCIeDeviceCollectionGet, std::ref(app))); } inline std::optional -- cgit v1.2.3