1 #pragma once
2 
3 #include "app.hpp"
4 #include "query.hpp"
5 #include "registries/privilege_registry.hpp"
6 #include "utils/chassis_utils.hpp"
7 
8 #include <functional>
9 #include <memory>
10 #include <optional>
11 #include <string>
12 
13 namespace redfish
14 {
15 inline void
doThermalMetrics(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & chassisId,const std::optional<std::string> & validChassisPath)16     doThermalMetrics(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
17                      const std::string& chassisId,
18                      const std::optional<std::string>& validChassisPath)
19 {
20     if (!validChassisPath)
21     {
22         messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
23         return;
24     }
25 
26     asyncResp->res.addHeader(
27         boost::beast::http::field::link,
28         "</redfish/v1/JsonSchemas/ThermalMetrics/ThermalMetrics.json>; rel=describedby");
29     asyncResp->res.jsonValue["@odata.type"] =
30         "#ThermalMetrics.v1_0_1.ThermalMetrics";
31     asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
32         "/redfish/v1/Chassis/{}/ThermalSubsystem/ThermalMetrics", chassisId);
33     asyncResp->res.jsonValue["Id"] = "ThermalMetrics";
34     asyncResp->res.jsonValue["Name"] = "Thermal Metrics";
35 }
36 
handleThermalMetricsHead(App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & chassisId)37 inline void handleThermalMetricsHead(
38     App& app, const crow::Request& req,
39     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
40     const std::string& chassisId)
41 {
42     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
43     {
44         return;
45     }
46 
47     redfish::chassis_utils::getValidChassisPath(
48         asyncResp, chassisId,
49         [asyncResp,
50          chassisId](const std::optional<std::string>& validChassisPath) {
51         if (!validChassisPath)
52         {
53             messages::resourceNotFound(asyncResp->res, "Chassis", chassisId);
54             return;
55         }
56         asyncResp->res.addHeader(
57             boost::beast::http::field::link,
58             "</redfish/v1/JsonSchemas/ThermalMetrics/ThermalMetrics.json>; rel=describedby");
59     });
60 }
61 
62 inline void
handleThermalMetricsGet(App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & chassisId)63     handleThermalMetricsGet(App& app, const crow::Request& req,
64                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
65                             const std::string& chassisId)
66 {
67     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
68     {
69         return;
70     }
71 
72     redfish::chassis_utils::getValidChassisPath(
73         asyncResp, chassisId,
74         std::bind_front(doThermalMetrics, asyncResp, chassisId));
75 }
76 
requestRoutesThermalMetrics(App & app)77 inline void requestRoutesThermalMetrics(App& app)
78 {
79     BMCWEB_ROUTE(app,
80                  "/redfish/v1/Chassis/<str>/ThermalSubsystem/ThermalMetrics/")
81         .privileges(redfish::privileges::headThermalMetrics)
82         .methods(boost::beast::http::verb::head)(
83             std::bind_front(handleThermalMetricsHead, std::ref(app)));
84 
85     BMCWEB_ROUTE(app,
86                  "/redfish/v1/Chassis/<str>/ThermalSubsystem/ThermalMetrics/")
87         .privileges(redfish::privileges::getThermalMetrics)
88         .methods(boost::beast::http::verb::get)(
89             std::bind_front(handleThermalMetricsGet, std::ref(app)));
90 }
91 } // namespace redfish
92