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/log_services.hpp b/redfish-core/lib/log_services.hpp
index 307f2e2..e5beb32 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -15,6 +15,7 @@
 */
 #pragma once
 
+#include "dbus_utility.hpp"
 #include "gzfile.hpp"
 #include "http_utility.hpp"
 #include "human_sort.hpp"
@@ -35,7 +36,6 @@
 #include <boost/beast/http/verb.hpp>
 #include <boost/container/flat_map.hpp>
 #include <boost/system/linux_error.hpp>
-#include <dbus_utility.hpp>
 #include <error_messages.hpp>
 #include <query.hpp>
 #include <registries/privilege_registry.hpp>
@@ -44,6 +44,7 @@
 #include <utils/dbus_utils.hpp>
 #include <utils/time_utils.hpp>
 
+#include <array>
 #include <charconv>
 #include <filesystem>
 #include <optional>
@@ -973,10 +974,13 @@
 {
     std::string dumpTypeLowerCopy =
         std::string(boost::algorithm::to_lower_copy(dumpType));
+    std::string interface = "xyz.openbmc_project.Dump.Entry." + dumpType;
+    const std::array<const std::string_view, 1> interfaces{interface};
 
-    crow::connections::systemBus->async_method_call(
+    dbus::utility::getSubTreePaths(
+        "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0, interfaces,
         [asyncResp, dumpType](
-            const boost::system::error_code ec,
+            const boost::system::error_code& ec,
             const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) {
         if (ec)
         {
@@ -995,13 +999,7 @@
             }
             deleteDumpEntry(asyncResp, logID, dumpType);
         }
-        },
-        "xyz.openbmc_project.ObjectMapper",
-        "/xyz/openbmc_project/object_mapper",
-        "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
-        "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0,
-        std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." +
-                                   dumpType});
+        });
 }
 
 inline static void
@@ -1038,7 +1036,6 @@
     }
 }
 
-constexpr char const* postCodeIface = "xyz.openbmc_project.State.Boot.PostCode";
 inline void requestRoutesSystemLogServiceCollection(App& app)
 {
     /**
@@ -1098,8 +1095,11 @@
         asyncResp->res.jsonValue["Members@odata.count"] =
             logServiceArray.size();
 
-        crow::connections::systemBus->async_method_call(
-            [asyncResp](const boost::system::error_code ec,
+        constexpr std::array<std::string_view, 1> interfaces = {
+            "xyz.openbmc_project.State.Boot.PostCode"};
+        dbus::utility::getSubTreePaths(
+            "/", 0, interfaces,
+            [asyncResp](const boost::system::error_code& ec,
                         const dbus::utility::MapperGetSubTreePathsResponse&
                             subtreePath) {
             if (ec)
@@ -1125,11 +1125,7 @@
                     return;
                 }
             }
-            },
-            "xyz.openbmc_project.ObjectMapper",
-            "/xyz/openbmc_project/object_mapper",
-            "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", 0,
-            std::array<const char*, 1>{postCodeIface});
+            });
         });
 }
 
@@ -2257,8 +2253,6 @@
         });
 }
 
-constexpr char const* dumpManagerIface =
-    "xyz.openbmc_project.Collection.DeleteAll";
 inline void handleBMCLogServicesCollectionGet(
     crow::App& app, const crow::Request& req,
     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
@@ -2288,9 +2282,12 @@
     asyncResp->res.jsonValue["Members@odata.count"] = logServiceArray.size();
 
 #ifdef BMCWEB_ENABLE_REDFISH_DUMP_LOG
-    auto respHandler =
+    const std::array<const char*, 1> interfaces = {
+        "xyz.openbmc_project.Collection.DeleteAll"};
+    dbus::utility::getSubTreePaths(
+        "/xyz/openbmc_project/dump", 0, interfaces,
         [asyncResp](
-            const boost::system::error_code ec,
+            const boost::system::error_code& ec,
             const dbus::utility::MapperGetSubTreePathsResponse& subTreePaths) {
         if (ec)
         {
@@ -2325,14 +2322,7 @@
 
         asyncResp->res.jsonValue["Members@odata.count"] =
             logServiceArrayLocal.size();
-    };
-
-    crow::connections::systemBus->async_method_call(
-        respHandler, "xyz.openbmc_project.ObjectMapper",
-        "/xyz/openbmc_project/object_mapper",
-        "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
-        "/xyz/openbmc_project/dump", 0,
-        std::array<const char*, 1>{dumpManagerIface});
+        });
 #endif
 }
 
@@ -3155,8 +3145,11 @@
             return;
         }
 
-        crow::connections::systemBus->async_method_call(
-            [asyncResp](const boost::system::error_code ec,
+        constexpr std::array<std::string_view, 1> interfaces = {
+            crashdumpInterface};
+        dbus::utility::getSubTreePaths(
+            "/", 0, interfaces,
+            [asyncResp](const boost::system::error_code& ec,
                         const std::vector<std::string>& resp) {
             if (ec)
             {
@@ -3192,11 +3185,7 @@
                 logCrashdumpEntry(asyncResp, logID,
                                   asyncResp->res.jsonValue["Members"]);
             }
-            },
-            "xyz.openbmc_project.ObjectMapper",
-            "/xyz/openbmc_project/object_mapper",
-            "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "", 0,
-            std::array<const char*, 1>{crashdumpInterface});
+            });
         });
 }