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