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 9 #include <memory> 10 #include <optional> 11 #include <string> 12 13 namespace redfish 14 { 15 16 inline void doPowerSubsystemCollection( 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 messages::resourceNotFound(asyncResp->res, "Chassis", chassisId); 24 return; 25 } 26 27 asyncResp->res.addHeader( 28 boost::beast::http::field::link, 29 "</redfish/v1/JsonSchemas/PowerSubsystem/PowerSubsystem.json>; rel=describedby"); 30 asyncResp->res.jsonValue["@odata.type"] = 31 "#PowerSubsystem.v1_1_0.PowerSubsystem"; 32 asyncResp->res.jsonValue["Name"] = "Power Subsystem"; 33 asyncResp->res.jsonValue["Id"] = "PowerSubsystem"; 34 asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces( 35 "redfish", "v1", "Chassis", chassisId, "PowerSubsystem"); 36 asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 37 asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 38 asyncResp->res.jsonValue["PowerSupplies"]["@odata.id"] = 39 crow::utility::urlFromPieces("redfish", "v1", "Chassis", chassisId, 40 "PowerSubsystem", "PowerSupplies"); 41 } 42 43 inline void handlePowerSubsystemCollectionHead( 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/PowerSubsystem/PowerSubsystem.json>; rel=describedby"); 63 }; 64 redfish::chassis_utils::getValidChassisPath(asyncResp, chassisId, 65 std::move(respHandler)); 66 } 67 68 inline void handlePowerSubsystemCollectionGet( 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(doPowerSubsystemCollection, asyncResp, chassisId)); 81 } 82 83 inline void requestRoutesPowerSubsystem(App& app) 84 { 85 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/") 86 .privileges(redfish::privileges::headPowerSubsystem) 87 .methods(boost::beast::http::verb::head)( 88 std::bind_front(handlePowerSubsystemCollectionHead, std::ref(app))); 89 90 BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/PowerSubsystem/") 91 .privileges(redfish::privileges::getPowerSubsystem) 92 .methods(boost::beast::http::verb::get)( 93 std::bind_front(handlePowerSubsystemCollectionGet, std::ref(app))); 94 } 95 96 } // namespace redfish 97