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/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index e53a7d2..00b2ba6 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -15,6 +15,7 @@
*/
#pragma once
+#include "dbus_utility.hpp"
#include "generated/enums/sensor.hpp"
#include <app.hpp>
@@ -34,10 +35,12 @@
#include <utils/json_utils.hpp>
#include <utils/query_param.hpp>
+#include <array>
#include <cmath>
#include <iterator>
#include <map>
#include <set>
+#include <string_view>
#include <utility>
#include <variant>
@@ -515,14 +518,17 @@
std::span<std::string_view> sensorTypes, Callback&& callback)
{
BMCWEB_LOG_DEBUG << "getChassis 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,
chassisIdStr{std::string(chassisId)},
chassisSubNode{std::string(chassisSubNode)}, sensorTypes](
- const boost::system::error_code ec,
+ const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreePathsResponse& chassisPaths) {
BMCWEB_LOG_DEBUG << "getChassis respHandler enter";
if (ec)
@@ -581,14 +587,7 @@
BMCWEB_LOG_DEBUG << "Finishing with " << culledSensorList->size();
callback(culledSensorList);
});
- };
-
- // 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 << "getChassis exit";
}