summaryrefslogtreecommitdiff
path: root/redfish-core/lib/pcie.hpp
diff options
context:
space:
mode:
authorLakshmi Yadlapati <lakshmiy@us.ibm.com>2023-03-11 01:19:46 +0300
committerEd Tanous <ed@tanous.net>2023-03-15 23:31:35 +0300
commitb38fa2abdb1f5f732d1a759cb13209682f7fd4df (patch)
tree64a33597c03e6ba22605e3903a01df4a6986e0ff /redfish-core/lib/pcie.hpp
parentd9f466b3b92f242343dcdecae83b40579f92c506 (diff)
downloadbmcweb-b38fa2abdb1f5f732d1a759cb13209682f7fd4df.tar.xz
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 <lakshmiy@us.ibm.com>
Diffstat (limited to 'redfish-core/lib/pcie.hpp')
-rw-r--r--redfish-core/lib/pcie.hpp59
1 files changed, 35 insertions, 24 deletions
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 <boost/system/linux_error.hpp>
@@ -75,6 +76,39 @@ static inline void
});
}
+static inline void handlePCIeDeviceCollectionGet(
+ crow::App& app, const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& 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,
+ "</redfish/v1/JsonSchemas/PCIeDeviceCollection/"
+ "PCIeDeviceCollection.json>; 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<std::string_view, 1> 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/<str>/PCIeDevices/")
.privileges(redfish::privileges::getPCIeDeviceCollection)
.methods(boost::beast::http::verb::get)(
- [&app](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& 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<pcie_device::PCIeTypes>