Add getSubtree utility functions
- Added getSubtree utility function that can returns
the service name & dbus object paths that implement a
particular dbus interface.
Signed-off-by: Manojkiran Eda <manojkiran.eda@gmail.com>
Change-Id: If1faeba285ce4de26d7343ca400f5820736bb3e0
diff --git a/common/utils.cpp b/common/utils.cpp
index 20ff1d4..89b55d1 100644
--- a/common/utils.cpp
+++ b/common/utils.cpp
@@ -231,6 +231,21 @@
return mapperResponse.begin()->first;
}
+GetSubTreeResponse
+ DBusHandler::getSubtree(const std::string& searchPath, int depth,
+ const std::vector<std::string>& ifaceList) const
+{
+
+ auto& bus = pldm::utils::DBusHandler::getBus();
+ auto method = bus.new_method_call(mapperBusName, mapperPath,
+ mapperInterface, "GetSubTree");
+ method.append(searchPath, depth, ifaceList);
+ auto reply = bus.call(method);
+ GetSubTreeResponse response;
+ reply.read(response);
+ return response;
+}
+
void reportError(const char* errorMsg)
{
static constexpr auto logObjPath = "/xyz/openbmc_project/logging";
diff --git a/common/utils.hpp b/common/utils.hpp
index 72170fb..c7c63ef 100644
--- a/common/utils.hpp
+++ b/common/utils.hpp
@@ -145,6 +145,11 @@
std::pair<pldm::dbus::Interface,
std::vector<std::pair<pldm::dbus::Property,
std::variant<pldm::dbus::Property>>>>>;
+using ObjectPath = std::string;
+using ServiceName = std::string;
+using Interfaces = std::vector<std::string>;
+using MapperServiceMap = std::vector<std::pair<ServiceName, Interfaces>>;
+using GetSubTreeResponse = std::vector<std::pair<ObjectPath, MapperServiceMap>>;
/**
* @brief The interface for DBusHandler
@@ -156,6 +161,9 @@
virtual std::string getService(const char* path,
const char* interface) const = 0;
+ virtual GetSubTreeResponse
+ getSubtree(const std::string& path, int depth,
+ const std::vector<std::string>& ifaceList) const = 0;
virtual void setDbusProperty(const DBusMapping& dBusMap,
const PropertyValue& value) const = 0;
@@ -197,6 +205,22 @@
std::string getService(const char* path,
const char* interface) const override;
+ /**
+ * @brief Get the Subtree response from the mapper
+ *
+ * @param[in] path - DBUS object path
+ * @param[in] depth - Search depth
+ * @param[in] ifaceList - list of the interface that are being
+ * queried from the mapper
+ *
+ * @return GetSubTreeResponse - the mapper subtree response
+ *
+ * @throw sdbusplus::exception::exception when it fails
+ */
+ GetSubTreeResponse
+ getSubtree(const std::string& path, int depth,
+ const std::vector<std::string>& ifaceList) const override;
+
/** @brief Get property(type: variant) from the requested dbus
*
* @param[in] objPath - The Dbus object path