diff options
author | zhanghch05 <zhanghch05@inspur.com> | 2021-04-01 06:18:24 +0300 |
---|---|---|
committer | zhanghch05 <zhanghch05@inspur.com> | 2021-04-08 04:01:21 +0300 |
commit | 8d1b46d7f8d39db2ba048f9e9007106ca3a28c9b (patch) | |
tree | 821fcb9b383fdf3db22db77e154cd7f57606d402 /redfish-core/lib/event_service.hpp | |
parent | dab0604af234bdd5010407031a01343d6c242edf (diff) | |
download | bmcweb-8d1b46d7f8d39db2ba048f9e9007106ca3a28c9b.tar.xz |
Using AsyncResp everywhere
Get the core using AsyncResp everywhere, and not have each individual handler
creating its own object.We can call app.handle() without fear of the response
getting ended after the first tree is done populating.
Don't use res.end() anymore.
Tested:
1. Validator passed.
Signed-off-by: zhanghaicheng <zhanghch05@inspur.com>
Change-Id: I867367ce4a0caf8c4b3f4e07e06c11feed0782e8
Diffstat (limited to 'redfish-core/lib/event_service.hpp')
-rw-r--r-- | redfish-core/lib/event_service.hpp | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/redfish-core/lib/event_service.hpp b/redfish-core/lib/event_service.hpp index be6f04df2f..ad567ef135 100644 --- a/redfish-core/lib/event_service.hpp +++ b/redfish-core/lib/event_service.hpp @@ -51,11 +51,11 @@ class EventService : public Node } private: - void doGet(crow::Response& res, const crow::Request&, - const std::vector<std::string>&) override + void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const crow::Request&, const std::vector<std::string>&) override { - auto asyncResp = std::make_shared<AsyncResp>(res); - res.jsonValue = { + + asyncResp->res.jsonValue = { {"@odata.type", "#EventService.v1_5_0.EventService"}, {"Id", "EventService"}, {"Name", "Event Service"}, @@ -89,18 +89,19 @@ class EventService : public Node supportedSSEFilters; } - void doPatch(crow::Response& res, const crow::Request& req, + void doPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const crow::Request& req, const std::vector<std::string>&) override { - auto asyncResp = std::make_shared<AsyncResp>(res); std::optional<bool> serviceEnabled; std::optional<uint32_t> retryAttemps; std::optional<uint32_t> retryInterval; - if (!json_util::readJson(req, res, "ServiceEnabled", serviceEnabled, - "DeliveryRetryAttempts", retryAttemps, - "DeliveryRetryIntervalSeconds", retryInterval)) + if (!json_util::readJson(req, asyncResp->res, "ServiceEnabled", + serviceEnabled, "DeliveryRetryAttempts", + retryAttemps, "DeliveryRetryIntervalSeconds", + retryInterval)) { return; } @@ -165,12 +166,11 @@ class SubmitTestEvent : public Node } private: - void doPost(crow::Response& res, const crow::Request&, - const std::vector<std::string>&) override + void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const crow::Request&, const std::vector<std::string>&) override { EventServiceManager::getInstance().sendTestEventLog(); - res.result(boost::beast::http::status::no_content); - res.end(); + asyncResp->res.result(boost::beast::http::status::no_content); } }; @@ -190,12 +190,11 @@ class EventDestinationCollection : public Node } private: - void doGet(crow::Response& res, const crow::Request&, - const std::vector<std::string>&) override + void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const crow::Request&, const std::vector<std::string>&) override { - auto asyncResp = std::make_shared<AsyncResp>(res); - res.jsonValue = { + asyncResp->res.jsonValue = { {"@odata.type", "#EventDestinationCollection.EventDestinationCollection"}, {"@odata.id", "/redfish/v1/EventService/Subscriptions"}, @@ -216,10 +215,10 @@ class EventDestinationCollection : public Node } } - void doPost(crow::Response& res, const crow::Request& req, + void doPost(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const crow::Request& req, const std::vector<std::string>&) override { - auto asyncResp = std::make_shared<AsyncResp>(res); if (EventServiceManager::getInstance().getNumberOfSubscriptions() >= maxNoOfSubscriptions) @@ -240,7 +239,7 @@ class EventDestinationCollection : public Node std::optional<std::vector<nlohmann::json>> mrdJsonArray; if (!json_util::readJson( - req, res, "Destination", destUrl, "Context", context, + req, asyncResp->res, "Destination", destUrl, "Context", context, "Protocol", protocol, "SubscriptionType", subscriptionType, "EventFormatType", eventFormatType2, "HttpHeaders", headers, "RegistryPrefixes", regPrefixes, "MessageIds", msgIds, @@ -474,10 +473,11 @@ class EventDestination : public Node } private: - void doGet(crow::Response& res, const crow::Request&, + void doGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const crow::Request&, const std::vector<std::string>& params) override { - auto asyncResp = std::make_shared<AsyncResp>(res); + if (params.size() != 1) { messages::internalError(asyncResp->res); @@ -488,13 +488,12 @@ class EventDestination : public Node EventServiceManager::getInstance().getSubscription(params[0]); if (subValue == nullptr) { - res.result(boost::beast::http::status::not_found); - res.end(); + asyncResp->res.result(boost::beast::http::status::not_found); return; } const std::string& id = params[0]; - res.jsonValue = { + asyncResp->res.jsonValue = { {"@odata.type", "#EventDestination.v1_7_0.EventDestination"}, {"Protocol", "Redfish"}}; asyncResp->res.jsonValue["@odata.id"] = @@ -522,10 +521,11 @@ class EventDestination : public Node asyncResp->res.jsonValue["MetricReportDefinitions"] = mrdJsonArray; } - void doPatch(crow::Response& res, const crow::Request& req, + void doPatch(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const crow::Request& req, const std::vector<std::string>& params) override { - auto asyncResp = std::make_shared<AsyncResp>(res); + if (params.size() != 1) { messages::internalError(asyncResp->res); @@ -536,8 +536,7 @@ class EventDestination : public Node EventServiceManager::getInstance().getSubscription(params[0]); if (subValue == nullptr) { - res.result(boost::beast::http::status::not_found); - res.end(); + asyncResp->res.result(boost::beast::http::status::not_found); return; } @@ -545,7 +544,7 @@ class EventDestination : public Node std::optional<std::string> retryPolicy; std::optional<std::vector<nlohmann::json>> headers; - if (!json_util::readJson(req, res, "Context", context, + if (!json_util::readJson(req, asyncResp->res, "Context", context, "DeliveryRetryPolicy", retryPolicy, "HttpHeaders", headers)) { @@ -579,10 +578,10 @@ class EventDestination : public Node EventServiceManager::getInstance().updateSubscriptionData(); } - void doDelete(crow::Response& res, const crow::Request&, + void doDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, + const crow::Request&, const std::vector<std::string>& params) override { - auto asyncResp = std::make_shared<AsyncResp>(res); if (params.size() != 1) { @@ -592,8 +591,7 @@ class EventDestination : public Node if (!EventServiceManager::getInstance().isSubscriptionExist(params[0])) { - res.result(boost::beast::http::status::not_found); - res.end(); + asyncResp->res.result(boost::beast::http::status::not_found); return; } EventServiceManager::getInstance().deleteSubscription(params[0]); |