diff options
author | John Edward Broadbent <jebr@google.com> | 2021-07-13 00:06:30 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2021-09-29 21:54:56 +0300 |
commit | 26bd9b57dbabf170a29a7fe151c77f5f01103434 (patch) | |
tree | 1d6fc56c52cf49807aa22e18667214fe54999d3f /redfish-core/lib/telemetry_service.hpp | |
parent | 6e8c18f0a7c49e77d044cc51bda215ba60a8e4b7 (diff) | |
download | bmcweb-26bd9b57dbabf170a29a7fe151c77f5f01103434.tar.xz |
move to free function: Telemetry
This change will allow for unit testing of the free function.
There are no changes to logic in the response, only the organization.
Signed-off-by: John Edward Broadbent <jebr@google.com>
Change-Id: I3b40163d9aad8564a28a0468847edfce2d96683f
Diffstat (limited to 'redfish-core/lib/telemetry_service.hpp')
-rw-r--r-- | redfish-core/lib/telemetry_service.hpp | 122 |
1 files changed, 61 insertions, 61 deletions
diff --git a/redfish-core/lib/telemetry_service.hpp b/redfish-core/lib/telemetry_service.hpp index ad86d5cd45..8ecc5916ca 100644 --- a/redfish-core/lib/telemetry_service.hpp +++ b/redfish-core/lib/telemetry_service.hpp @@ -10,74 +10,74 @@ namespace redfish { -inline void requestRoutesTelemetryService(App& app) +inline void handleTelemetryServiceGet( + const crow::Request&, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { - BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/") - .privileges(redfish::privileges::getTelemetryService) - .methods( - boost::beast::http::verb:: - get)([](const crow::Request&, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { - asyncResp->res.jsonValue["@odata.type"] = - "#TelemetryService.v1_2_1.TelemetryService"; - asyncResp->res.jsonValue["@odata.id"] = - "/redfish/v1/TelemetryService"; - asyncResp->res.jsonValue["Id"] = "TelemetryService"; - asyncResp->res.jsonValue["Name"] = "Telemetry Service"; + asyncResp->res.jsonValue["@odata.type"] = + "#TelemetryService.v1_2_1.TelemetryService"; + asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/TelemetryService"; + asyncResp->res.jsonValue["Id"] = "TelemetryService"; + asyncResp->res.jsonValue["Name"] = "Telemetry Service"; - asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] = - "/redfish/v1/TelemetryService/MetricReportDefinitions"; - asyncResp->res.jsonValue["MetricReports"]["@odata.id"] = - "/redfish/v1/TelemetryService/MetricReports"; + asyncResp->res.jsonValue["MetricReportDefinitions"]["@odata.id"] = + "/redfish/v1/TelemetryService/MetricReportDefinitions"; + asyncResp->res.jsonValue["MetricReports"]["@odata.id"] = + "/redfish/v1/TelemetryService/MetricReports"; - crow::connections::systemBus->async_method_call( - [asyncResp]( - const boost::system::error_code ec, + crow::connections::systemBus->async_method_call( + [asyncResp](const boost::system::error_code ec, const std::vector<std::pair< std::string, std::variant<uint32_t, uint64_t>>>& ret) { - if (ec == boost::system::errc::host_unreachable) - { - asyncResp->res.jsonValue["Status"]["State"] = "Absent"; - return; - } - if (ec) - { - BMCWEB_LOG_ERROR << "respHandler DBus error " << ec; - messages::internalError(asyncResp->res); - return; - } + if (ec == boost::system::errc::host_unreachable) + { + asyncResp->res.jsonValue["Status"]["State"] = "Absent"; + return; + } + if (ec) + { + BMCWEB_LOG_ERROR << "respHandler DBus error " << ec; + messages::internalError(asyncResp->res); + return; + } - asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; + asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; - const size_t* maxReports = nullptr; - const uint64_t* minInterval = nullptr; - for (const auto& [key, var] : ret) - { - if (key == "MaxReports") - { - maxReports = std::get_if<size_t>(&var); - } - else if (key == "MinInterval") - { - minInterval = std::get_if<uint64_t>(&var); - } - } - if (!maxReports || !minInterval) - { - BMCWEB_LOG_ERROR - << "Property type mismatch or property is missing"; - messages::internalError(asyncResp->res); - return; - } + const size_t* maxReports = nullptr; + const uint64_t* minInterval = nullptr; + for (const auto& [key, var] : ret) + { + if (key == "MaxReports") + { + maxReports = std::get_if<size_t>(&var); + } + else if (key == "MinInterval") + { + minInterval = std::get_if<uint64_t>(&var); + } + } + if (!maxReports || !minInterval) + { + BMCWEB_LOG_ERROR + << "Property type mismatch or property is missing"; + messages::internalError(asyncResp->res); + return; + } + + asyncResp->res.jsonValue["MaxReports"] = *maxReports; + asyncResp->res.jsonValue["MinCollectionInterval"] = + time_utils::toDurationString(std::chrono::milliseconds( + static_cast<time_t>(*minInterval))); + }, + telemetry::service, "/xyz/openbmc_project/Telemetry/Reports", + "org.freedesktop.DBus.Properties", "GetAll", + "xyz.openbmc_project.Telemetry.ReportManager"); +} - asyncResp->res.jsonValue["MaxReports"] = *maxReports; - asyncResp->res.jsonValue["MinCollectionInterval"] = - time_utils::toDurationString(std::chrono::milliseconds( - static_cast<time_t>(*minInterval))); - }, - telemetry::service, "/xyz/openbmc_project/Telemetry/Reports", - "org.freedesktop.DBus.Properties", "GetAll", - "xyz.openbmc_project.Telemetry.ReportManager"); - }); +inline void requestRoutesTelemetryService(App& app) +{ + BMCWEB_ROUTE(app, "/redfish/v1/TelemetryService/") + .privileges(redfish::privileges::getTelemetryService) + .methods(boost::beast::http::verb::get)(handleTelemetryServiceGet); } + } // namespace redfish |