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",
54                                            chassisId);
55                 return;
56             }
57             asyncResp->res.addHeader(
58                 boost::beast::http::field::link,
59                 "</redfish/v1/JsonSchemas/ThermalMetrics/ThermalMetrics.json>; rel=describedby");
60         });
61 }
62 
63 inline void
handleThermalMetricsGet(App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & chassisId)64     handleThermalMetricsGet(App& app, const crow::Request& req,
65                             const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
66                             const std::string& chassisId)
67 {
68     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
69     {
70         return;
71     }
72 
73     redfish::chassis_utils::getValidChassisPath(
74         asyncResp, chassisId,
75         std::bind_front(doThermalMetrics, asyncResp, chassisId));
76 }
77 
requestRoutesThermalMetrics(App & app)78 inline void requestRoutesThermalMetrics(App& app)
79 {
80     BMCWEB_ROUTE(app,
81                  "/redfish/v1/Chassis/<str>/ThermalSubsystem/ThermalMetrics/")
82         .privileges(redfish::privileges::headThermalMetrics)
83         .methods(boost::beast::http::verb::head)(
84             std::bind_front(handleThermalMetricsHead, std::ref(app)));
85 
86     BMCWEB_ROUTE(app,
87                  "/redfish/v1/Chassis/<str>/ThermalSubsystem/ThermalMetrics/")
88         .privileges(redfish::privileges::getThermalMetrics)
89         .methods(boost::beast::http::verb::get)(
90             std::bind_front(handleThermalMetricsGet, std::ref(app)));
91 }
92 } // namespace redfish
93