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/include/nbd_proxy.hpp b/include/nbd_proxy.hpp
index e4d709b..62bd324 100644
--- a/include/nbd_proxy.hpp
+++ b/include/nbd_proxy.hpp
@@ -327,15 +327,13 @@
 {
     BMCWEB_LOG_DEBUG << "nbd-proxy.onopen(" << &conn << ")";
 
-    auto openHandler =
+    sdbusplus::message::object_path path("/xyz/openbmc_project/VirtualMedia");
+    dbus::utility::getManagedObjects(
+        "xyz.openbmc_project.VirtualMedia", path,
         [&conn](const boost::system::error_code& ec,
                 const dbus::utility::ManagedObjectType& objects) {
         afterGetManagedObjects(conn, ec, objects);
-    };
-    crow::connections::systemBus->async_method_call(
-        std::move(openHandler), "xyz.openbmc_project.VirtualMedia",
-        "/xyz/openbmc_project/VirtualMedia",
-        "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+        });
 
     // We need to wait for dbus and the websockets to hook up before data is
     // sent/received.  Tell the core to hold off messages until the sockets are
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 0fbef04..4dbf12e 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -302,7 +302,9 @@
     BMCWEB_LOG_DEBUG << "getManagedObjectsForEnumerate " << objectName
                      << " object_manager_path " << objectManagerPath
                      << " connection_name " << connectionName;
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::message::object_path path(objectManagerPath);
+    dbus::utility::getManagedObjects(
+        connectionName, path,
         [transaction, objectName,
          connectionName](const boost::system::error_code& ec,
                          const dbus::utility::ManagedObjectType& objects) {
@@ -360,9 +362,7 @@
                 }
             }
         }
-        },
-        connectionName, objectManagerPath, "org.freedesktop.DBus.ObjectManager",
-        "GetManagedObjects");
+        });
 }
 
 inline void findObjectManagerPathForEnumerate(
diff --git a/redfish-core/include/redfish_aggregator.hpp b/redfish-core/include/redfish_aggregator.hpp
index 3b48bda..a6920e8 100644
--- a/redfish-core/include/redfish_aggregator.hpp
+++ b/redfish-core/include/redfish_aggregator.hpp
@@ -756,7 +756,9 @@
             handler)
     {
         BMCWEB_LOG_DEBUG << "Gathering satellite configs";
-        crow::connections::systemBus->async_method_call(
+        sdbusplus::message::object_path path("/xyz/openbmc_project/inventory");
+        dbus::utility::getManagedObjects(
+            "xyz.openbmc_project.EntityManager", path,
             [handler{std::move(handler)}](
                 const boost::system::error_code& ec,
                 const dbus::utility::ManagedObjectType& objects) {
@@ -786,10 +788,7 @@
                     << "No satellite BMCs detected.  Redfish Aggregation not enabled";
             }
             handler(ec, satelliteInfo);
-            },
-            "xyz.openbmc_project.EntityManager",
-            "/xyz/openbmc_project/inventory",
-            "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+            });
     }
 
     // Processes the response returned by a satellite BMC and loads its
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index 6f5f122..91f7804 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -53,7 +53,6 @@
 constexpr const char* ldapEnableInterface = "xyz.openbmc_project.Object.Enable";
 constexpr const char* ldapPrivMapperInterface =
     "xyz.openbmc_project.User.PrivilegeMapper";
-constexpr const char* dbusObjManagerIntf = "org.freedesktop.DBus.ObjectManager";
 constexpr const char* propertyInterface = "org.freedesktop.DBus.Properties";
 
 struct LDAPRoleMapData
@@ -580,7 +579,9 @@
             return;
         }
         std::string service = resp.begin()->first;
-        crow::connections::systemBus->async_method_call(
+        sdbusplus::message::object_path path(ldapRootObject);
+        dbus::utility::getManagedObjects(
+            service, path,
             [callback,
              ldapType](const boost::system::error_code& errorCode,
                        const dbus::utility::ManagedObjectType& ldapObjects) {
@@ -717,8 +718,7 @@
                 }
             }
             callback(true, confData, ldapType);
-            },
-            service, ldapRootObject, dbusObjManagerIntf, "GetManagedObjects");
+            });
         });
 }
 
@@ -1732,7 +1732,9 @@
     {
         thisUser = req.session->username;
     }
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::message::object_path path("/xyz/openbmc_project/user");
+    dbus::utility::getManagedObjects(
+        "xyz.openbmc_project.User.Manager", path,
         [asyncResp, thisUser, effectiveUserPrivileges](
             const boost::system::error_code& ec,
             const dbus::utility::ManagedObjectType& users) {
@@ -1776,9 +1778,7 @@
             }
         }
         asyncResp->res.jsonValue["Members@odata.count"] = memberArray.size();
-        },
-        "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
-        "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+        });
 }
 
 inline void processAfterCreateUser(
@@ -2016,7 +2016,9 @@
         }
     }
 
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::message::object_path path("/xyz/openbmc_project/user");
+    dbus::utility::getManagedObjects(
+        "xyz.openbmc_project.User.Manager", path,
         [asyncResp,
          accountName](const boost::system::error_code& ec,
                       const dbus::utility::ManagedObjectType& users) {
@@ -2148,9 +2150,7 @@
             "/redfish/v1/AccountService/Accounts/" + accountName;
         asyncResp->res.jsonValue["Id"] = accountName;
         asyncResp->res.jsonValue["UserName"] = accountName;
-        },
-        "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
-        "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+        });
 }
 
 inline void
diff --git a/redfish-core/lib/health.hpp b/redfish-core/lib/health.hpp
index ef858a1..c5249f2 100644
--- a/redfish-core/lib/health.hpp
+++ b/redfish-core/lib/health.hpp
@@ -212,7 +212,9 @@
     void getAllStatusAssociations()
     {
         std::shared_ptr<HealthPopulate> self = shared_from_this();
-        crow::connections::systemBus->async_method_call(
+        sdbusplus::message::object_path path("/");
+        dbus::utility::getManagedObjects(
+            "xyz.openbmc_project.ObjectMapper", path,
             [self](const boost::system::error_code& ec,
                    const dbus::utility::ManagedObjectType& resp) {
             if (ec)
@@ -230,9 +232,7 @@
                 }
                 it = self->statuses.erase(it);
             }
-            },
-            "xyz.openbmc_project.ObjectMapper", "/",
-            "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+            });
     }
 
     std::shared_ptr<bmcweb::AsyncResp> asyncResp;
diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp
index 52aeb43..c16c171 100644
--- a/redfish-core/lib/hypervisor_system.hpp
+++ b/redfish-core/lib/hypervisor_system.hpp
@@ -311,7 +311,9 @@
 void getHypervisorIfaceData(const std::string& ethIfaceId,
                             CallbackFunc&& callback)
 {
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::message::object_path path("/");
+    dbus::utility::getManagedObjects(
+        "xyz.openbmc_project.Settings", path,
         [ethIfaceId{std::string{ethIfaceId}},
          callback{std::forward<CallbackFunc>(callback)}](
             const boost::system::error_code& error,
@@ -331,9 +333,7 @@
             BMCWEB_LOG_INFO << "Hypervisor Interface not found";
         }
         callback(found, ethData, ipv4Data);
-        },
-        "xyz.openbmc_project.Settings", "/",
-        "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+        });
 }
 
 /**
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 9ff3cdf..323c22a 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -467,10 +467,12 @@
         return;
     }
 
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::message::object_path path("/xyz/openbmc_project/dump");
+    dbus::utility::getManagedObjects(
+        "xyz.openbmc_project.Dump.Manager", path,
         [asyncResp, entriesPath,
          dumpType](const boost::system::error_code& ec,
-                   dbus::utility::ManagedObjectType& resp) {
+                   const dbus::utility::ManagedObjectType& objects) {
         if (ec)
         {
             BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
@@ -498,6 +500,7 @@
             "/xyz/openbmc_project/dump/" +
             std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/";
 
+        dbus::utility::ManagedObjectType resp(objects);
         std::sort(resp.begin(), resp.end(), [](const auto& l, const auto& r) {
             return AlphanumLess<std::string>()(l.first.filename(),
                                                r.first.filename());
@@ -567,9 +570,7 @@
             entriesArray.emplace_back(std::move(thisEntry));
         }
         asyncResp->res.jsonValue["Members@odata.count"] = entriesArray.size();
-        },
-        "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
-        "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+        });
 }
 
 inline void
@@ -583,7 +584,9 @@
         return;
     }
 
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::message::object_path path("/xyz/openbmc_project/dump");
+    dbus::utility::getManagedObjects(
+        "xyz.openbmc_project.Dump.Manager", path,
         [asyncResp, entryID, dumpType,
          entriesPath](const boost::system::error_code& ec,
                       const dbus::utility::ManagedObjectType& resp) {
@@ -667,9 +670,7 @@
                                        entryID);
             return;
         }
-        },
-        "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
-        "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+        });
 }
 
 inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
@@ -1564,7 +1565,9 @@
 
         // DBus implementation of EventLog/Entries
         // Make call to Logging Service to find all log entry objects
-        crow::connections::systemBus->async_method_call(
+        sdbusplus::message::object_path path("/xyz/openbmc_project/logging");
+        dbus::utility::getManagedObjects(
+            "xyz.openbmc_project.Logging", path,
             [asyncResp](const boost::system::error_code& ec,
                         const dbus::utility::ManagedObjectType& resp) {
             if (ec)
@@ -1718,9 +1721,7 @@
                 });
             asyncResp->res.jsonValue["Members@odata.count"] =
                 entriesArray.size();
-            },
-            "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging",
-            "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+            });
         });
 }
 
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index 5bb4908..b630609 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -290,7 +290,9 @@
                      const std::vector<std::string>& supportedProfiles,
                      const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
 {
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::message::object_path objPath(path);
+    dbus::utility::getManagedObjects(
+        connection, objPath,
         [asyncResp, currentProfile, supportedProfiles](
             const boost::system::error_code& ec,
             const dbus::utility::ManagedObjectType& managedObj) {
@@ -688,8 +690,7 @@
                 }
             }
         }
-        },
-        connection, path, objectManagerIface, "GetManagedObjects");
+        });
 }
 
 enum class CreatePIDRet
@@ -1358,7 +1359,10 @@
 
         // todo(james): might make sense to do a mapper call here if this
         // interface gets more traction
-        crow::connections::systemBus->async_method_call(
+        sdbusplus::message::object_path objPath(
+            "/xyz/openbmc_project/inventory");
+        dbus::utility::getManagedObjects(
+            "xyz.openbmc_project.EntityManager", objPath,
             [self](const boost::system::error_code& ec,
                    const dbus::utility::ManagedObjectType& mObj) {
             if (ec)
@@ -1384,10 +1388,7 @@
                 }
             }
             self->managedObj = mObj;
-            },
-            "xyz.openbmc_project.EntityManager",
-            "/xyz/openbmc_project/inventory", objectManagerIface,
-            "GetManagedObjects");
+            });
 
         // at the same time get the profile information
         constexpr std::array<std::string_view, 1> thermalModeIfaces = {
@@ -1779,10 +1780,12 @@
     std::string firmwareId = runningFirmwareTarget.substr(idPos);
 
     // Make sure the image is valid before setting priority
-    crow::connections::systemBus->async_method_call(
-        [asyncResp, firmwareId,
-         runningFirmwareTarget](const boost::system::error_code& ec,
-                                dbus::utility::ManagedObjectType& subtree) {
+    sdbusplus::message::object_path objPath("/xyz/openbmc_project/software");
+    dbus::utility::getManagedObjects(
+        "xyz.openbmc_project.Software.BMC.Updater", objPath,
+        [asyncResp, firmwareId, runningFirmwareTarget](
+            const boost::system::error_code& ec,
+            const dbus::utility::ManagedObjectType& subtree) {
         if (ec)
         {
             BMCWEB_LOG_DEBUG << "D-Bus response error getting objects.";
@@ -1852,10 +1855,7 @@
             "org.freedesktop.DBus.Properties", "Set",
             "xyz.openbmc_project.Software.RedundancyPriority", "Priority",
             dbus::utility::DbusVariantType(static_cast<uint8_t>(0)));
-        },
-        "xyz.openbmc_project.Software.BMC.Updater",
-        "/xyz/openbmc_project/software", "org.freedesktop.DBus.ObjectManager",
-        "GetManagedObjects");
+        });
 }
 
 inline void setDateTime(std::shared_ptr<bmcweb::AsyncResp> asyncResp,
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index be84246..35c3dae 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -98,7 +98,9 @@
 template <typename CallbackFunc>
 void getEthernetIfaceData(CallbackFunc&& callback)
 {
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::message::object_path path("/xyz/openbmc_project/network");
+    dbus::utility::getManagedObjects(
+        "xyz.openbmc_project.Network", path,
         [callback{std::forward<CallbackFunc>(callback)}](
             const boost::system::error_code& errorCode,
             const dbus::utility::ManagedObjectType& dbusData) {
@@ -114,9 +116,7 @@
         extractNTPServersAndDomainNamesData(dbusData, ntpServers, domainNames);
 
         callback(true, ntpServers, domainNames);
-        },
-        "xyz.openbmc_project.Network", "/xyz/openbmc_project/network",
-        "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+        });
 }
 
 inline void afterNetworkPortRequest(
diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp
index a2c49a6..2d52cd7 100644
--- a/redfish-core/lib/processor.hpp
+++ b/redfish-core/lib/processor.hpp
@@ -225,7 +225,9 @@
 {
     BMCWEB_LOG_DEBUG << "Get available system cpu resources by service.";
 
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::message::object_path path("/xyz/openbmc_project/inventory");
+    dbus::utility::getManagedObjects(
+        service, path,
         [cpuId, service, objPath, asyncResp{std::move(asyncResp)}](
             const boost::system::error_code& ec,
             const dbus::utility::ManagedObjectType& dbusData) {
@@ -288,9 +290,7 @@
             asyncResp->res.jsonValue["TotalCores"] = totalCores;
         }
         return;
-        },
-        service, "/xyz/openbmc_project/inventory",
-        "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+        });
 }
 
 /**
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";
 }
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index 5e177ab..81af41f 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -94,7 +94,9 @@
                        const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
                        CheckItemHandler&& handler)
 {
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::message::object_path path("/xyz/openbmc_project/VirtualMedia");
+    dbus::utility::getManagedObjects(
+        service, path,
         [service, resName, asyncResp,
          handler](const boost::system::error_code& ec,
                   const dbus::utility::ManagedObjectType& subtree) {
@@ -117,9 +119,7 @@
 
         BMCWEB_LOG_DEBUG << "Parent item not found";
         asyncResp->res.result(boost::beast::http::status::not_found);
-        },
-        service, "/xyz/openbmc_project/VirtualMedia",
-        "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+        });
 }
 
 /**
@@ -273,7 +273,10 @@
                               const std::string& name)
 {
     BMCWEB_LOG_DEBUG << "Get available Virtual Media resources.";
-    crow::connections::systemBus->async_method_call(
+    sdbusplus::message::object_path objPath(
+        "/xyz/openbmc_project/VirtualMedia");
+    dbus::utility::getManagedObjects(
+        service, objPath,
         [name, asyncResp{std::move(asyncResp)}](
             const boost::system::error_code& ec,
             const dbus::utility::ManagedObjectType& subtree) {
@@ -299,9 +302,7 @@
             members.emplace_back(std::move(item));
         }
         asyncResp->res.jsonValue["Members@odata.count"] = members.size();
-        },
-        service, "/xyz/openbmc_project/VirtualMedia",
-        "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+        });
 }
 
 inline void
@@ -877,10 +878,13 @@
         std::string service = getObjectType.begin()->first;
         BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
 
-        crow::connections::systemBus->async_method_call(
-            [service, resName, action, actionParams,
-             asyncResp](const boost::system::error_code& ec2,
-                        dbus::utility::ManagedObjectType& subtree) mutable {
+        sdbusplus::message::object_path path(
+            "/xyz/openbmc_project/VirtualMedia");
+        dbus::utility::getManagedObjects(
+            service, path,
+            [service, resName, action, actionParams, asyncResp](
+                const boost::system::error_code& ec2,
+                const dbus::utility::ManagedObjectType& subtree) mutable {
             if (ec2)
             {
                 // Not possible in proxy mode
@@ -902,9 +906,7 @@
             }
             BMCWEB_LOG_DEBUG << "Parent item not found";
             messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName);
-            },
-            service, "/xyz/openbmc_project/VirtualMedia",
-            "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+            });
         });
 }
 
@@ -941,7 +943,10 @@
         std::string service = getObjectType.begin()->first;
         BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
 
-        crow::connections::systemBus->async_method_call(
+        sdbusplus::message::object_path path(
+            "/xyz/openbmc_project/VirtualMedia");
+        dbus::utility::getManagedObjects(
+            service, path,
             [resName, service, action,
              asyncResp](const boost::system::error_code& ec,
                         const dbus::utility::ManagedObjectType& subtree) {
@@ -964,9 +969,7 @@
             }
             BMCWEB_LOG_DEBUG << "Parent item not found";
             messages::resourceNotFound(asyncResp->res, "VirtualMedia", resName);
-            },
-            service, "/xyz/openbmc_project/VirtualMedia",
-            "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+            });
         });
 }