Refactor to call the GetSubTree method

Uniformly use the getSubTree method of utils.hpp to obtain objectTree

Signed-off-by: George Liu <liuxiwei@ieisystem.com>
Change-Id: I20204745a01c50f053db74a5749a070bc8193d39
diff --git a/dbus-sdr/sdrutils.cpp b/dbus-sdr/sdrutils.cpp
index e7ed347..fa96c6b 100644
--- a/dbus-sdr/sdrutils.cpp
+++ b/dbus-sdr/sdrutils.cpp
@@ -16,6 +16,7 @@
 
 #include "dbus-sdr/sdrutils.hpp"
 
+#include <ipmid/utils.hpp>
 #include <nlohmann/json.hpp>
 
 #include <fstream>
diff --git a/settings.cpp b/settings.cpp
index e76694f..93eb094 100644
--- a/settings.cpp
+++ b/settings.cpp
@@ -19,30 +19,19 @@
 Objects::Objects(sdbusplus::bus_t& bus, const std::vector<Interface>& filter) :
     bus(bus)
 {
-    auto depth = 0;
-
-    auto mapperCall = bus.new_method_call(mapperService, mapperPath, mapperIntf,
-                                          "GetSubTree");
-    mapperCall.append(root);
-    mapperCall.append(depth);
-    mapperCall.append(filter);
-
-    using Interfaces = std::vector<Interface>;
-    using MapperResponse = std::map<Path, std::map<Service, Interfaces>>;
-    MapperResponse result;
+    ipmi::ObjectTree objectTree;
     try
     {
-        auto response = bus.call(mapperCall);
-        response.read(result);
+        objectTree = ipmi::getSubTree(bus, filter);
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>("Error in mapper GetSubTree",
+        log<level::ERR>("Failed to call the getSubTree method.",
                         entry("ERROR=%s", e.what()));
         elog<InternalFailure>();
     }
 
-    for (auto& iter : result)
+    for (auto& iter : objectTree)
     {
         const auto& path = iter.first;
         for (auto& interface : iter.second.begin()->second)
diff --git a/settings.hpp b/settings.hpp
index 42a8560..66cd3ae 100644
--- a/settings.hpp
+++ b/settings.hpp
@@ -12,8 +12,6 @@
 using Service = std::string;
 using Interface = std::string;
 
-constexpr auto root = "/";
-
 /** @class Objects
  *  @brief Fetch paths of settings d-bus objects of interest, upon construction
  */
diff --git a/transporthandler.cpp b/transporthandler.cpp
index 0c6e4ac..669728e 100644
--- a/transporthandler.cpp
+++ b/transporthandler.cpp
@@ -1,5 +1,6 @@
 #include "transporthandler.hpp"
 
+#include <ipmid/utils.hpp>
 #include <stdplus/net/addr/subnet.hpp>
 #include <stdplus/raw.hpp>
 
@@ -83,13 +84,9 @@
     }
 
     // Enumerate all VLAN + ETHERNET interfaces
-    auto req = bus.new_method_call(MAPPER_BUS_NAME, MAPPER_OBJ, MAPPER_INTF,
-                                   "GetSubTree");
-    req.append(std::string_view(PATH_ROOT), 0,
-               std::vector<std::string>{INTF_VLAN, INTF_ETHERNET});
-    auto reply = bus.call(req);
-    ObjectTree objs;
-    reply.read(objs);
+    std::vector<std::string> interfaces = {INTF_VLAN, INTF_ETHERNET};
+    ipmi::ObjectTree objs = ipmi::getSubTree(bus, interfaces,
+                                             std::string{PATH_ROOT});
 
     ChannelParams params;
     for (const auto& [path, impls] : objs)
@@ -481,13 +478,9 @@
 void deconfigureChannel(sdbusplus::bus_t& bus, ChannelParams& params)
 {
     // Delete all objects associated with the interface
-    auto objreq = bus.new_method_call(MAPPER_BUS_NAME, MAPPER_OBJ, MAPPER_INTF,
-                                      "GetSubTree");
-    objreq.append(std::string_view(PATH_ROOT), 0,
-                  std::vector<std::string>{DELETE_INTERFACE});
-    auto objreply = bus.call(objreq);
-    ObjectTree objs;
-    objreply.read(objs);
+    ObjectTree objs =
+        ipmi::getSubTree(bus, std::vector<std::string>{DELETE_INTERFACE},
+                         std::string{PATH_ROOT});
     for (const auto& [path, impls] : objs)
     {
         if (!ifnameInPath(params.ifname, path))