summaryrefslogtreecommitdiff
path: root/redfish-core/lib/chassis.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/chassis.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/chassis.hpp')
-rw-r--r--redfish-core/lib/chassis.hpp73
1 files changed, 36 insertions, 37 deletions
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
index 01d6081899..88f9fd7dc8 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -34,7 +34,7 @@ namespace redfish
*
* @return None.
*/
-inline void getChassisState(std::shared_ptr<AsyncResp> aResp)
+inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> aResp)
{
crow::connections::systemBus->async_method_call(
[aResp{std::move(aResp)}](
@@ -86,7 +86,7 @@ using ManagedObjectsType = std::vector<std::pair<
using PropertiesType = boost::container::flat_map<std::string, VariantType>;
-inline void getIntrusionByService(std::shared_ptr<AsyncResp> aResp,
+inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> aResp,
const std::string& service,
const std::string& objPath)
{
@@ -121,7 +121,7 @@ inline void getIntrusionByService(std::shared_ptr<AsyncResp> aResp,
/**
* Retrieves physical security properties over dbus
*/
-inline void getPhysicalSecurityData(std::shared_ptr<AsyncResp> aResp)
+inline void getPhysicalSecurityData(std::shared_ptr<bmcweb::AsyncResp> aResp)
{
crow::connections::systemBus->async_method_call(
[aResp{std::move(aResp)}](
@@ -176,14 +176,13 @@ class ChassisCollection : public Node
/**
* Functions triggers appropriate requests on DBus
*/
- 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
{
- res.jsonValue["@odata.type"] = "#ChassisCollection.ChassisCollection";
- res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
- res.jsonValue["Name"] = "Chassis Collection";
-
- auto asyncResp = std::make_shared<AsyncResp>(res);
+ asyncResp->res.jsonValue["@odata.type"] =
+ "#ChassisCollection.ChassisCollection";
+ asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis";
+ asyncResp->res.jsonValue["Name"] = "Chassis Collection";
collection_util::getCollectionMembers(
asyncResp, "/redfish/v1/Chassis",
@@ -213,7 +212,8 @@ class Chassis : public Node
/**
* Functions triggers appropriate requests on DBus
*/
- 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
{
const std::array<const char*, 2> interfaces = {
@@ -224,13 +224,11 @@ class Chassis : public Node
// impossible.
if (params.size() != 1)
{
- messages::internalError(res);
- res.end();
+ messages::internalError(asyncResp->res);
return;
}
const std::string& chassisId = params[0];
- auto asyncResp = std::make_shared<AsyncResp>(res);
crow::connections::systemBus->async_method_call(
[asyncResp, chassisId(std::string(chassisId))](
const boost::system::error_code ec,
@@ -427,19 +425,19 @@ class Chassis : public Node
getPhysicalSecurityData(asyncResp);
}
- 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
{
std::optional<bool> locationIndicatorActive;
std::optional<std::string> indicatorLed;
- auto asyncResp = std::make_shared<AsyncResp>(res);
if (params.size() != 1)
{
return;
}
- if (!json_util::readJson(req, res, "LocationIndicatorActive",
+ if (!json_util::readJson(req, asyncResp->res, "LocationIndicatorActive",
locationIndicatorActive, "IndicatorLED",
indicatorLed))
{
@@ -453,9 +451,9 @@ class Chassis : public Node
}
if (indicatorLed)
{
- res.addHeader(boost::beast::http::field::warning,
- "299 - \"IndicatorLED is deprecated. Use "
- "LocationIndicatorActive instead.\"");
+ asyncResp->res.addHeader(boost::beast::http::field::warning,
+ "299 - \"IndicatorLED is deprecated. Use "
+ "LocationIndicatorActive instead.\"");
}
const std::array<const char*, 2> interfaces = {
@@ -552,7 +550,8 @@ class Chassis : public Node
}
};
-inline void doChassisPowerCycle(const std::shared_ptr<AsyncResp>& asyncResp)
+inline void
+ doChassisPowerCycle(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
const char* busName = "xyz.openbmc_project.ObjectMapper";
const char* path = "/xyz/openbmc_project/object_mapper";
@@ -631,13 +630,13 @@ class ChassisResetAction : public Node
* Function handles POST method request.
* Analyzes POST body before sending Reset request data to D-Bus.
*/
- 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
{
BMCWEB_LOG_DEBUG << "Post Chassis Reset.";
std::string resetType;
- auto asyncResp = std::make_shared<AsyncResp>(res);
if (!json_util::readJson(req, asyncResp->res, "ResetType", resetType))
{
@@ -683,28 +682,28 @@ class ChassisResetActionInfo : public Node
/**
* Functions triggers appropriate requests on DBus
*/
- 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
{
if (params.size() != 1)
{
- messages::internalError(res);
- res.end();
+ messages::internalError(asyncResp->res);
return;
}
const std::string& chassisId = params[0];
- res.jsonValue = {{"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"},
- {"@odata.id", "/redfish/v1/Chassis/" + chassisId +
- "/ResetActionInfo"},
- {"Name", "Reset Action Info"},
- {"Id", "ResetActionInfo"},
- {"Parameters",
- {{{"Name", "ResetType"},
- {"Required", true},
- {"DataType", "String"},
- {"AllowableValues", {"PowerCycle"}}}}}};
- res.end();
+ asyncResp->res.jsonValue = {
+ {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"},
+ {"@odata.id",
+ "/redfish/v1/Chassis/" + chassisId + "/ResetActionInfo"},
+ {"Name", "Reset Action Info"},
+ {"Id", "ResetActionInfo"},
+ {"Parameters",
+ {{{"Name", "ResetType"},
+ {"Required", true},
+ {"DataType", "String"},
+ {"AllowableValues", {"PowerCycle"}}}}}};
}
};