1 #pragma once 2 #include <async_resp.hpp> 3 4 namespace redfish 5 { 6 7 namespace chassis_utils 8 { 9 /** 10 * @brief Retrieves valid chassis path 11 * @param asyncResp Pointer to object holding response data 12 * @param callback Callback for next step to get valid chassis path 13 */ 14 template <typename Callback> 15 void getValidChassisPath(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 16 const std::string& chassisId, Callback&& callback) 17 { 18 BMCWEB_LOG_DEBUG << "checkChassisId enter"; 19 const std::array<const char*, 2> interfaces = { 20 "xyz.openbmc_project.Inventory.Item.Board", 21 "xyz.openbmc_project.Inventory.Item.Chassis"}; 22 23 auto respHandler = 24 [callback{std::forward<Callback>(callback)}, asyncResp, 25 chassisId](const boost::system::error_code ec, 26 const dbus::utility::MapperGetSubTreePathsResponse& 27 chassisPaths) mutable { 28 BMCWEB_LOG_DEBUG << "getValidChassisPath respHandler enter"; 29 if (ec) 30 { 31 BMCWEB_LOG_ERROR << "getValidChassisPath respHandler DBUS error: " 32 << ec; 33 messages::internalError(asyncResp->res); 34 return; 35 } 36 37 std::optional<std::string> chassisPath; 38 std::string chassisName; 39 for (const std::string& chassis : chassisPaths) 40 { 41 sdbusplus::message::object_path path(chassis); 42 chassisName = path.filename(); 43 if (chassisName.empty()) 44 { 45 BMCWEB_LOG_ERROR << "Failed to find '/' in " << chassis; 46 continue; 47 } 48 if (chassisName == chassisId) 49 { 50 chassisPath = chassis; 51 break; 52 } 53 } 54 callback(chassisPath); 55 }; 56 57 // Get the Chassis Collection 58 crow::connections::systemBus->async_method_call( 59 respHandler, "xyz.openbmc_project.ObjectMapper", 60 "/xyz/openbmc_project/object_mapper", 61 "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", 62 "/xyz/openbmc_project/inventory", 0, interfaces); 63 BMCWEB_LOG_DEBUG << "checkChassisId exit"; 64 } 65 66 } // namespace chassis_utils 67 } // namespace redfish 68