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/include/dbus_utility.hpp b/include/dbus_utility.hpp
index 393ffe3..c7fda6d 100644
--- a/include/dbus_utility.hpp
+++ b/include/dbus_utility.hpp
@@ -29,6 +29,7 @@
#include <span>
#include <sstream>
#include <string>
+#include <string_view>
#include <tuple>
#include <utility>
#include <variant>
@@ -157,7 +158,8 @@
}
inline void getSubTreePaths(
- const std::string& path, std::span<std::string> interfaces,
+ const std::string& path, int32_t depth,
+ std::span<const std::string_view> interfaces,
std::function<void(const boost::system::error_code&,
const MapperGetSubTreePathsResponse&)>&& callback)
{
@@ -169,7 +171,7 @@
},
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", path, 0,
+ "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", path, depth,
interfaces);
}
diff --git a/include/google/google_service_root.hpp b/include/google/google_service_root.hpp
index d802d00..f14cffe 100644
--- a/include/google/google_service_root.hpp
+++ b/include/google/google_service_root.hpp
@@ -9,6 +9,8 @@
#include <utils/hex_utils.hpp>
#include <utils/json_utils.hpp>
+#include <array>
+#include <string_view>
#include <vector>
namespace crow
@@ -37,9 +39,11 @@
asyncResp->res.jsonValue["@odata.id"] = "/google/v1/RootOfTrustCollection";
asyncResp->res.jsonValue["@odata.type"] =
"#RootOfTrustCollection.RootOfTrustCollection";
+ const std::array<std::string_view, 1> interfaces{
+ "xyz.openbmc_project.Control.Hoth"};
redfish::collection_util::getCollectionMembers(
asyncResp, boost::urls::url("/google/v1/RootOfTrustCollection"),
- {"xyz.openbmc_project.Control.Hoth"}, "/xyz/openbmc_project");
+ interfaces, "/xyz/openbmc_project");
}
// Helper struct to identify a resolved D-Bus object interface
@@ -94,7 +98,7 @@
ResolvedEntityHandler&& entityHandler)
{
- std::array<std::string, 1> hothIfaces = {
+ constexpr std::array<std::string_view, 1> hothIfaces = {
"xyz.openbmc_project.Control.Hoth"};
crow::connections::systemBus->async_method_call(
[command, asyncResp, rotId,
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 2cb2bc3..c7dbb27 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -13,6 +13,7 @@
// limitations under the License.
#pragma once
+#include "dbus_utility.hpp"
#include "http_request.hpp"
#include "http_response.hpp"
#include "logging.hpp"
@@ -1640,9 +1641,10 @@
inline void handleList(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& objectPath, int32_t depth = 0)
{
- crow::connections::systemBus->async_method_call(
+ dbus::utility::getSubTreePaths(
+ objectPath, depth, {},
[asyncResp](
- const boost::system::error_code ec,
+ const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreePathsResponse& objectPaths) {
if (ec)
{
@@ -1656,11 +1658,7 @@
asyncResp->res.jsonValue["message"] = "200 OK";
asyncResp->res.jsonValue["data"] = objectPaths;
}
- },
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", objectPath,
- depth, std::array<std::string, 0>());
+ });
}
inline void handleEnumerate(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,