summaryrefslogtreecommitdiff
path: root/redfish-core/lib/network_protocol.hpp
diff options
context:
space:
mode:
authorzhanghch05 <zhanghch05@inspur.com>2021-04-01 06:18:24 +0300
committerzhanghch05 <zhanghch05@inspur.com>2021-04-08 04:01:21 +0300
commit8d1b46d7f8d39db2ba048f9e9007106ca3a28c9b (patch)
tree821fcb9b383fdf3db22db77e154cd7f57606d402 /redfish-core/lib/network_protocol.hpp
parentdab0604af234bdd5010407031a01343d6c242edf (diff)
downloadbmcweb-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/network_protocol.hpp')
-rw-r--r--redfish-core/lib/network_protocol.hpp48
1 files changed, 26 insertions, 22 deletions
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index c8f63d1a8b..491204eab0 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -141,11 +141,9 @@ class NetworkProtocol : 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
{
- std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
-
getData(asyncResp);
}
@@ -161,7 +159,8 @@ class NetworkProtocol : public Node
return hostName;
}
- void getNTPProtocolEnabled(const std::shared_ptr<AsyncResp>& asyncResp)
+ void getNTPProtocolEnabled(
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code errorCode,
@@ -190,7 +189,7 @@ class NetworkProtocol : public Node
"xyz.openbmc_project.Time.Synchronization", "TimeSyncMethod");
}
- void getData(const std::shared_ptr<AsyncResp>& asyncResp)
+ void getData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
asyncResp->res.jsonValue["@odata.type"] =
"#ManagerNetworkProtocol.v1_5_0.ManagerNetworkProtocol";
@@ -355,8 +354,9 @@ class NetworkProtocol : public Node
}
#ifdef BMCWEB_ALLOW_DEPRECATED_HOSTNAME_PATCH
- void handleHostnamePatch(const std::string& hostName,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ void
+ handleHostnamePatch(const std::string& hostName,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code ec) {
@@ -374,8 +374,9 @@ class NetworkProtocol : public Node
}
#endif
- void handleNTPProtocolEnabled(const bool& ntpEnabled,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ void handleNTPProtocolEnabled(
+ const bool& ntpEnabled,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
std::string timeSyncMethod;
if (ntpEnabled)
@@ -403,8 +404,9 @@ class NetworkProtocol : public Node
std::variant<std::string>{timeSyncMethod});
}
- void handleNTPServersPatch(const std::vector<std::string>& ntpServers,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ void handleNTPServersPatch(
+ const std::vector<std::string>& ntpServers,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code ec) {
@@ -420,8 +422,9 @@ class NetworkProtocol : public Node
std::variant<std::vector<std::string>>{ntpServers});
}
- void handleIpmiProtocolEnabled(const bool ipmiProtocolEnabled,
- const std::shared_ptr<AsyncResp>& asyncResp)
+ void handleIpmiProtocolEnabled(
+ const bool ipmiProtocolEnabled,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
crow::connections::systemBus->async_method_call(
[ipmiProtocolEnabled,
@@ -478,21 +481,22 @@ class NetworkProtocol : public Node
"xyz.openbmc_project.Control.Service.Attributes"});
}
- 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
{
- std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
+
std::optional<std::string> newHostName;
std::optional<nlohmann::json> ntp;
std::optional<nlohmann::json> ipmi;
- if (!json_util::readJson(req, res, "NTP", ntp, "HostName", newHostName,
- "IPMI", ipmi))
+ if (!json_util::readJson(req, asyncResp->res, "NTP", ntp, "HostName",
+ newHostName, "IPMI", ipmi))
{
return;
}
- res.result(boost::beast::http::status::no_content);
+ asyncResp->res.result(boost::beast::http::status::no_content);
if (newHostName)
{
#ifdef BMCWEB_ALLOW_DEPRECATED_HOSTNAME_PATCH
@@ -506,8 +510,8 @@ class NetworkProtocol : public Node
{
std::optional<std::vector<std::string>> ntpServers;
std::optional<bool> ntpEnabled;
- if (!json_util::readJson(*ntp, res, "NTPServers", ntpServers,
- "ProtocolEnabled", ntpEnabled))
+ if (!json_util::readJson(*ntp, asyncResp->res, "NTPServers",
+ ntpServers, "ProtocolEnabled", ntpEnabled))
{
return;
}
@@ -531,7 +535,7 @@ class NetworkProtocol : public Node
if (ipmi)
{
std::optional<bool> ipmiProtocolEnabled;
- if (!json_util::readJson(*ipmi, res, "ProtocolEnabled",
+ if (!json_util::readJson(*ipmi, asyncResp->res, "ProtocolEnabled",
ipmiProtocolEnabled))
{
return;