mapper: use async client for GetSubTreePaths
Use the generated client bindings instead of hard-coding strings for
function names and parameters.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Ica2c6f29961a81a484548a8f74634067c53cec3d
diff --git a/health_monitor.cpp b/health_monitor.cpp
index 0c732b0..36d027e 100644
--- a/health_monitor.cpp
+++ b/health_monitor.cpp
@@ -2,6 +2,8 @@
#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/async.hpp>
+#include <xyz/openbmc_project/Inventory/Item/Bmc/common.hpp>
+#include <xyz/openbmc_project/Inventory/Item/common.hpp>
PHOSPHOR_LOG2_USING;
@@ -14,8 +16,12 @@
{
info("Creating Health Monitor with config size {SIZE}", "SIZE",
configs.size());
- constexpr auto BMCInventoryItem = "xyz.openbmc_project.Inventory.Item.Bmc";
- auto bmcPaths = findPaths(ctx.get_bus(), BMCInventoryItem);
+
+ static constexpr auto bmcIntf = sdbusplus::common::xyz::openbmc_project::
+ inventory::item::Bmc::interface;
+ static constexpr auto invPath = sdbusplus::common::xyz::openbmc_project::
+ inventory::Item::namespace_path;
+ auto bmcPaths = co_await findPaths(ctx, bmcIntf, invPath);
for (auto& [type, collectionConfig] : configs)
{
diff --git a/health_utils.cpp b/health_utils.cpp
index a60db8b..474a04d 100644
--- a/health_utils.cpp
+++ b/health_utils.cpp
@@ -1,6 +1,7 @@
#include "health_utils.hpp"
#include <phosphor-logging/lg2.hpp>
+#include <xyz/openbmc_project/ObjectMapper/client.hpp>
PHOSPHOR_LOG2_USING;
@@ -20,29 +21,27 @@
bus.call_noreply(msg);
}
-auto findPaths(sdbusplus::bus_t& bus, const std::string& iface) -> paths_t
+auto findPaths(sdbusplus::async::context& ctx, const std::string& iface,
+ const std::string& subpath) -> sdbusplus::async::task<paths_t>
{
- sdbusplus::message_t msg = bus.new_method_call(
- "xyz.openbmc_project.ObjectMapper",
- "/xyz/openbmc_project/object_mapper",
- "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths");
- const char* inventoryPath = "/xyz/openbmc_project/inventory";
-
- msg.append("/", 0, std::vector<std::string>{iface});
-
try
{
- auto paths = bus.call(msg, int32_t(0)).unpack<paths_t>();
- debug("Found {COUNT} paths for {IFACE}", "COUNT", paths.size(), "IFACE",
- iface);
- return paths;
+ using ObjectMapper =
+ sdbusplus::client::xyz::openbmc_project::ObjectMapper<>;
+
+ auto mapper = ObjectMapper(ctx)
+ .service(ObjectMapper::default_service)
+ .path(ObjectMapper::instance_path);
+
+ std::vector<std::string> ifaces = {iface};
+ co_return co_await mapper.get_sub_tree_paths(subpath, 0, ifaces);
}
catch (std::exception& e)
{
error("Exception occurred for GetSubTreePaths for {PATH}: {ERROR}",
- "PATH", inventoryPath, "ERROR", e);
+ "PATH", subpath, "ERROR", e);
}
- return {};
+ co_return {};
}
} // namespace phosphor::health::utils
diff --git a/health_utils.hpp b/health_utils.hpp
index ded0159..7a924e5 100644
--- a/health_utils.hpp
+++ b/health_utils.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <sdbusplus/async.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/sdbus.hpp>
@@ -13,6 +14,7 @@
/** @brief Start a systemd unit */
void startUnit(sdbusplus::bus_t& bus, const std::string& sysdUnit);
/** @brief Find D-Bus paths for given interface */
-auto findPaths(sdbusplus::bus_t& bus, const std::string& iface) -> paths_t;
+auto findPaths(sdbusplus::async::context& ctx, const std::string& iface,
+ const std::string& subpath) -> sdbusplus::async::task<paths_t>;
} // namespace phosphor::health::utils