Expose AsyncResp shared_ptr when handling response
For Redfish Aggregation, we need a common point to check the D-Bus
for satellite configs. If they are available then we perform the
aggregation operations. The functions in query.hpp are used by all
endpoints making them the logical location. The aggregation code
requires a shared_ptr to the AsyncResp so these functions need to be
able to supply that.
This patch is broken out of a future patch for routing Redfish
Aggregation requests
https://gerrit.openbmc.org/c/openbmc/bmcweb/+/53310
The follow commands can be used to perform most of the replacements:
find . -type f | xargs sed -i 's/setUpRedfishRoute(app, req, asyncResp->res/setUpRedfishRoute(app, req, asyncResp/g'
find . -type f | xargs sed -i 's/setUpRedfishRouteWithDelegation(app, req, asyncResp->res/setUpRedfishRouteWithDelegation(app, req, asyncResp/g'
Signed-off-by: Carson Labrado <clabrado@google.com>
Change-Id: I4f4f9f22cdcfb14a3bd94b9a8f3d64aae34e57bc
diff --git a/redfish-core/include/query.hpp b/redfish-core/include/query.hpp
index 1f7774f..4c7e2f4 100644
--- a/redfish-core/include/query.hpp
+++ b/redfish-core/include/query.hpp
@@ -12,7 +12,8 @@
// handled by redfish-core/lib codes, then default query parameter handler won't
// process these parameters.
[[nodiscard]] inline bool setUpRedfishRouteWithDelegation(
- crow::App& app, const crow::Request& req, crow::Response& res,
+ crow::App& app, const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
query_param::Query& delegated,
const query_param::QueryCapabilities& queryCapabilities)
{
@@ -25,14 +26,14 @@
std::string_view odataHeader = req.getHeaderValue("OData-Version");
if (!odataHeader.empty() && odataHeader != "4.0")
{
- messages::preconditionFailed(res);
+ messages::preconditionFailed(asyncResp->res);
return false;
}
- res.addHeader("OData-Version", "4.0");
+ asyncResp->res.addHeader("OData-Version", "4.0");
std::optional<query_param::Query> queryOpt =
- query_param::parseParameters(req.urlView.params(), res);
+ query_param::parseParameters(req.urlView.params(), asyncResp->res);
if (queryOpt == std::nullopt)
{
return false;
@@ -46,8 +47,8 @@
delegated = query_param::delegate(queryCapabilities, *queryOpt);
std::function<void(crow::Response&)> handler =
- res.releaseCompleteRequestHandler();
- res.setCompleteRequestHandler(
+ asyncResp->res.releaseCompleteRequestHandler();
+ asyncResp->res.setCompleteRequestHandler(
[&app, handler(std::move(handler)),
query{*queryOpt}](crow::Response& res) mutable {
processAllParams(app, query, handler, res);
@@ -56,13 +57,13 @@
}
// Sets up the Redfish Route. All parameters are handled by the default handler.
-[[nodiscard]] inline bool setUpRedfishRoute(crow::App& app,
- const crow::Request& req,
- crow::Response& res)
+[[nodiscard]] inline bool
+ setUpRedfishRoute(crow::App& app, const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
// This route |delegated| is never used
query_param::Query delegated;
- return setUpRedfishRouteWithDelegation(app, req, res, delegated,
+ return setUpRedfishRouteWithDelegation(app, req, asyncResp, delegated,
query_param::QueryCapabilities{});
}
} // namespace redfish