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