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
diff --git a/redfish-core/lib/thermal.hpp b/redfish-core/lib/thermal.hpp
index 00acdf9..af31831 100644
--- a/redfish-core/lib/thermal.hpp
+++ b/redfish-core/lib/thermal.hpp
@@ -37,30 +37,33 @@
}
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
{
if (params.size() != 1)
{
- messages::internalError(res);
- res.end();
+ messages::internalError(asyncResp->res);
+
return;
}
const std::string& chassisName = params[0];
auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
- res, chassisName, sensors::dbus::paths.at(sensors::node::thermal),
+ asyncResp, chassisName,
+ sensors::dbus::paths.at(sensors::node::thermal),
sensors::node::thermal);
// TODO Need to get Chassis Redundancy information.
getChassisData(sensorAsyncResp);
}
- 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
{
if (params.size() != 1)
{
- res.end();
- messages::internalError(res);
+
+ messages::internalError(asyncResp->res);
return;
}
@@ -70,20 +73,21 @@
std::unordered_map<std::string, std::vector<nlohmann::json>>
allCollections;
- auto asyncResp = std::make_shared<SensorsAsyncResp>(
- res, chassisName, sensors::dbus::paths.at(sensors::node::thermal),
+ auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
+ asyncResp, chassisName,
+ sensors::dbus::paths.at(sensors::node::thermal),
sensors::node::thermal);
- if (!json_util::readJson(req, asyncResp->res, "Temperatures",
- temperatureCollections, "Fans",
+ if (!json_util::readJson(req, sensorsAsyncResp->asyncResp->res,
+ "Temperatures", temperatureCollections, "Fans",
fanCollections))
{
return;
}
if (!temperatureCollections && !fanCollections)
{
- messages::resourceNotFound(asyncResp->res, "Thermal",
- "Temperatures / Voltages");
+ messages::resourceNotFound(sensorsAsyncResp->asyncResp->res,
+ "Thermal", "Temperatures / Voltages");
return;
}
if (temperatureCollections)
@@ -96,7 +100,7 @@
allCollections.emplace("Fans", *std::move(fanCollections));
}
- checkAndDoSensorsOverride(asyncResp, allCollections);
+ checkAndDoSensorsOverride(sensorsAsyncResp, allCollections);
}
};