xref: /openbmc/bmcweb/features/redfish/lib/thermal.hpp (revision c95636082b63d020e0f63545f5d87e2eb6a05c52)
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"
225b90429aSEd Tanous #include "utils/json_utils.hpp"
23*c9563608SJanet Adkins #include "utils/sensor_utils.hpp"
2408777fb0SLewanczyk, Dawid 
251abe55efSEd Tanous namespace redfish
261abe55efSEd Tanous {
2708777fb0SLewanczyk, Dawid 
287e860f15SJohn Edward Broadbent inline void requestRoutesThermal(App& app)
291abe55efSEd Tanous {
307e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
31ed398213SEd Tanous         .privileges(redfish::privileges::getThermal)
327e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::get)(
3345ca1b86SEd Tanous             [&app](const crow::Request& req,
347e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
357e860f15SJohn Edward Broadbent                    const std::string& chassisName) {
363ba00073SCarson Labrado                 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
3745ca1b86SEd Tanous                 {
3845ca1b86SEd Tanous                     return;
3945ca1b86SEd Tanous                 }
4045ca1b86SEd Tanous 
412474adfaSEd Tanous                 auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
4202da7c5aSEd Tanous                     asyncResp, chassisName, sensors::dbus::thermalPaths,
43*c9563608SJanet Adkins                     sensor_utils::thermalNode);
442474adfaSEd Tanous 
452474adfaSEd Tanous                 // TODO Need to get Chassis Redundancy information.
462474adfaSEd Tanous                 getChassisData(sensorAsyncResp);
477e860f15SJohn Edward Broadbent             });
488d1b46d7Szhanghch05 
497e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/")
50ed398213SEd Tanous         .privileges(redfish::privileges::patchThermal)
517e860f15SJohn Edward Broadbent         .methods(boost::beast::http::verb::patch)(
5245ca1b86SEd Tanous             [&app](const crow::Request& req,
537e860f15SJohn Edward Broadbent                    const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
547e860f15SJohn Edward Broadbent                    const std::string& chassisName) {
553ba00073SCarson Labrado                 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
5645ca1b86SEd Tanous                 {
5745ca1b86SEd Tanous                     return;
5845ca1b86SEd Tanous                 }
5945ca1b86SEd Tanous 
600885057cSEd Tanous                 std::optional<std::vector<nlohmann::json::object_t>>
610885057cSEd Tanous                     temperatureCollections;
62bd79bce8SPatrick Williams                 std::optional<std::vector<nlohmann::json::object_t>>
63bd79bce8SPatrick Williams                     fanCollections;
64bd79bce8SPatrick Williams                 std::unordered_map<std::string,
65bd79bce8SPatrick Williams                                    std::vector<nlohmann::json::object_t>>
664bb3dc34SCarol Wang                     allCollections;
674bb3dc34SCarol Wang 
688d1b46d7Szhanghch05                 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>(
6902da7c5aSEd Tanous                     asyncResp, chassisName, sensors::dbus::thermalPaths,
70*c9563608SJanet Adkins                     sensor_utils::thermalNode);
714bb3dc34SCarol Wang 
72bd79bce8SPatrick Williams                 if (!json_util::readJsonPatch(
73bd79bce8SPatrick Williams                         req, sensorsAsyncResp->asyncResp->res, "Temperatures",
74bd79bce8SPatrick Williams                         temperatureCollections, "Fans", fanCollections))
754bb3dc34SCarol Wang                 {
764bb3dc34SCarol Wang                     return;
774bb3dc34SCarol Wang                 }
784bb3dc34SCarol Wang                 if (!temperatureCollections && !fanCollections)
794bb3dc34SCarol Wang                 {
808d1b46d7Szhanghch05                     messages::resourceNotFound(sensorsAsyncResp->asyncResp->res,
81bd79bce8SPatrick Williams                                                "Thermal",
82bd79bce8SPatrick Williams                                                "Temperatures / Voltages");
834bb3dc34SCarol Wang                     return;
844bb3dc34SCarol Wang                 }
854bb3dc34SCarol Wang                 if (temperatureCollections)
864bb3dc34SCarol Wang                 {
874bb3dc34SCarol Wang                     allCollections.emplace("Temperatures",
884bb3dc34SCarol Wang                                            *std::move(temperatureCollections));
894bb3dc34SCarol Wang                 }
904bb3dc34SCarol Wang                 if (fanCollections)
914bb3dc34SCarol Wang                 {
924bb3dc34SCarol Wang                     allCollections.emplace("Fans", *std::move(fanCollections));
934bb3dc34SCarol Wang                 }
9480ac4024SBruce Lee                 setSensorsOverride(sensorsAsyncResp, allCollections);
957e860f15SJohn Edward Broadbent             });
96413961deSRichard Marian Thomaiyar }
9708777fb0SLewanczyk, Dawid 
9808777fb0SLewanczyk, Dawid } // namespace redfish
99