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/metric_report_definition.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/metric_report_definition.hpp')
-rw-r--r-- | redfish-core/lib/metric_report_definition.hpp | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/redfish-core/lib/metric_report_definition.hpp b/redfish-core/lib/metric_report_definition.hpp index fcbc99c1ef..a1231b14a8 100644 --- a/redfish-core/lib/metric_report_definition.hpp +++ b/redfish-core/lib/metric_report_definition.hpp @@ -21,7 +21,7 @@ using ReadingParameters = std::string, std::string>>; inline void fillReportDefinition( - const std::shared_ptr<AsyncResp>& asyncResp, const std::string& id, + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& id, const std::vector< std::pair<std::string, std::variant<std::string, bool, uint64_t, ReadingParameters>>>& ret) @@ -217,7 +217,7 @@ inline bool getUserParameters(crow::Response& res, const crow::Request& req, } inline bool getChassisSensorNode( - const std::shared_ptr<AsyncResp>& asyncResp, + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::vector<std::pair<std::string, std::vector<std::string>>>& metrics, boost::container::flat_set<std::pair<std::string, std::string>>& matched) @@ -257,8 +257,10 @@ inline bool getChassisSensorNode( class AddReport { public: - AddReport(AddReportArgs argsIn, std::shared_ptr<AsyncResp> asyncResp) : - asyncResp{std::move(asyncResp)}, args{std::move(argsIn)} + AddReport(AddReportArgs argsIn, + const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) : + asyncResp(asyncResp), + args{std::move(argsIn)} {} ~AddReport() { @@ -291,20 +293,19 @@ class AddReport readingParams.emplace_back(dbusPath, "SINGLE", id, uri); } } - + const std::shared_ptr<bmcweb::AsyncResp> aResp = asyncResp; crow::connections::systemBus->async_method_call( - [asyncResp = std::move(asyncResp), name = args.name, - uriToDbus = std::move(uriToDbus)]( + [aResp, name = args.name, uriToDbus = std::move(uriToDbus)]( const boost::system::error_code ec, const std::string&) { if (ec == boost::system::errc::file_exists) { messages::resourceAlreadyExists( - asyncResp->res, "MetricReportDefinition", "Id", name); + aResp->res, "MetricReportDefinition", "Id", name); return; } if (ec == boost::system::errc::too_many_files_open) { - messages::createLimitReachedForResource(asyncResp->res); + messages::createLimitReachedForResource(aResp->res); return; } if (ec == boost::system::errc::argument_list_too_long) @@ -315,17 +316,17 @@ class AddReport metricProperties.emplace_back(uri); } messages::propertyValueIncorrect( - asyncResp->res, metricProperties, "MetricProperties"); + aResp->res, metricProperties, "MetricProperties"); return; } if (ec) { - messages::internalError(asyncResp->res); + messages::internalError(aResp->res); BMCWEB_LOG_ERROR << "respHandler DBus error " << ec; return; } - messages::created(asyncResp->res); + messages::created(aResp->res); }, telemetry::service, "/xyz/openbmc_project/Telemetry/Reports", "xyz.openbmc_project.Telemetry.ReportManager", "AddReport", @@ -340,7 +341,7 @@ class AddReport } private: - std::shared_ptr<AsyncResp> asyncResp; + const std::shared_ptr<bmcweb::AsyncResp> asyncResp; AddReportArgs args; boost::container::flat_map<std::string, std::string> uriToDbus{}; }; @@ -362,26 +363,26 @@ class MetricReportDefinitionCollection : 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 { - res.jsonValue["@odata.type"] = "#MetricReportDefinitionCollection." - "MetricReportDefinitionCollection"; - res.jsonValue["@odata.id"] = + asyncResp->res.jsonValue["@odata.type"] = + "#MetricReportDefinitionCollection." + "MetricReportDefinitionCollection"; + asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService/MetricReportDefinitions"; - res.jsonValue["Name"] = "Metric Definition Collection"; + asyncResp->res.jsonValue["Name"] = "Metric Definition Collection"; - auto asyncResp = std::make_shared<AsyncResp>(res); telemetry::getReportCollection(asyncResp, telemetry::metricReportDefinitionUri); } - 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); telemetry::AddReportArgs args; - if (!telemetry::getUserParameters(res, req, args)) + if (!telemetry::getUserParameters(asyncResp->res, req, args)) { return; } @@ -434,10 +435,10 @@ class MetricReportDefinition : 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) { @@ -474,10 +475,10 @@ class MetricReportDefinition : public Node telemetry::reportInterface); } - 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) { messages::internalError(asyncResp->res); |