xref: /openbmc/bmcweb/features/redfish/lib/thermal.hpp (revision 0885057cf9e0a155eecaa8c15cb1076eaa432057)
108777fb0SLewanczyk, Dawid /*
208777fb0SLewanczyk, Dawid // Copyright (c) 2018 Intel Corporation
308777fb0SLewanczyk, Dawid //
408777fb0SLewanczyk, Dawid // Licensed under the Apache License, Version 2.0 (the "License");
508777fb0SLewanczyk, Dawid // you may not use this file except in compliance with the License.
608777fb0SLewanczyk, Dawid // You may obtain a copy of the License at
708777fb0SLewanczyk, Dawid //
808777fb0SLewanczyk, Dawid //      http://www.apache.org/licenses/LICENSE-2.0
908777fb0SLewanczyk, Dawid //
1008777fb0SLewanczyk, Dawid // Unless required by applicable law or agreed to in writing, software
1108777fb0SLewanczyk, Dawid // distributed under the License is distributed on an "AS IS" BASIS,
1208777fb0SLewanczyk, Dawid // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1308777fb0SLewanczyk, Dawid // See the License for the specific language governing permissions and
1408777fb0SLewanczyk, Dawid // limitations under the License.
1508777fb0SLewanczyk, Dawid */
1608777fb0SLewanczyk, Dawid #pragma once
1708777fb0SLewanczyk, Dawid 
183ccb3adbSEd Tanous #include "app.hpp"
193ccb3adbSEd Tanous #include "query.hpp"
203ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
2108777fb0SLewanczyk, Dawid #include "sensors.hpp"
2208777fb0SLewanczyk, Dawid 
231abe55efSEd Tanous namespace redfish
241abe55efSEd Tanous {
2508777fb0SLewanczyk, Dawid 
267e860f15SJohn Edward Broadbent inline void requestRoutesThermal(App& app)
271abe55efSEd Tanous {
287e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
29ed398213SEd Tanous         .privileges(redfish::privileges::getThermal)
307e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
3145ca1b86SEd Tanous             [&app](const crow::Request& req,
327e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
337e860f15SJohn Edward Broadbent                    const std::string& chassisName) {
343ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
3545ca1b86SEd Tanous         {
3645ca1b86SEd Tanous             return;
3745ca1b86SEd Tanous         }
3845ca1b86SEd Tanous 
392474adfaSEd Tanous         auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
4002da7c5aSEd Tanous             asyncResp, chassisName, sensors::dbus::thermalPaths,
41a0ec28b6SAdrian Ambrożewicz             sensors::node::thermal);
422474adfaSEd Tanous 
432474adfaSEd Tanous         // TODO Need to get Chassis Redundancy information.
442474adfaSEd Tanous         getChassisData(sensorAsyncResp);
457e860f15SJohn Edward Broadbent     });
468d1b46d7Szhanghch05 
477e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
48ed398213SEd Tanous         .privileges(redfish::privileges::patchThermal)
497e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::patch)(
5045ca1b86SEd Tanous             [&app](const crow::Request& req,
517e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
527e860f15SJohn Edward Broadbent                    const std::string& chassisName) {
533ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
5445ca1b86SEd Tanous         {
5545ca1b86SEd Tanous             return;
5645ca1b86SEd Tanous         }
5745ca1b86SEd Tanous 
58*0885057cSEd Tanous         std::optional<std::vector<nlohmann::json::object_t>>
59*0885057cSEd Tanous             temperatureCollections;
60*0885057cSEd Tanous         std::optional<std::vector<nlohmann::json::object_t>> fanCollections;
61*0885057cSEd Tanous         std::unordered_map<std::string, std::vector<nlohmann::json::object_t>>
624bb3dc34SCarol Wang             allCollections;
634bb3dc34SCarol Wang 
648d1b46d7Szhanghch05         auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
6502da7c5aSEd Tanous             asyncResp, chassisName, sensors::dbus::thermalPaths,
66a0ec28b6SAdrian Ambrożewicz             sensors::node::thermal);
674bb3dc34SCarol Wang 
68002d39b4SEd Tanous         if (!json_util::readJsonPatch(req, sensorsAsyncResp->asyncResp->res,
69002d39b4SEd Tanous                                       "Temperatures", temperatureCollections,
70002d39b4SEd Tanous                                       "Fans", fanCollections))
714bb3dc34SCarol Wang         {
724bb3dc34SCarol Wang             return;
734bb3dc34SCarol Wang         }
744bb3dc34SCarol Wang         if (!temperatureCollections && !fanCollections)
754bb3dc34SCarol Wang         {
768d1b46d7Szhanghch05             messages::resourceNotFound(sensorsAsyncResp->asyncResp->res,
77002d39b4SEd Tanous                                        "Thermal", "Temperatures / Voltages");
784bb3dc34SCarol Wang             return;
794bb3dc34SCarol Wang         }
804bb3dc34SCarol Wang         if (temperatureCollections)
814bb3dc34SCarol Wang         {
824bb3dc34SCarol Wang             allCollections.emplace("Temperatures",
834bb3dc34SCarol Wang                                    *std::move(temperatureCollections));
844bb3dc34SCarol Wang         }
854bb3dc34SCarol Wang         if (fanCollections)
864bb3dc34SCarol Wang         {
874bb3dc34SCarol Wang             allCollections.emplace("Fans", *std::move(fanCollections));
884bb3dc34SCarol Wang         }
8980ac4024SBruce Lee         setSensorsOverride(sensorsAsyncResp, allCollections);
907e860f15SJohn Edward Broadbent     });
91413961deSRichard Marian Thomaiyar }
9208777fb0SLewanczyk, Dawid 
9308777fb0SLewanczyk, Dawid } // namespace redfish
94