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/include/dbus_utility.hpp b/include/dbus_utility.hpp
index c9143de..e953a9f 100644
--- a/include/dbus_utility.hpp
+++ b/include/dbus_utility.hpp
@@ -144,7 +144,8 @@
 }
 
 inline void
-    getSubTree(const std::string& path, std::span<std::string> interfaces,
+    getSubTree(const std::string& path, int32_t depth,
+               std::span<const std::string_view> interfaces,
                std::function<void(const boost::system::error_code&,
                                   const MapperGetSubTreeResponse&)>&& callback)
 {
@@ -154,7 +155,8 @@
             const MapperGetSubTreeResponse& subtree) { callback(ec, subtree); },
         "xyz.openbmc_project.ObjectMapper",
         "/xyz/openbmc_project/object_mapper",
-        "xyz.openbmc_project.ObjectMapper", "GetSubTree", path, 0, interfaces);
+        "xyz.openbmc_project.ObjectMapper", "GetSubTree", path, depth,
+        interfaces);
 }
 
 inline void getSubTreePaths(
diff --git a/include/google/google_service_root.hpp b/include/google/google_service_root.hpp
index 7d48845..fd8aad4 100644
--- a/include/google/google_service_root.hpp
+++ b/include/google/google_service_root.hpp
@@ -8,6 +8,7 @@
 #include "utils/hex_utils.hpp"
 #include "utils/json_utils.hpp"
 
+#include <boost/system/error_code.hpp>
 #include <nlohmann/json.hpp>
 
 #include <array>
@@ -98,22 +99,17 @@
                        const std::string& rotId,
                        ResolvedEntityHandler&& entityHandler)
 {
-
     constexpr std::array<std::string_view, 1> hothIfaces = {
         "xyz.openbmc_project.Control.Hoth"};
-    crow::connections::systemBus->async_method_call(
+    dbus::utility::getSubTree(
+        "/xyz/openbmc_project", 0, hothIfaces,
         [command, asyncResp, rotId,
          entityHandler{std::forward<ResolvedEntityHandler>(entityHandler)}](
-            const boost::system::error_code ec,
+            const boost::system::error_code& ec,
             const dbus::utility::MapperGetSubTreeResponse& subtree) {
         hothGetSubtreeCallback(command, asyncResp, rotId, entityHandler, ec,
                                subtree);
-        },
-        "xyz.openbmc_project.ObjectMapper",
-        "/xyz/openbmc_project/object_mapper",
-        "xyz.openbmc_project.ObjectMapper", "GetSubTree",
-        "/xyz/openbmc_project",
-        /*depth=*/0, hothIfaces);
+        });
 }
 
 inline void populateRootOfTrustEntity(
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 948bc36..8dd7bb4 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -34,6 +34,7 @@
 #include <boost/container/flat_map.hpp>
 #include <boost/container/vector.hpp>
 #include <boost/iterator/iterator_facade.hpp>
+#include <boost/system/error_code.hpp>
 #include <nlohmann/json.hpp>
 #include <sdbusplus/asio/connection.hpp>
 #include <sdbusplus/asio/property.hpp>
@@ -1660,9 +1661,10 @@
     asyncResp->res.jsonValue["status"] = "ok";
     asyncResp->res.jsonValue["data"] = nlohmann::json::object();
 
-    crow::connections::systemBus->async_method_call(
+    dbus::utility::getSubTree(
+        objectPath, 0, {},
         [objectPath, asyncResp](
-            const boost::system::error_code ec,
+            const boost::system::error_code& ec,
             const dbus::utility::MapperGetSubTreeResponse& objectNames) {
         auto transaction =
             std::make_shared<InProgressEnumerateData>(objectPath, asyncResp);
@@ -1684,11 +1686,7 @@
         // Add the data for the path passed in to the results
         // as if GetSubTree returned it, and continue on enumerating
         getObjectAndEnumerate(transaction);
-        },
-        "xyz.openbmc_project.ObjectMapper",
-        "/xyz/openbmc_project/object_mapper",
-        "xyz.openbmc_project.ObjectMapper", "GetSubTree", objectPath, 0,
-        std::array<const char*, 0>());
+        });
 }
 
 inline void handleGet(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,