xref: /openbmc/bmcweb/features/redfish/lib/thermal.hpp (revision 5b90429a75c58797ec29ac9a8ed18c2dcd7d4950)
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"
22*5b90429aSEd Tanous #include "utils/json_utils.hpp"
2308777fb0SLewanczyk, Dawid 
241abe55efSEd Tanous namespace redfish
251abe55efSEd Tanous {
2608777fb0SLewanczyk, Dawid 
277e860f15SJohn Edward Broadbent inline void requestRoutesThermal(App& app)
281abe55efSEd Tanous {
297e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
30ed398213SEd Tanous         .privileges(redfish::privileges::getThermal)
317e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
3245ca1b86SEd Tanous             [&app](const crow::Request& req,
337e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
347e860f15SJohn Edward Broadbent                    const std::string& chassisName) {
353ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
3645ca1b86SEd Tanous         {
3745ca1b86SEd Tanous             return;
3845ca1b86SEd Tanous         }
3945ca1b86SEd Tanous 
402474adfaSEd Tanous         auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
4102da7c5aSEd Tanous             asyncResp, chassisName, sensors::dbus::thermalPaths,
42a0ec28b6SAdrian Ambrożewicz             sensors::node::thermal);
432474adfaSEd Tanous 
442474adfaSEd Tanous         // TODO Need to get Chassis Redundancy information.
452474adfaSEd Tanous         getChassisData(sensorAsyncResp);
467e860f15SJohn Edward Broadbent     });
478d1b46d7Szhanghch05 
487e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
49ed398213SEd Tanous         .privileges(redfish::privileges::patchThermal)
507e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::patch)(
5145ca1b86SEd Tanous             [&app](const crow::Request& req,
527e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
537e860f15SJohn Edward Broadbent                    const std::string& chassisName) {
543ba00073SCarson Labrado         if (!redfish::setUpRedfishRoute(app, req, asyncResp))
5545ca1b86SEd Tanous         {
5645ca1b86SEd Tanous             return;
5745ca1b86SEd Tanous         }
5845ca1b86SEd Tanous 
590885057cSEd Tanous         std::optional<std::vector<nlohmann::json::object_t>>
600885057cSEd Tanous             temperatureCollections;
610885057cSEd Tanous         std::optional<std::vector<nlohmann::json::object_t>> fanCollections;
620885057cSEd Tanous         std::unordered_map<std::string, std::vector<nlohmann::json::object_t>>
634bb3dc34SCarol Wang             allCollections;
644bb3dc34SCarol Wang 
658d1b46d7Szhanghch05         auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
6602da7c5aSEd Tanous             asyncResp, chassisName, sensors::dbus::thermalPaths,
67a0ec28b6SAdrian Ambrożewicz             sensors::node::thermal);
684bb3dc34SCarol Wang 
69002d39b4SEd Tanous         if (!json_util::readJsonPatch(req, sensorsAsyncResp->asyncResp->res,
70002d39b4SEd Tanous                                       "Temperatures", temperatureCollections,
71002d39b4SEd Tanous                                       "Fans", fanCollections))
724bb3dc34SCarol Wang         {
734bb3dc34SCarol Wang             return;
744bb3dc34SCarol Wang         }
754bb3dc34SCarol Wang         if (!temperatureCollections && !fanCollections)
764bb3dc34SCarol Wang         {
778d1b46d7Szhanghch05             messages::resourceNotFound(sensorsAsyncResp->asyncResp->res,
78002d39b4SEd Tanous                                        "Thermal", "Temperatures / Voltages");
794bb3dc34SCarol Wang             return;
804bb3dc34SCarol Wang         }
814bb3dc34SCarol Wang         if (temperatureCollections)
824bb3dc34SCarol Wang         {
834bb3dc34SCarol Wang             allCollections.emplace("Temperatures",
844bb3dc34SCarol Wang                                    *std::move(temperatureCollections));
854bb3dc34SCarol Wang         }
864bb3dc34SCarol Wang         if (fanCollections)
874bb3dc34SCarol Wang         {
884bb3dc34SCarol Wang             allCollections.emplace("Fans", *std::move(fanCollections));
894bb3dc34SCarol Wang         }
9080ac4024SBruce Lee         setSensorsOverride(sensorsAsyncResp, allCollections);
917e860f15SJohn Edward Broadbent     });
92413961deSRichard Marian Thomaiyar }
9308777fb0SLewanczyk, Dawid 
9408777fb0SLewanczyk, Dawid } // namespace redfish
95