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/managers.hpp b/redfish-core/lib/managers.hpp
index e8fa14b..376f70c 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -27,13 +27,16 @@
 #include "utils/systemd_utils.hpp"
 #include "utils/time_utils.hpp"
 
+#include <boost/system/error_code.hpp>
 #include <sdbusplus/asio/property.hpp>
 #include <sdbusplus/unpack_properties.hpp>
 
 #include <algorithm>
+#include <array>
 #include <cstdint>
 #include <memory>
 #include <sstream>
+#include <string_view>
 #include <variant>
 
 namespace redfish
@@ -1177,9 +1180,13 @@
         std::shared_ptr<GetPIDValues> self = shared_from_this();
 
         // get all configurations
-        crow::connections::systemBus->async_method_call(
+        constexpr std::array<std::string_view, 4> interfaces = {
+            pidConfigurationIface, pidZoneConfigurationIface,
+            objectManagerIface, stepwiseConfigurationIface};
+        dbus::utility::getSubTree(
+            "/", 0, interfaces,
             [self](
-                const boost::system::error_code ec,
+                const boost::system::error_code& ec,
                 const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) {
             if (ec)
             {
@@ -1188,18 +1195,15 @@
                 return;
             }
             self->complete.subtree = subtreeLocal;
-            },
-            "xyz.openbmc_project.ObjectMapper",
-            "/xyz/openbmc_project/object_mapper",
-            "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0,
-            std::array<const char*, 4>{
-                pidConfigurationIface, pidZoneConfigurationIface,
-                objectManagerIface, stepwiseConfigurationIface});
+            });
 
         // at the same time get the selected profile
-        crow::connections::systemBus->async_method_call(
+        constexpr std::array<std::string_view, 1> thermalModeIfaces = {
+            thermalModeIface};
+        dbus::utility::getSubTree(
+            "/", 0, thermalModeIfaces,
             [self](
-                const boost::system::error_code ec,
+                const boost::system::error_code& ec,
                 const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) {
             if (ec || subtreeLocal.empty())
             {
@@ -1252,11 +1256,7 @@
                 self->complete.currentProfile = *current;
                 self->complete.supportedProfiles = *supported;
                 });
-            },
-            "xyz.openbmc_project.ObjectMapper",
-            "/xyz/openbmc_project/object_mapper",
-            "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0,
-            std::array<const char*, 1>{thermalModeIface});
+            });
     }
 
     static void
@@ -1414,8 +1414,11 @@
             "GetManagedObjects");
 
         // at the same time get the profile information
-        crow::connections::systemBus->async_method_call(
-            [self](const boost::system::error_code ec,
+        constexpr std::array<std::string_view, 1> thermalModeIfaces = {
+            thermalModeIface};
+        dbus::utility::getSubTree(
+            "/", 0, thermalModeIfaces,
+            [self](const boost::system::error_code& ec,
                    const dbus::utility::MapperGetSubTreeResponse& subtree) {
             if (ec || subtree.empty())
             {
@@ -1467,11 +1470,7 @@
                 self->profileConnection = owner;
                 self->profilePath = path;
                 });
-            },
-            "xyz.openbmc_project.ObjectMapper",
-            "/xyz/openbmc_project/object_mapper",
-            "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0,
-            std::array<const char*, 1>{thermalModeIface});
+            });
     }
     void pidSetDone()
     {
@@ -2076,9 +2075,12 @@
                 });
         }
 
-        crow::connections::systemBus->async_method_call(
+        constexpr std::array<std::string_view, 1> interfaces = {
+            "xyz.openbmc_project.Inventory.Item.Bmc"};
+        dbus::utility::getSubTree(
+            "/xyz/openbmc_project/inventory", 0, interfaces,
             [asyncResp](
-                const boost::system::error_code ec,
+                const boost::system::error_code& ec,
                 const dbus::utility::MapperGetSubTreeResponse& subtree) {
             if (ec)
             {
@@ -2181,13 +2183,7 @@
                     getLocation(asyncResp, connectionName, path);
                 }
             }
-            },
-            "xyz.openbmc_project.ObjectMapper",
-            "/xyz/openbmc_project/object_mapper",
-            "xyz.openbmc_project.ObjectMapper", "GetSubTree",
-            "/xyz/openbmc_project/inventory", int32_t(0),
-            std::array<const char*, 1>{
-                "xyz.openbmc_project.Inventory.Item.Bmc"});
+            });
         });
 
     BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/")