1*72375723SMyung Bae // SPDX-License-Identifier: Apache-2.0 2*72375723SMyung Bae // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3*72375723SMyung Bae #pragma once 4*72375723SMyung Bae 5*72375723SMyung Bae #include "async_resp.hpp" 6*72375723SMyung Bae #include "boost_formatters.hpp" 7*72375723SMyung Bae #include "dbus_utility.hpp" 8*72375723SMyung Bae #include "error_messages.hpp" 9*72375723SMyung Bae #include "human_sort.hpp" 10*72375723SMyung Bae #include "logging.hpp" 11*72375723SMyung Bae #include "utils/chassis_utils.hpp" 12*72375723SMyung Bae 13*72375723SMyung Bae #include <asm-generic/errno.h> 14*72375723SMyung Bae 15*72375723SMyung Bae #include <boost/system/error_code.hpp> 16*72375723SMyung Bae #include <sdbusplus/message/native_types.hpp> 17*72375723SMyung Bae 18*72375723SMyung Bae #include <algorithm> 19*72375723SMyung Bae #include <array> 20*72375723SMyung Bae #include <functional> 21*72375723SMyung Bae #include <memory> 22*72375723SMyung Bae #include <optional> 23*72375723SMyung Bae #include <ranges> 24*72375723SMyung Bae #include <string> 25*72375723SMyung Bae #include <string_view> 26*72375723SMyung Bae #include <utility> 27*72375723SMyung Bae #include <vector> 28*72375723SMyung Bae 29*72375723SMyung Bae namespace redfish 30*72375723SMyung Bae { 31*72375723SMyung Bae 32*72375723SMyung Bae static constexpr std::array<std::string_view, 1> assemblyInterfaces = { 33*72375723SMyung Bae "xyz.openbmc_project.Inventory.Item.Panel"}; 34*72375723SMyung Bae 35*72375723SMyung Bae namespace assembly_utils 36*72375723SMyung Bae { 37*72375723SMyung Bae 38*72375723SMyung Bae inline void afterGetChassisAssembly( 39*72375723SMyung Bae const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 40*72375723SMyung Bae std::function<void(const boost::system::error_code&, 41*72375723SMyung Bae const std::vector<std::string>& sortedAssemblyList)>& 42*72375723SMyung Bae callback, 43*72375723SMyung Bae const boost::system::error_code& ec, 44*72375723SMyung Bae const dbus::utility::MapperGetSubTreePathsResponse& subtreePaths) 45*72375723SMyung Bae { 46*72375723SMyung Bae if (ec) 47*72375723SMyung Bae { 48*72375723SMyung Bae if (ec.value() == boost::system::errc::io_error || ec.value() == EBADR) 49*72375723SMyung Bae { 50*72375723SMyung Bae // Not found 51*72375723SMyung Bae callback(ec, std::vector<std::string>()); 52*72375723SMyung Bae return; 53*72375723SMyung Bae } 54*72375723SMyung Bae 55*72375723SMyung Bae BMCWEB_LOG_ERROR("DBUS response error {}", ec); 56*72375723SMyung Bae messages::internalError(asyncResp->res); 57*72375723SMyung Bae return; 58*72375723SMyung Bae } 59*72375723SMyung Bae 60*72375723SMyung Bae std::vector<std::string> sortedAssemblyList = subtreePaths; 61*72375723SMyung Bae std::ranges::sort(sortedAssemblyList, AlphanumLess<std::string>()); 62*72375723SMyung Bae 63*72375723SMyung Bae callback(ec, sortedAssemblyList); 64*72375723SMyung Bae } 65*72375723SMyung Bae 66*72375723SMyung Bae /** 67*72375723SMyung Bae * @brief Get chassis path with given chassis ID 68*72375723SMyung Bae * @param[in] asyncResp - Shared pointer for asynchronous calls. 69*72375723SMyung Bae * @param[in] chassisId - Chassis to which the assemblies are 70*72375723SMyung Bae * associated. 71*72375723SMyung Bae * @param[in] callback 72*72375723SMyung Bae * 73*72375723SMyung Bae * @return None. 74*72375723SMyung Bae */ 75*72375723SMyung Bae inline void getChassisAssembly( 76*72375723SMyung Bae const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 77*72375723SMyung Bae const std::string& chassisId, 78*72375723SMyung Bae std::function<void(const boost::system::error_code& ec, 79*72375723SMyung Bae const std::vector<std::string>& sortedAssemblyList)>&& 80*72375723SMyung Bae callback) 81*72375723SMyung Bae { 82*72375723SMyung Bae BMCWEB_LOG_DEBUG("Get ChassisAssembly"); 83*72375723SMyung Bae 84*72375723SMyung Bae dbus::utility::getAssociatedSubTreePathsById( 85*72375723SMyung Bae chassisId, "/xyz/openbmc_project/inventory", chassisInterfaces, 86*72375723SMyung Bae "containing", assemblyInterfaces, 87*72375723SMyung Bae std::bind_front(afterGetChassisAssembly, asyncResp, 88*72375723SMyung Bae std::move(callback))); 89*72375723SMyung Bae } 90*72375723SMyung Bae 91*72375723SMyung Bae } // namespace assembly_utils 92*72375723SMyung Bae } // namespace redfish 93