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