Refactor getManagedObjects method
Since the getManagedObjects method has been implemented in
dbus_utility and this commit is to integrate all the places where the
GetManagedObjects method is obtained, and use the method in
dbus_utility uniformly.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Ic13f2bef7b30f805cd3444a75d7df17b031f2eb0
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index f69ea5f..3fbbd2d 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -1449,12 +1449,14 @@
{
const std::string& invConnection = *it;
- // Response handler for GetManagedObjects
- auto respHandler = [sensorsAsyncResp, inventoryItems, invConnections,
- callback{std::forward<Callback>(callback)},
- invConnectionsIndex](
- const boost::system::error_code& ec,
- const dbus::utility::ManagedObjectType& resp) {
+ // Get all object paths and their interfaces for current connection
+ sdbusplus::message::object_path path("/xyz/openbmc_project/inventory");
+ dbus::utility::getManagedObjects(
+ invConnection, path,
+ [sensorsAsyncResp, inventoryItems, invConnections,
+ callback{std::forward<Callback>(callback)}, invConnectionsIndex](
+ const boost::system::error_code& ec,
+ const dbus::utility::ManagedObjectType& resp) {
BMCWEB_LOG_DEBUG << "getInventoryItemsData respHandler enter";
if (ec)
{
@@ -1486,13 +1488,7 @@
invConnectionsIndex + 1);
BMCWEB_LOG_DEBUG << "getInventoryItemsData respHandler exit";
- };
-
- // Get all object paths and their interfaces for current connection
- crow::connections::systemBus->async_method_call(
- std::move(respHandler), invConnection,
- "/xyz/openbmc_project/inventory",
- "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+ });
}
BMCWEB_LOG_DEBUG << "getInventoryItemsData exit";
@@ -1606,8 +1602,10 @@
{
BMCWEB_LOG_DEBUG << "getInventoryItemAssociations enter";
- // Response handler for GetManagedObjects
- auto respHandler =
+ // Call GetManagedObjects on the ObjectMapper to get all associations
+ sdbusplus::message::object_path path("/");
+ dbus::utility::getManagedObjects(
+ "xyz.openbmc_project.ObjectMapper", path,
[callback{std::forward<Callback>(callback)}, sensorsAsyncResp,
sensorNames](const boost::system::error_code& ec,
const dbus::utility::ManagedObjectType& resp) {
@@ -1716,12 +1714,7 @@
}
callback(inventoryItems);
BMCWEB_LOG_DEBUG << "getInventoryItemAssociations respHandler exit";
- };
-
- // Call GetManagedObjects on the ObjectMapper to get all associations
- crow::connections::systemBus->async_method_call(
- std::move(respHandler), "xyz.openbmc_project.ObjectMapper", "/",
- "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+ });
BMCWEB_LOG_DEBUG << "getInventoryItemAssociations exit";
}
@@ -2269,8 +2262,10 @@
// Get managed objects from all services exposing sensors
for (const std::string& connection : connections)
{
- // Response handler to process managed objects
- auto getManagedObjectsCb =
+ sdbusplus::message::object_path sensorPath(
+ "/xyz/openbmc_project/sensors");
+ dbus::utility::getManagedObjects(
+ connection, sensorPath,
[sensorsAsyncResp, sensorNames,
inventoryItems](const boost::system::error_code& ec,
const dbus::utility::ManagedObjectType& resp) {
@@ -2482,11 +2477,7 @@
}
}
BMCWEB_LOG_DEBUG << "getManagedObjectsCb exit";
- };
-
- crow::connections::systemBus->async_method_call(
- getManagedObjectsCb, connection, "/xyz/openbmc_project/sensors",
- "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+ });
}
BMCWEB_LOG_DEBUG << "getSensorData exit";
}