xref: /openbmc/bmcweb/features/redfish/lib/thermal.hpp (revision 3ccb3adb9a14783f6bef601506de9f8bcae22d51)
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 
18*3ccb3adbSEd Tanous #include "app.hpp"
19*3ccb3adbSEd Tanous #include "query.hpp"
20*3ccb3adbSEd 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 
58002d39b4SEd Tanous         std::optional<std::vector<nlohmann::json>> temperatureCollections;
594bb3dc34SCarol Wang         std::optional<std::vector<nlohmann::json>> fanCollections;
604bb3dc34SCarol Wang         std::unordered_map<std::string, std::vector<nlohmann::json>>
614bb3dc34SCarol Wang             allCollections;
624bb3dc34SCarol Wang 
638d1b46d7Szhanghch05         auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
6402da7c5aSEd Tanous             asyncResp, chassisName, sensors::dbus::thermalPaths,
65a0ec28b6SAdrian Ambrożewicz             sensors::node::thermal);
664bb3dc34SCarol Wang 
67002d39b4SEd Tanous         if (!json_util::readJsonPatch(req, sensorsAsyncResp->asyncResp->res,
68002d39b4SEd Tanous                                       "Temperatures", temperatureCollections,
69002d39b4SEd Tanous                                       "Fans", fanCollections))
704bb3dc34SCarol Wang         {
714bb3dc34SCarol Wang             return;
724bb3dc34SCarol Wang         }
734bb3dc34SCarol Wang         if (!temperatureCollections && !fanCollections)
744bb3dc34SCarol Wang         {
758d1b46d7Szhanghch05             messages::resourceNotFound(sensorsAsyncResp->asyncResp->res,
76002d39b4SEd Tanous                                        "Thermal", "Temperatures / Voltages");
774bb3dc34SCarol Wang             return;
784bb3dc34SCarol Wang         }
794bb3dc34SCarol Wang         if (temperatureCollections)
804bb3dc34SCarol Wang         {
814bb3dc34SCarol Wang             allCollections.emplace("Temperatures",
824bb3dc34SCarol Wang                                    *std::move(temperatureCollections));
834bb3dc34SCarol Wang         }
844bb3dc34SCarol Wang         if (fanCollections)
854bb3dc34SCarol Wang         {
864bb3dc34SCarol Wang             allCollections.emplace("Fans", *std::move(fanCollections));
874bb3dc34SCarol Wang         }
8880ac4024SBruce Lee         setSensorsOverride(sensorsAsyncResp, allCollections);
897e860f15SJohn Edward Broadbent         });
90413961deSRichard Marian Thomaiyar }
9108777fb0SLewanczyk, Dawid 
9208777fb0SLewanczyk, Dawid } // namespace redfish
93