// SPDX-License-Identifier: Apache-2.0 // SPDX-FileCopyrightText: Copyright OpenBMC Authors #pragma once #include "async_resp.hpp" #include "dbus_utility.hpp" #include "error_messages.hpp" #include "human_sort.hpp" #include "logging.hpp" #include #include #include #include #include #include #include #include #include #include #include namespace redfish { constexpr std::array fanInterface = { "xyz.openbmc_project.Inventory.Item.Fan"}; namespace fan_utils { constexpr std::array sensorInterface = { "xyz.openbmc_project.Sensor.Value"}; inline void afterGetFanSensorObjects( const std::shared_ptr& asyncResp, const std::function>&)>& callback, const boost::system::error_code& ec, const dbus::utility::MapperGetSubTreeResponse& subtree) { if (ec) { if (ec.value() != boost::system::errc::io_error && ec.value() != EBADR) { BMCWEB_LOG_ERROR("DBUS response error {}", ec); messages::internalError(asyncResp->res); } return; } std::vector> sensorsPathAndService; for (const auto& [sensorPath, serviceMaps] : subtree) { for (const auto& [service, interfaces] : serviceMaps) { sensorsPathAndService.emplace_back(service, sensorPath); } } /* Sort list by sensorPath */ std::ranges::sort( sensorsPathAndService, [](const auto& c1, const auto& c2) { return AlphanumLess()(c1.second, c2.second); }); callback(sensorsPathAndService); } inline void getFanSensorObjects( const std::shared_ptr& asyncResp, const sdbusplus::object_path& fanPath, const std::function>&)>& callback) { sdbusplus::object_path endpointPath{fanPath}; endpointPath /= "sensors"; dbus::utility::getAssociatedSubTree( endpointPath, sdbusplus::object_path("/xyz/openbmc_project/sensors"), 0, sensorInterface, std::bind_front(afterGetFanSensorObjects, asyncResp, callback)); } inline void afterGetFanPaths( const std::shared_ptr& asyncResp, const std::function& callback, const boost::system::error_code& ec, const dbus::utility::MapperGetSubTreePathsResponse& subtreePaths) { if (ec) { if (ec.value() != boost::system::errc::io_error && ec.value() != EBADR) { BMCWEB_LOG_ERROR("DBUS response error {}", ec); messages::internalError(asyncResp->res); } return; } callback(subtreePaths); } inline void getFanPaths( const std::shared_ptr& asyncResp, const std::string& validChassisPath, const std::function& callback) { sdbusplus::object_path endpointPath{validChassisPath}; endpointPath /= "cooled_by"; dbus::utility::getAssociatedSubTreePaths( endpointPath, sdbusplus::object_path("/xyz/openbmc_project/inventory"), 0, fanInterface, std::bind_front(afterGetFanPaths, asyncResp, callback)); } } // namespace fan_utils } // namespace redfish