diff options
author | George Liu <liuxiwei@inspur.com> | 2022-12-07 11:03:22 +0300 |
---|---|---|
committer | George Liu <liuxiwei@inspur.com> | 2023-01-11 04:10:26 +0300 |
commit | 7a1dbc4803bf78bfc0c574e6676b3c5def4cdae3 (patch) | |
tree | 9d4713a0125046d112ce3eae7053364ddb2c1d26 /redfish-core/include/utils | |
parent | 1f2a40ce3223e024d510f2e3b32fbc7e08012728 (diff) | |
download | bmcweb-7a1dbc4803bf78bfc0c574e6676b3c5def4cdae3.tar.xz |
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 <liuxiwei@inspur.com>
Change-Id: Ie4140d4484a7e4f4b943013f4371ffd2d44a22e9
Diffstat (limited to 'redfish-core/include/utils')
-rw-r--r-- | redfish-core/include/utils/chassis_utils.hpp | 23 | ||||
-rw-r--r-- | redfish-core/include/utils/collection.hpp | 17 |
2 files changed, 21 insertions, 19 deletions
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 <async_resp.hpp> +#include <array> +#include <string_view> + namespace redfish { @@ -16,13 +22,15 @@ void getValidChassisPath(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& chassisId, Callback&& callback) { BMCWEB_LOG_DEBUG << "checkChassisId enter"; - const std::array<const char*, 2> interfaces = { + constexpr std::array<std::string_view, 2> 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>(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<bmcweb::AsyncResp>& 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 <human_sort.hpp> +#include <span> #include <string> +#include <string_view> #include <vector> namespace redfish @@ -25,14 +29,15 @@ namespace collection_util inline void getCollectionMembers(std::shared_ptr<bmcweb::AsyncResp> aResp, const boost::urls::url& collectionPath, - const std::vector<const char*>& interfaces, + std::span<const std::string_view> 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 |