From 7a1dbc4803bf78bfc0c574e6676b3c5def4cdae3 Mon Sep 17 00:00:00 2001 From: George Liu Date: Wed, 7 Dec 2022 16:03:22 +0800 Subject: Refactor GetSubTreePaths method Since the GetSubTreePaths method has been implemented in dbus_utility and this commit is to integrate all the places where the GetSubTreePaths method is called, and use the method in dbus_utility uniformly. Requires https://gerrit.openbmc.org/c/openbmc/sdbusplus/+/60020 to build. Tested: Redfish Validator Passed Signed-off-by: George Liu Change-Id: Ie4140d4484a7e4f4b943013f4371ffd2d44a22e9 --- redfish-core/include/utils/chassis_utils.hpp | 23 ++++++++++++----------- redfish-core/include/utils/collection.hpp | 17 +++++++++-------- 2 files changed, 21 insertions(+), 19 deletions(-) (limited to 'redfish-core/include') diff --git a/redfish-core/include/utils/chassis_utils.hpp b/redfish-core/include/utils/chassis_utils.hpp index b7f16d83d0..33e8bb7070 100644 --- a/redfish-core/include/utils/chassis_utils.hpp +++ b/redfish-core/include/utils/chassis_utils.hpp @@ -1,6 +1,12 @@ #pragma once + +#include "dbus_utility.hpp" + #include +#include +#include + namespace redfish { @@ -16,13 +22,15 @@ void getValidChassisPath(const std::shared_ptr& asyncResp, const std::string& chassisId, Callback&& callback) { BMCWEB_LOG_DEBUG << "checkChassisId enter"; - const std::array interfaces = { + constexpr std::array interfaces = { "xyz.openbmc_project.Inventory.Item.Board", "xyz.openbmc_project.Inventory.Item.Chassis"}; - auto respHandler = + // Get the Chassis Collection + dbus::utility::getSubTreePaths( + "/xyz/openbmc_project/inventory", 0, interfaces, [callback{std::forward(callback)}, asyncResp, - chassisId](const boost::system::error_code ec, + chassisId](const boost::system::error_code& ec, const dbus::utility::MapperGetSubTreePathsResponse& chassisPaths) mutable { BMCWEB_LOG_DEBUG << "getValidChassisPath respHandler enter"; @@ -51,14 +59,7 @@ void getValidChassisPath(const std::shared_ptr& asyncResp, } } callback(chassisPath); - }; - - // Get the Chassis Collection - crow::connections::systemBus->async_method_call( - respHandler, "xyz.openbmc_project.ObjectMapper", - "/xyz/openbmc_project/object_mapper", - "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", - "/xyz/openbmc_project/inventory", 0, interfaces); + }); BMCWEB_LOG_DEBUG << "checkChassisId exit"; } diff --git a/redfish-core/include/utils/collection.hpp b/redfish-core/include/utils/collection.hpp index f11730279d..b66ab5d05c 100644 --- a/redfish-core/include/utils/collection.hpp +++ b/redfish-core/include/utils/collection.hpp @@ -1,8 +1,12 @@ #pragma once +#include "dbus_utility.hpp" + #include +#include #include +#include #include namespace redfish @@ -25,14 +29,15 @@ namespace collection_util inline void getCollectionMembers(std::shared_ptr aResp, const boost::urls::url& collectionPath, - const std::vector& interfaces, + std::span interfaces, const char* subtree = "/xyz/openbmc_project/inventory") { BMCWEB_LOG_DEBUG << "Get collection members for: " << collectionPath.buffer(); - crow::connections::systemBus->async_method_call( + dbus::utility::getSubTreePaths( + subtree, 0, interfaces, [collectionPath, aResp{std::move(aResp)}]( - const boost::system::error_code ec, + const boost::system::error_code& ec, const dbus::utility::MapperGetSubTreePathsResponse& objects) { if (ec == boost::system::errc::io_error) { @@ -73,11 +78,7 @@ inline void members.push_back(std::move(member)); } aResp->res.jsonValue["Members@odata.count"] = members.size(); - }, - "xyz.openbmc_project.ObjectMapper", - "/xyz/openbmc_project/object_mapper", - "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", subtree, 0, - interfaces); + }); } } // namespace collection_util -- cgit v1.2.3