1*40e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0 2*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors 30d7702c0SZhenwei Chen #pragma once 47a1dbc48SGeorge Liu 53ccb3adbSEd Tanous #include "async_resp.hpp" 67a1dbc48SGeorge Liu #include "dbus_utility.hpp" 73ccb3adbSEd Tanous #include "error_messages.hpp" 80d7702c0SZhenwei Chen 97a1dbc48SGeorge Liu #include <array> 107a1dbc48SGeorge Liu #include <string_view> 117a1dbc48SGeorge Liu 120d7702c0SZhenwei Chen namespace redfish 130d7702c0SZhenwei Chen { 140d7702c0SZhenwei Chen 150d7702c0SZhenwei Chen namespace chassis_utils 160d7702c0SZhenwei Chen { 170d7702c0SZhenwei Chen /** 180d7702c0SZhenwei Chen * @brief Retrieves valid chassis path 190d7702c0SZhenwei Chen * @param asyncResp Pointer to object holding response data 200d7702c0SZhenwei Chen * @param callback Callback for next step to get valid chassis path 210d7702c0SZhenwei Chen */ 220d7702c0SZhenwei Chen template <typename Callback> 230d7702c0SZhenwei Chen void getValidChassisPath(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 240d7702c0SZhenwei Chen const std::string& chassisId, Callback&& callback) 250d7702c0SZhenwei Chen { 2662598e31SEd Tanous BMCWEB_LOG_DEBUG("checkChassisId enter"); 277a1dbc48SGeorge Liu constexpr std::array<std::string_view, 2> interfaces = { 280d7702c0SZhenwei Chen "xyz.openbmc_project.Inventory.Item.Board", 290d7702c0SZhenwei Chen "xyz.openbmc_project.Inventory.Item.Chassis"}; 300d7702c0SZhenwei Chen 317a1dbc48SGeorge Liu // Get the Chassis Collection 327a1dbc48SGeorge Liu dbus::utility::getSubTreePaths( 337a1dbc48SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 348cb2c024SEd Tanous [callback = std::forward<Callback>(callback), asyncResp, 357a1dbc48SGeorge Liu chassisId](const boost::system::error_code& ec, 360d7702c0SZhenwei Chen const dbus::utility::MapperGetSubTreePathsResponse& 370d7702c0SZhenwei Chen chassisPaths) mutable { 3862598e31SEd Tanous BMCWEB_LOG_DEBUG("getValidChassisPath respHandler enter"); 390d7702c0SZhenwei Chen if (ec) 400d7702c0SZhenwei Chen { 41bd79bce8SPatrick Williams BMCWEB_LOG_ERROR( 42bd79bce8SPatrick Williams "getValidChassisPath respHandler DBUS error: {}", ec); 430d7702c0SZhenwei Chen messages::internalError(asyncResp->res); 440d7702c0SZhenwei Chen return; 450d7702c0SZhenwei Chen } 460d7702c0SZhenwei Chen 470d7702c0SZhenwei Chen std::optional<std::string> chassisPath; 480d7702c0SZhenwei Chen for (const std::string& chassis : chassisPaths) 490d7702c0SZhenwei Chen { 500d7702c0SZhenwei Chen sdbusplus::message::object_path path(chassis); 51f8fe53e7SEd Tanous std::string chassisName = path.filename(); 520d7702c0SZhenwei Chen if (chassisName.empty()) 530d7702c0SZhenwei Chen { 5462598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to find '/' in {}", chassis); 550d7702c0SZhenwei Chen continue; 560d7702c0SZhenwei Chen } 570d7702c0SZhenwei Chen if (chassisName == chassisId) 580d7702c0SZhenwei Chen { 590d7702c0SZhenwei Chen chassisPath = chassis; 600d7702c0SZhenwei Chen break; 610d7702c0SZhenwei Chen } 620d7702c0SZhenwei Chen } 630d7702c0SZhenwei Chen callback(chassisPath); 647a1dbc48SGeorge Liu }); 6562598e31SEd Tanous BMCWEB_LOG_DEBUG("checkChassisId exit"); 660d7702c0SZhenwei Chen } 670d7702c0SZhenwei Chen 680d7702c0SZhenwei Chen } // namespace chassis_utils 690d7702c0SZhenwei Chen } // namespace redfish 70