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 207e860f15SJohn Edward Broadbent #include <app.hpp> 21ed398213SEd Tanous #include <registries/privilege_registry.hpp> 227e860f15SJohn Edward Broadbent 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)( 317e860f15SJohn Edward Broadbent [](const crow::Request&, 327e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 337e860f15SJohn Edward Broadbent const std::string& chassisName) { 347e860f15SJohn Edward Broadbent auto thermalPaths = 357e860f15SJohn Edward Broadbent sensors::dbus::paths.find(sensors::node::thermal); 361b1be67fSKrzysztof Grobelny if (thermalPaths == sensors::dbus::paths.end()) 371b1be67fSKrzysztof Grobelny { 381b1be67fSKrzysztof Grobelny messages::internalError(asyncResp->res); 391b1be67fSKrzysztof Grobelny return; 401b1be67fSKrzysztof Grobelny } 411b1be67fSKrzysztof Grobelny 422474adfaSEd Tanous auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( 431b1be67fSKrzysztof Grobelny asyncResp, chassisName, thermalPaths->second, 44a0ec28b6SAdrian Ambrożewicz sensors::node::thermal); 452474adfaSEd Tanous 462474adfaSEd Tanous // TODO Need to get Chassis Redundancy information. 472474adfaSEd Tanous getChassisData(sensorAsyncResp); 487e860f15SJohn Edward Broadbent }); 498d1b46d7Szhanghch05 507e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Thermal/") 51ed398213SEd Tanous .privileges(redfish::privileges::patchThermal) 527e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::patch)( 537e860f15SJohn Edward Broadbent [](const crow::Request& req, 547e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 557e860f15SJohn Edward Broadbent const std::string& chassisName) { 567e860f15SJohn Edward Broadbent auto thermalPaths = 577e860f15SJohn Edward Broadbent sensors::dbus::paths.find(sensors::node::thermal); 581b1be67fSKrzysztof Grobelny if (thermalPaths == sensors::dbus::paths.end()) 591b1be67fSKrzysztof Grobelny { 601b1be67fSKrzysztof Grobelny messages::internalError(asyncResp->res); 611b1be67fSKrzysztof Grobelny return; 621b1be67fSKrzysztof Grobelny } 631b1be67fSKrzysztof Grobelny 647e860f15SJohn Edward Broadbent std::optional<std::vector<nlohmann::json>> 657e860f15SJohn Edward Broadbent temperatureCollections; 664bb3dc34SCarol Wang std::optional<std::vector<nlohmann::json>> fanCollections; 674bb3dc34SCarol Wang std::unordered_map<std::string, std::vector<nlohmann::json>> 684bb3dc34SCarol Wang allCollections; 694bb3dc34SCarol Wang 708d1b46d7Szhanghch05 auto sensorsAsyncResp = std::make_shared<SensorsAsyncResp>( 711b1be67fSKrzysztof Grobelny asyncResp, chassisName, thermalPaths->second, 72a0ec28b6SAdrian Ambrożewicz sensors::node::thermal); 734bb3dc34SCarol Wang 74*15ed6780SWilly Tu if (!json_util::readJsonPatch( 75*15ed6780SWilly Tu req, sensorsAsyncResp->asyncResp->res, "Temperatures", 76*15ed6780SWilly Tu temperatureCollections, "Fans", fanCollections)) 774bb3dc34SCarol Wang { 784bb3dc34SCarol Wang return; 794bb3dc34SCarol Wang } 804bb3dc34SCarol Wang if (!temperatureCollections && !fanCollections) 814bb3dc34SCarol Wang { 828d1b46d7Szhanghch05 messages::resourceNotFound(sensorsAsyncResp->asyncResp->res, 837e860f15SJohn Edward Broadbent "Thermal", 847e860f15SJohn Edward Broadbent "Temperatures / Voltages"); 854bb3dc34SCarol Wang return; 864bb3dc34SCarol Wang } 874bb3dc34SCarol Wang if (temperatureCollections) 884bb3dc34SCarol Wang { 894bb3dc34SCarol Wang allCollections.emplace("Temperatures", 904bb3dc34SCarol Wang *std::move(temperatureCollections)); 914bb3dc34SCarol Wang } 924bb3dc34SCarol Wang if (fanCollections) 934bb3dc34SCarol Wang { 944bb3dc34SCarol Wang allCollections.emplace("Fans", *std::move(fanCollections)); 954bb3dc34SCarol Wang } 9680ac4024SBruce Lee setSensorsOverride(sensorsAsyncResp, allCollections); 977e860f15SJohn Edward Broadbent }); 98413961deSRichard Marian Thomaiyar } 9908777fb0SLewanczyk, Dawid 10008777fb0SLewanczyk, Dawid } // namespace redfish 101