xref: /openbmc/bmcweb/features/redfish/lib/thermal.hpp (revision 7e860f1550c8686eec42f7a75bc5f2ef51e756ad)
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 
1808777fb0SLewanczyk, Dawid #include "sensors.hpp"
1908777fb0SLewanczyk, Dawid 
20*7e860f15SJohn Edward Broadbent #include <app.hpp>
21*7e860f15SJohn Edward Broadbent 
221abe55efSEd Tanous namespace redfish
231abe55efSEd Tanous {
2408777fb0SLewanczyk, Dawid 
25*7e860f15SJohn Edward Broadbent inline void requestRoutesThermal(App& app)
261abe55efSEd Tanous {
27*7e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
28*7e860f15SJohn Edward Broadbent         .privileges({"Login"})
29*7e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
30*7e860f15SJohn Edward Broadbent             [](const crow::Request&,
31*7e860f15SJohn Edward Broadbent                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
32*7e860f15SJohn Edward Broadbent                const std::string& chassisName) {
33*7e860f15SJohn Edward Broadbent                 auto thermalPaths =
34*7e860f15SJohn Edward Broadbent                     sensors::dbus::paths.find(sensors::node::thermal);
351b1be67fSKrzysztof Grobelny                 if (thermalPaths == sensors::dbus::paths.end())
361b1be67fSKrzysztof Grobelny                 {
371b1be67fSKrzysztof Grobelny                     messages::internalError(asyncResp->res);
381b1be67fSKrzysztof Grobelny                     return;
391b1be67fSKrzysztof Grobelny                 }
401b1be67fSKrzysztof Grobelny 
412474adfaSEd Tanous                 auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
421b1be67fSKrzysztof Grobelny                     asyncResp, chassisName, thermalPaths->second,
43a0ec28b6SAdrian Ambrożewicz                     sensors::node::thermal);
442474adfaSEd Tanous 
452474adfaSEd Tanous                 // TODO Need to get Chassis Redundancy information.
462474adfaSEd Tanous                 getChassisData(sensorAsyncResp);
47*7e860f15SJohn Edward Broadbent             });
488d1b46d7Szhanghch05 
49*7e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
50*7e860f15SJohn Edward Broadbent         .privileges({"ConfigureManager"})
51*7e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::patch)(
52*7e860f15SJohn Edward Broadbent             [](const crow::Request& req,
53*7e860f15SJohn Edward Broadbent                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
54*7e860f15SJohn Edward Broadbent                const std::string& chassisName) {
55*7e860f15SJohn Edward Broadbent                 auto thermalPaths =
56*7e860f15SJohn Edward Broadbent                     sensors::dbus::paths.find(sensors::node::thermal);
571b1be67fSKrzysztof Grobelny                 if (thermalPaths == sensors::dbus::paths.end())
581b1be67fSKrzysztof Grobelny                 {
591b1be67fSKrzysztof Grobelny                     messages::internalError(asyncResp->res);
601b1be67fSKrzysztof Grobelny                     return;
611b1be67fSKrzysztof Grobelny                 }
621b1be67fSKrzysztof Grobelny 
63*7e860f15SJohn Edward Broadbent                 std::optional<std::vector<nlohmann::json>>
64*7e860f15SJohn Edward Broadbent                     temperatureCollections;
654bb3dc34SCarol Wang                 std::optional<std::vector<nlohmann::json>> fanCollections;
664bb3dc34SCarol Wang                 std::unordered_map<std::string, std::vector<nlohmann::json>>
674bb3dc34SCarol Wang                     allCollections;
684bb3dc34SCarol Wang 
698d1b46d7Szhanghch05                 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
701b1be67fSKrzysztof Grobelny                     asyncResp, chassisName, thermalPaths->second,
71a0ec28b6SAdrian Ambrożewicz                     sensors::node::thermal);
724bb3dc34SCarol Wang 
738d1b46d7Szhanghch05                 if (!json_util::readJson(req, sensorsAsyncResp->asyncResp->res,
74*7e860f15SJohn Edward Broadbent                                          "Temperatures", temperatureCollections,
75*7e860f15SJohn Edward Broadbent                                          "Fans", fanCollections))
764bb3dc34SCarol Wang                 {
774bb3dc34SCarol Wang                     return;
784bb3dc34SCarol Wang                 }
794bb3dc34SCarol Wang                 if (!temperatureCollections && !fanCollections)
804bb3dc34SCarol Wang                 {
818d1b46d7Szhanghch05                     messages::resourceNotFound(sensorsAsyncResp->asyncResp->res,
82*7e860f15SJohn Edward Broadbent                                                "Thermal",
83*7e860f15SJohn Edward Broadbent                                                "Temperatures / Voltages");
844bb3dc34SCarol Wang                     return;
854bb3dc34SCarol Wang                 }
864bb3dc34SCarol Wang                 if (temperatureCollections)
874bb3dc34SCarol Wang                 {
884bb3dc34SCarol Wang                     allCollections.emplace("Temperatures",
894bb3dc34SCarol Wang                                            *std::move(temperatureCollections));
904bb3dc34SCarol Wang                 }
914bb3dc34SCarol Wang                 if (fanCollections)
924bb3dc34SCarol Wang                 {
934bb3dc34SCarol Wang                     allCollections.emplace("Fans", *std::move(fanCollections));
944bb3dc34SCarol Wang                 }
958d1b46d7Szhanghch05                 checkAndDoSensorsOverride(sensorsAsyncResp, allCollections);
96*7e860f15SJohn Edward Broadbent             });
97413961deSRichard Marian Thomaiyar }
9808777fb0SLewanczyk, Dawid 
9908777fb0SLewanczyk, Dawid } // namespace redfish
100