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
diff --git a/redfish-core/include/utils/chassis_utils.hpp b/redfish-core/include/utils/chassis_utils.hpp
index b7f16d8..33e8bb7 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 @@
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 @@
}
}
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 f117302..b66ab5d 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 @@
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 @@
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