redfish/lib: simplify memory.hpp
This change simplify the routes and route setup for memory functions.
Change-Id: I13d66fbda48672032bb4a037743ad6f074783620
Signed-off-by: Christopher Meis <christopher.meis@9elements.com>
diff --git a/redfish-core/lib/memory.hpp b/redfish-core/lib/memory.hpp
index 79ccdac..bdd31a0 100644
--- a/redfish-core/lib/memory.hpp
+++ b/redfish-core/lib/memory.hpp
@@ -959,50 +959,42 @@
getDimmData(asyncResp, dimmId);
}
-inline void requestRoutesMemoryCollection(App& app)
+inline void handleMemoryCollectionGet(
+ App& app, const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& systemName)
{
- /**
- * Functions triggers appropriate requests on DBus
- */
- BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/")
- .privileges(redfish::privileges::getMemoryCollection)
- .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 constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
- {
- // Option currently returns no systems. TBD
- messages::resourceNotFound(asyncResp->res, "ComputerSystem",
- systemName);
- return;
- }
- if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
- {
- messages::resourceNotFound(asyncResp->res, "ComputerSystem",
- systemName);
- return;
- }
+ if (!redfish::setUpRedfishRoute(app, req, asyncResp))
+ {
+ return;
+ }
+ if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
+ {
+ // Option currently returns no systems. TBD
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemName);
+ return;
+ }
+ if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
+ {
+ messages::resourceNotFound(asyncResp->res, "ComputerSystem",
+ systemName);
+ return;
+ }
- asyncResp->res.jsonValue["@odata.type"] =
- "#MemoryCollection.MemoryCollection";
- asyncResp->res.jsonValue["Name"] = "Memory Module Collection";
- asyncResp->res.jsonValue["@odata.id"] =
- boost::urls::format("/redfish/v1/Systems/{}/Memory",
- BMCWEB_REDFISH_SYSTEM_URI_NAME);
+ asyncResp->res.jsonValue["@odata.type"] =
+ "#MemoryCollection.MemoryCollection";
+ asyncResp->res.jsonValue["Name"] = "Memory Module Collection";
+ asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
+ "/redfish/v1/Systems/{}/Memory", BMCWEB_REDFISH_SYSTEM_URI_NAME);
- constexpr std::array<std::string_view, 1> interfaces{
- "xyz.openbmc_project.Inventory.Item.Dimm"};
- collection_util::getCollectionMembers(
- asyncResp,
- boost::urls::format("/redfish/v1/Systems/{}/Memory",
- BMCWEB_REDFISH_SYSTEM_URI_NAME),
- interfaces, "/xyz/openbmc_project/inventory");
- });
+ constexpr std::array<std::string_view, 1> interfaces{
+ "xyz.openbmc_project.Inventory.Item.Dimm"};
+ collection_util::getCollectionMembers(
+ asyncResp,
+ boost::urls::format("/redfish/v1/Systems/{}/Memory",
+ BMCWEB_REDFISH_SYSTEM_URI_NAME),
+ interfaces, "/xyz/openbmc_project/inventory");
}
inline void requestRoutesMemory(App& app)
@@ -1010,6 +1002,11 @@
/**
* Functions triggers appropriate requests on DBus
*/
+ BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/")
+ .privileges(redfish::privileges::getMemoryCollection)
+ .methods(boost::beast::http::verb::get)(
+ std::bind_front(handleMemoryCollectionGet, std::ref(app)));
+
BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Memory/<str>/")
.privileges(redfish::privileges::getMemory)
.methods(boost::beast::http::verb::get)(
diff --git a/redfish-core/src/redfish.cpp b/redfish-core/src/redfish.cpp
index 770e630..67bd25e 100644
--- a/redfish-core/src/redfish.cpp
+++ b/redfish-core/src/redfish.cpp
@@ -159,7 +159,6 @@
requestRoutesProcessor(app);
requestRoutesOperatingConfig(app);
- requestRoutesMemoryCollection(app);
requestRoutesMemory(app);
requestRoutesSystems(app);