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