12973963eSXiaochao Ma #pragma once 22973963eSXiaochao Ma 32973963eSXiaochao Ma #include "app.hpp" 4ce05f6c4SNan Zhou #include "logging.hpp" 52973963eSXiaochao Ma #include "query.hpp" 62973963eSXiaochao Ma #include "registries/privilege_registry.hpp" 72973963eSXiaochao Ma #include "utils/chassis_utils.hpp" 82973963eSXiaochao Ma #include "utils/json_utils.hpp" 92973963eSXiaochao Ma 10ce05f6c4SNan Zhou #include <optional> 11ce05f6c4SNan Zhou #include <string> 12ce05f6c4SNan Zhou 132973963eSXiaochao Ma namespace redfish 142973963eSXiaochao Ma { 152973963eSXiaochao Ma 162973963eSXiaochao Ma inline void doThermalSubsystemCollection( 172973963eSXiaochao Ma const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 182973963eSXiaochao Ma const std::string& chassisId, 192973963eSXiaochao Ma const std::optional<std::string>& validChassisPath) 202973963eSXiaochao Ma { 212973963eSXiaochao Ma if (!validChassisPath) 222973963eSXiaochao Ma { 23*a7405d5fSGunnar Mills BMCWEB_LOG_WARNING << "Not a valid chassis ID" << chassisId; 242973963eSXiaochao Ma messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 252973963eSXiaochao Ma return; 262973963eSXiaochao Ma } 271aee751cSGeorge Liu 281aee751cSGeorge Liu asyncResp->res.addHeader( 291aee751cSGeorge Liu boost::beast::http::field::link, 301aee751cSGeorge Liu "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby"); 312973963eSXiaochao Ma asyncResp->res.jsonValue["@odata.type"] = 322973963eSXiaochao Ma "#ThermalSubsystem.v1_0_0.ThermalSubsystem"; 332973963eSXiaochao Ma asyncResp->res.jsonValue["Name"] = "Thermal Subsystem"; 342973963eSXiaochao Ma asyncResp->res.jsonValue["Id"] = "ThermalSubsystem"; 352973963eSXiaochao Ma 362973963eSXiaochao Ma asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces( 372973963eSXiaochao Ma "redfish", "v1", "Chassis", chassisId, "ThermalSubsystem"); 382973963eSXiaochao Ma 392973963eSXiaochao Ma asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 402973963eSXiaochao Ma asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 412973963eSXiaochao Ma } 422973963eSXiaochao Ma 431aee751cSGeorge Liu inline void handleThermalSubsystemCollectionHead( 442973963eSXiaochao Ma App& app, const crow::Request& req, 452973963eSXiaochao Ma const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 461aee751cSGeorge Liu const std::string& chassisId) 472973963eSXiaochao Ma { 482973963eSXiaochao Ma if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 492973963eSXiaochao Ma { 502973963eSXiaochao Ma return; 512973963eSXiaochao Ma } 521aee751cSGeorge Liu 531aee751cSGeorge Liu auto respHandler = [asyncResp, chassisId]( 541aee751cSGeorge Liu const std::optional<std::string>& validChassisPath) { 551aee751cSGeorge Liu if (!validChassisPath) 561aee751cSGeorge Liu { 571aee751cSGeorge Liu messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 581aee751cSGeorge Liu return; 591aee751cSGeorge Liu } 601aee751cSGeorge Liu asyncResp->res.addHeader( 611aee751cSGeorge Liu boost::beast::http::field::link, 621aee751cSGeorge Liu "</redfish/v1/JsonSchemas/ThermalSubsystem/ThermalSubsystem.json>; rel=describedby"); 631aee751cSGeorge Liu }; 641aee751cSGeorge Liu redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId, 651aee751cSGeorge Liu std::bind_front(respHandler)); 661aee751cSGeorge Liu } 671aee751cSGeorge Liu 681aee751cSGeorge Liu inline void handleThermalSubsystemCollectionGet( 691aee751cSGeorge Liu App& app, const crow::Request& req, 701aee751cSGeorge Liu const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 711aee751cSGeorge Liu const std::string& chassisId) 721aee751cSGeorge Liu { 731aee751cSGeorge Liu if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 741aee751cSGeorge Liu { 751aee751cSGeorge Liu return; 761aee751cSGeorge Liu } 772973963eSXiaochao Ma 782973963eSXiaochao Ma redfish::chassis_utils::getValidChassisPath( 792973963eSXiaochao Ma asyncResp, chassisId, 802973963eSXiaochao Ma std::bind_front(doThermalSubsystemCollection, asyncResp, chassisId)); 812973963eSXiaochao Ma } 822973963eSXiaochao Ma 832973963eSXiaochao Ma inline void requestRoutesThermalSubsystem(App& app) 842973963eSXiaochao Ma { 852973963eSXiaochao Ma BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/") 861aee751cSGeorge Liu .privileges(redfish::privileges::headThermalSubsystem) 871aee751cSGeorge Liu .methods(boost::beast::http::verb::head)(std::bind_front( 881aee751cSGeorge Liu handleThermalSubsystemCollectionHead, std::ref(app))); 891aee751cSGeorge Liu 901aee751cSGeorge Liu BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ThermalSubsystem/") 912973963eSXiaochao Ma .privileges(redfish::privileges::getThermalSubsystem) 922973963eSXiaochao Ma .methods(boost::beast::http::verb::get)(std::bind_front( 932973963eSXiaochao Ma handleThermalSubsystemCollectionGet, std::ref(app))); 942973963eSXiaochao Ma } 952973963eSXiaochao Ma 962973963eSXiaochao Ma } // namespace redfish 97