1*40e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0 2*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation 408777fb0SLewanczyk, Dawid #pragma once 508777fb0SLewanczyk, Dawid 63ccb3adbSEd Tanous #include "app.hpp" 73ccb3adbSEd Tanous #include "query.hpp" 83ccb3adbSEd Tanous #include "registries/privilege_registry.hpp" 908777fb0SLewanczyk, Dawid #include "sensors.hpp" 105b90429aSEd Tanous #include "utils/json_utils.hpp" 11c9563608SJanet Adkins #include "utils/sensor_utils.hpp" 1208777fb0SLewanczyk, Dawid 131abe55efSEd Tanous namespace redfish 141abe55efSEd Tanous { 1508777fb0SLewanczyk, Dawid 167e860f15SJohn Edward Broadbent inline void requestRoutesThermal(App& app) 171abe55efSEd Tanous { 187e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/") 19ed398213SEd Tanous .privileges(redfish::privileges::getThermal) 207e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 2145ca1b86SEd Tanous [&app](const crow::Request& req, 227e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 237e860f15SJohn Edward Broadbent const std::string& chassisName) { 243ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 2545ca1b86SEd Tanous { 2645ca1b86SEd Tanous return; 2745ca1b86SEd Tanous } 2845ca1b86SEd Tanous 292474adfaSEd Tanous auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( 3002da7c5aSEd Tanous asyncResp, chassisName, sensors::dbus::thermalPaths, 310c728b42SJanet Adkins sensor_utils::chassisSubNodeToString( 320c728b42SJanet Adkins sensor_utils::ChassisSubNode::thermalNode)); 332474adfaSEd Tanous 342474adfaSEd Tanous // TODO Need to get Chassis Redundancy information. 352474adfaSEd Tanous getChassisData(sensorAsyncResp); 367e860f15SJohn Edward Broadbent }); 378d1b46d7Szhanghch05 387e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/") 39ed398213SEd Tanous .privileges(redfish::privileges::patchThermal) 407e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 4145ca1b86SEd Tanous [&app](const crow::Request& req, 427e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 437e860f15SJohn Edward Broadbent const std::string& chassisName) { 443ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 4545ca1b86SEd Tanous { 4645ca1b86SEd Tanous return; 4745ca1b86SEd Tanous } 4845ca1b86SEd Tanous 490885057cSEd Tanous std::optional<std::vector<nlohmann::json::object_t>> 500885057cSEd Tanous temperatureCollections; 51bd79bce8SPatrick Williams std::optional<std::vector<nlohmann::json::object_t>> 52bd79bce8SPatrick Williams fanCollections; 53bd79bce8SPatrick Williams std::unordered_map<std::string, 54bd79bce8SPatrick Williams std::vector<nlohmann::json::object_t>> 554bb3dc34SCarol Wang allCollections; 564bb3dc34SCarol Wang 578d1b46d7Szhanghch05 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>( 5802da7c5aSEd Tanous asyncResp, chassisName, sensors::dbus::thermalPaths, 590c728b42SJanet Adkins sensor_utils::chassisSubNodeToString( 600c728b42SJanet Adkins sensor_utils::ChassisSubNode::thermalNode)); 614bb3dc34SCarol Wang 62afc474aeSMyung Bae if (!json_util::readJsonPatch( // 63afc474aeSMyung Bae req, sensorsAsyncResp->asyncResp->res, // 64afc474aeSMyung Bae "Fans", fanCollections, // 65afc474aeSMyung Bae "Temperatures", temperatureCollections // 66afc474aeSMyung Bae )) 674bb3dc34SCarol Wang { 684bb3dc34SCarol Wang return; 694bb3dc34SCarol Wang } 704bb3dc34SCarol Wang if (!temperatureCollections && !fanCollections) 714bb3dc34SCarol Wang { 728d1b46d7Szhanghch05 messages::resourceNotFound(sensorsAsyncResp->asyncResp->res, 73bd79bce8SPatrick Williams "Thermal", 74bd79bce8SPatrick Williams "Temperatures / Voltages"); 754bb3dc34SCarol Wang return; 764bb3dc34SCarol Wang } 774bb3dc34SCarol Wang if (temperatureCollections) 784bb3dc34SCarol Wang { 794bb3dc34SCarol Wang allCollections.emplace("Temperatures", 804bb3dc34SCarol Wang *std::move(temperatureCollections)); 814bb3dc34SCarol Wang } 824bb3dc34SCarol Wang if (fanCollections) 834bb3dc34SCarol Wang { 844bb3dc34SCarol Wang allCollections.emplace("Fans", *std::move(fanCollections)); 854bb3dc34SCarol Wang } 8680ac4024SBruce Lee setSensorsOverride(sensorsAsyncResp, allCollections); 877e860f15SJohn Edward Broadbent }); 88413961deSRichard Marian Thomaiyar } 8908777fb0SLewanczyk, Dawid 9008777fb0SLewanczyk, Dawid } // namespace redfish 91