Refactor GetSubTree method
Since the GetSubTree method has been implemented in dbus_utility and
this commit is to integrate all the places where the GetSubTree
method is called, and use the method in dbus_utility uniformly.
Tested: Redfish Validator Passed
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: If3852b487d74e7cd8f123e0efffbd4affe92743c
diff --git a/redfish-core/lib/cable.hpp b/redfish-core/lib/cable.hpp
index e724118..51eca27 100644
--- a/redfish-core/lib/cable.hpp
+++ b/redfish-core/lib/cable.hpp
@@ -7,6 +7,7 @@
#include "utils/dbus_utils.hpp"
#include "utils/json_utils.hpp"
+#include <boost/system/error_code.hpp>
#include <sdbusplus/asio/property.hpp>
#include <sdbusplus/unpack_properties.hpp>
@@ -120,9 +121,12 @@
return;
}
BMCWEB_LOG_DEBUG << "Cable Id: " << cableId;
- auto respHandler =
+ constexpr std::array<std::string_view, 1> interfaces = {
+ "xyz.openbmc_project.Inventory.Item.Cable"};
+ dbus::utility::getSubTree(
+ "/xyz/openbmc_project/inventory", 0, interfaces,
[asyncResp,
- cableId](const boost::system::error_code ec,
+ cableId](const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreeResponse& subtree) {
if (ec.value() == EBADR)
{
@@ -155,15 +159,7 @@
return;
}
messages::resourceNotFound(asyncResp->res, "Cable", cableId);
- };
-
- crow::connections::systemBus->async_method_call(
- respHandler, "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetSubTree",
- "/xyz/openbmc_project/inventory", 0,
- std::array<const char*, 1>{
- "xyz.openbmc_project.Inventory.Item.Cable"});
+ });
});
}