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/power.hpp b/redfish-core/lib/power.hpp
index 33aefa3..88f6a0c 100644
--- a/redfish-core/lib/power.hpp
+++ b/redfish-core/lib/power.hpp
@@ -16,15 +16,18 @@
 */
 #pragma once
 
+#include "dbus_utility.hpp"
 #include "sensors.hpp"
 #include "utils/chassis_utils.hpp"
 
 #include <app.hpp>
-#include <dbus_utility.hpp>
 #include <query.hpp>
 #include <registries/privilege_registry.hpp>
 #include <sdbusplus/asio/property.hpp>
 
+#include <array>
+#include <string_view>
+
 namespace redfish
 {
 inline void setPowerCapOverride(
@@ -144,7 +147,7 @@
 
         using Mapper = dbus::utility::MapperGetSubTreePathsResponse;
         auto chassisHandler =
-            [sensorAsyncResp](const boost::system::error_code e,
+            [sensorAsyncResp](const boost::system::error_code& e,
                               const Mapper& chassisPaths) {
             if (e)
             {
@@ -273,6 +276,9 @@
                     }
                 }
 
+                nlohmann::json& value =
+                    sensorJson["PowerLimit"]["LimitInWatts"];
+
                 // LimitException is Mandatory attribute as per OCP
                 // Baseline Profile – v1.0.0, so currently making it
                 // "NoAction" as default value to make it OCP Compliant.
@@ -282,12 +288,7 @@
                 {
                     // Redfish specification indicates PowerLimit should
                     // be null if the limit is not enabled.
-                    sensorJson["PowerLimit"]["LimitInWatts"] =
-                        powerCap * std::pow(10, scale);
-                }
-                else
-                {
-                    sensorJson["PowerLimit"]["LimitInWatts"] = nullptr;
+                    value = powerCap * std::pow(10, scale);
                 }
             };
 
@@ -298,14 +299,12 @@
                 std::move(valueHandler));
         };
 
-        crow::connections::systemBus->async_method_call(
-            std::move(chassisHandler), "xyz.openbmc_project.ObjectMapper",
-            "/xyz/openbmc_project/object_mapper",
-            "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
-            "/xyz/openbmc_project/inventory", 0,
-            std::array<const char*, 2>{
-                "xyz.openbmc_project.Inventory.Item.Board",
-                "xyz.openbmc_project.Inventory.Item.Chassis"});
+        constexpr std::array<std::string_view, 2> interfaces = {
+            "xyz.openbmc_project.Inventory.Item.Board",
+            "xyz.openbmc_project.Inventory.Item.Chassis"};
+
+        dbus::utility::getSubTreePaths("/xyz/openbmc_project/inventory", 0,
+                                       interfaces, std::move(chassisHandler));
         });
 
     BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Power/")