common: utils: Add get ancestors mapper function
Add get ancestors mapper function. A use case is getting an inventory
item's parent path for its board or chassis.
Change-Id: I7a25c8e11f7662fd07147b7da3b8db9fbff5e00e
Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
diff --git a/common/utils.cpp b/common/utils.cpp
index 6f39321..a5792f5 100644
--- a/common/utils.cpp
+++ b/common/utils.cpp
@@ -279,6 +279,21 @@
return paths;
}
+GetAncestorsResponse
+ DBusHandler::getAncestors(const std::string& searchPath,
+ const std::vector<std::string>& ifaceList) const
+{
+ auto& bus = pldm::utils::DBusHandler::getBus();
+ auto method = bus.new_method_call(ObjectMapper::default_service,
+ ObjectMapper::instance_path,
+ ObjectMapper::interface, "GetAncestors");
+ method.append(searchPath, ifaceList);
+ auto reply = bus.call(method, dbusTimeout);
+ GetAncestorsResponse response;
+ reply.read(response);
+ return response;
+}
+
void reportError(const char* errorMsg)
{
auto& bus = pldm::utils::DBusHandler::getBus();
diff --git a/common/utils.hpp b/common/utils.hpp
index 05dc4bd..bfae329 100644
--- a/common/utils.hpp
+++ b/common/utils.hpp
@@ -194,6 +194,8 @@
using MapperServiceMap = std::vector<std::pair<ServiceName, Interfaces>>;
using GetSubTreeResponse = std::vector<std::pair<ObjectPath, MapperServiceMap>>;
using GetSubTreePathsResponse = std::vector<std::string>;
+using GetAncestorsResponse =
+ std::vector<std::pair<ObjectPath, MapperServiceMap>>;
using PropertyMap = std::map<std::string, PropertyValue>;
using InterfaceMap = std::map<std::string, PropertyMap>;
using ObjectValueTree = std::map<sdbusplus::message::object_path, InterfaceMap>;
@@ -216,6 +218,10 @@
getSubTreePaths(const std::string& objectPath, int depth,
const std::vector<std::string>& ifaceList) const = 0;
+ virtual GetAncestorsResponse
+ getAncestors(const std::string& path,
+ const std::vector<std::string>& ifaceList) const = 0;
+
virtual void setDbusProperty(const DBusMapping& dBusMap,
const PropertyValue& value) const = 0;
@@ -289,6 +295,21 @@
const std::string& objectPath, int depth,
const std::vector<std::string>& ifaceList) const override;
+ /**
+ * @brief Get the Ancestors response from the mapper
+ *
+ * @param[in] path - DBUS object path
+ * @param[in] ifaceList - list of the interface that are being
+ * queried from the mapper
+ *
+ * @return GetAncestorsResponse - the mapper GetAncestors response
+ *
+ * @throw sdbusplus::exception_t when it fails
+ */
+ GetAncestorsResponse
+ getAncestors(const std::string& path,
+ const std::vector<std::string>& ifaceList) const override;
+
/** @brief Get property(type: variant) from the requested dbus
*
* @param[in] objPath - The Dbus object path