xref: /openbmc/bmcweb/features/redfish/lib/thermal.hpp (revision 4bb3dc346522b5f1e3bf6241c64238837caff5d2)
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 "node.hpp"
1908777fb0SLewanczyk, Dawid #include "sensors.hpp"
2008777fb0SLewanczyk, Dawid 
211abe55efSEd Tanous namespace redfish
221abe55efSEd Tanous {
2308777fb0SLewanczyk, Dawid 
241abe55efSEd Tanous class Thermal : public Node
251abe55efSEd Tanous {
2608777fb0SLewanczyk, Dawid   public:
271abe55efSEd Tanous     Thermal(CrowApp& app) :
281abe55efSEd Tanous         Node((app), "/redfish/v1/Chassis/<str>/Thermal/", std::string())
291abe55efSEd Tanous     {
30e0d918bcSEd Tanous         entityPrivileges = {
31e0d918bcSEd Tanous             {boost::beast::http::verb::get, {{"Login"}}},
32e0d918bcSEd Tanous             {boost::beast::http::verb::head, {{"Login"}}},
336f4fd479SRichard Marian Thomaiyar             {boost::beast::http::verb::patch, {{"ConfigureComponents"}}},
34e0d918bcSEd Tanous             {boost::beast::http::verb::put, {{"ConfigureManager"}}},
35e0d918bcSEd Tanous             {boost::beast::http::verb::delete_, {{"ConfigureManager"}}},
36e0d918bcSEd Tanous             {boost::beast::http::verb::post, {{"ConfigureManager"}}}};
3708777fb0SLewanczyk, Dawid     }
3808777fb0SLewanczyk, Dawid 
3908777fb0SLewanczyk, Dawid   private:
4085e1424fSEd Tanous     std::vector<const char*> typeList = {
418afa1b9bSRichard Marian Thomaiyar         "/xyz/openbmc_project/sensors/fan_tach",
42413961deSRichard Marian Thomaiyar         "/xyz/openbmc_project/sensors/temperature",
43413961deSRichard Marian Thomaiyar         "/xyz/openbmc_project/sensors/fan_pwm"};
4455c7b7a2SEd Tanous     void doGet(crow::Response& res, const crow::Request& req,
451abe55efSEd Tanous                const std::vector<std::string>& params) override
461abe55efSEd Tanous     {
471abe55efSEd Tanous         if (params.size() != 1)
481abe55efSEd Tanous         {
49f12894f8SJason M. Bills             messages::internalError(res);
5008777fb0SLewanczyk, Dawid             res.end();
5108777fb0SLewanczyk, Dawid             return;
5208777fb0SLewanczyk, Dawid         }
5355c7b7a2SEd Tanous         const std::string& chassisName = params[0];
542474adfaSEd Tanous         auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>(
55413961deSRichard Marian Thomaiyar             res, chassisName, typeList, "Thermal");
562474adfaSEd Tanous 
572474adfaSEd Tanous         // TODO Need to get Chassis Redundancy information.
582474adfaSEd Tanous         getChassisData(sensorAsyncResp);
5908777fb0SLewanczyk, Dawid     }
60413961deSRichard Marian Thomaiyar     void doPatch(crow::Response& res, const crow::Request& req,
61413961deSRichard Marian Thomaiyar                  const std::vector<std::string>& params) override
62413961deSRichard Marian Thomaiyar     {
63*4bb3dc34SCarol Wang         if (params.size() != 1)
64*4bb3dc34SCarol Wang         {
65*4bb3dc34SCarol Wang             res.end();
66*4bb3dc34SCarol Wang             messages::internalError(res);
67*4bb3dc34SCarol Wang             return;
68*4bb3dc34SCarol Wang         }
69*4bb3dc34SCarol Wang 
70*4bb3dc34SCarol Wang         const std::string& chassisName = params[0];
71*4bb3dc34SCarol Wang         std::optional<std::vector<nlohmann::json>> temperatureCollections;
72*4bb3dc34SCarol Wang         std::optional<std::vector<nlohmann::json>> fanCollections;
73*4bb3dc34SCarol Wang         std::unordered_map<std::string, std::vector<nlohmann::json>>
74*4bb3dc34SCarol Wang             allCollections;
75*4bb3dc34SCarol Wang 
76*4bb3dc34SCarol Wang         auto asyncResp = std::make_shared<SensorsAsyncResp>(
77*4bb3dc34SCarol Wang             res, chassisName, typeList, "Thermal");
78*4bb3dc34SCarol Wang 
79*4bb3dc34SCarol Wang         if (!json_util::readJson(req, asyncResp->res, "Temperatures",
80*4bb3dc34SCarol Wang                                  temperatureCollections, "Fans",
81*4bb3dc34SCarol Wang                                  fanCollections))
82*4bb3dc34SCarol Wang         {
83*4bb3dc34SCarol Wang             return;
84*4bb3dc34SCarol Wang         }
85*4bb3dc34SCarol Wang         if (!temperatureCollections && !fanCollections)
86*4bb3dc34SCarol Wang         {
87*4bb3dc34SCarol Wang             messages::resourceNotFound(asyncResp->res, "Thermal",
88*4bb3dc34SCarol Wang                                        "Temperatures / Voltages");
89*4bb3dc34SCarol Wang             return;
90*4bb3dc34SCarol Wang         }
91*4bb3dc34SCarol Wang         if (temperatureCollections)
92*4bb3dc34SCarol Wang         {
93*4bb3dc34SCarol Wang             allCollections.emplace("Temperatures",
94*4bb3dc34SCarol Wang                                    *std::move(temperatureCollections));
95*4bb3dc34SCarol Wang         }
96*4bb3dc34SCarol Wang         if (fanCollections)
97*4bb3dc34SCarol Wang         {
98*4bb3dc34SCarol Wang             allCollections.emplace("Fans", *std::move(fanCollections));
99*4bb3dc34SCarol Wang         }
100*4bb3dc34SCarol Wang 
101*4bb3dc34SCarol Wang         setSensorOverride(asyncResp, allCollections, chassisName, typeList);
102413961deSRichard Marian Thomaiyar     }
10308777fb0SLewanczyk, Dawid };
10408777fb0SLewanczyk, Dawid 
10508777fb0SLewanczyk, Dawid } // namespace redfish
106