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/processor.hpp b/redfish-core/lib/processor.hpp
index 879c04b..1ac29ff 100644
--- a/redfish-core/lib/processor.hpp
+++ b/redfish-core/lib/processor.hpp
@@ -27,6 +27,7 @@
#include "utils/json_utils.hpp"
#include <boost/container/flat_map.hpp>
+#include <boost/system/error_code.hpp>
#include <sdbusplus/asio/property.hpp>
#include <sdbusplus/message/native_types.hpp>
#include <sdbusplus/unpack_properties.hpp>
@@ -681,10 +682,20 @@
BMCWEB_LOG_DEBUG << "Get available system processor resources.";
// GetSubTree on all interfaces which provide info about a Processor
- crow::connections::systemBus->async_method_call(
+ constexpr std::array<std::string_view, 8> interfaces = {
+ "xyz.openbmc_project.Common.UUID",
+ "xyz.openbmc_project.Inventory.Decorator.Asset",
+ "xyz.openbmc_project.Inventory.Decorator.Revision",
+ "xyz.openbmc_project.Inventory.Item.Cpu",
+ "xyz.openbmc_project.Inventory.Decorator.LocationCode",
+ "xyz.openbmc_project.Inventory.Item.Accelerator",
+ "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
+ "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier"};
+ dbus::utility::getSubTree(
+ "/xyz/openbmc_project/inventory", 0, interfaces,
[resp, processorId, handler = std::forward<Handler>(handler)](
- boost::system::error_code ec,
- const dbus::utility::MapperGetSubTreeResponse& subtree) mutable {
+ const boost::system::error_code& ec,
+ const dbus::utility::MapperGetSubTreeResponse& subtree) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error: " << ec;
@@ -729,20 +740,7 @@
return;
}
messages::resourceNotFound(resp->res, "Processor", processorId);
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetSubTree",
- "/xyz/openbmc_project/inventory", 0,
- std::array<const char*, 8>{
- "xyz.openbmc_project.Common.UUID",
- "xyz.openbmc_project.Inventory.Decorator.Asset",
- "xyz.openbmc_project.Inventory.Decorator.Revision",
- "xyz.openbmc_project.Inventory.Item.Cpu",
- "xyz.openbmc_project.Inventory.Decorator.LocationCode",
- "xyz.openbmc_project.Inventory.Item.Accelerator",
- "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig",
- "xyz.openbmc_project.Inventory.Decorator.UniqueIdentifier"});
+ });
}
inline void getProcessorData(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
@@ -1137,9 +1135,12 @@
}
// Ask for all objects implementing OperatingConfig so we can search
// for one with a matching name
- crow::connections::systemBus->async_method_call(
+ constexpr std::array<std::string_view, 1> interfaces = {
+ "xyz.openbmc_project.Inventory.Item.Cpu.OperatingConfig"};
+ dbus::utility::getSubTree(
+ "/xyz/openbmc_project/inventory", 0, interfaces,
[asyncResp, cpuName, configName, reqUrl{req.url}](
- boost::system::error_code ec,
+ const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreeResponse& subtree) {
if (ec)
{
@@ -1172,13 +1173,7 @@
}
messages::resourceNotFound(asyncResp->res, "OperatingConfig",
configName);
- },
- "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.Cpu.OperatingConfig"});
+ });
});
}