oem-ibm: Add util API to get the connector object paths
This commit adds a common API to find all the port object paths
if present under a connected adapter.
Change-Id: I340838570a3c5add02ef92ecac3df9278b0faffb
Signed-off-by: Pavithra Barithaya <pavithrabarithaya07@gmail.com>
diff --git a/oem/ibm/libpldmresponder/utils.cpp b/oem/ibm/libpldmresponder/utils.cpp
index 5e8658f..05978b4 100644
--- a/oem/ibm/libpldmresponder/utils.cpp
+++ b/oem/ibm/libpldmresponder/utils.cpp
@@ -10,6 +10,8 @@
#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Inventory/Decorator/Asset/client.hpp>
+#include <xyz/openbmc_project/Inventory/Item/Connector/client.hpp>
+#include <xyz/openbmc_project/ObjectMapper/client.hpp>
PHOSPHOR_LOG2_USING;
@@ -162,6 +164,26 @@
return false;
}
+std::vector<std::string> findPortObjects(const std::string& adapterObjPath)
+{
+ using ItemConnector =
+ sdbusplus::client::xyz::openbmc_project::inventory::item::Connector<>;
+
+ std::vector<std::string> portObjects;
+ try
+ {
+ portObjects = pldm::utils::DBusHandler().getSubTreePaths(
+ adapterObjPath, 0,
+ std::vector<std::string>({ItemConnector::interface}));
+ }
+ catch (const std::exception& e)
+ {
+ error("No ports under adapter '{ADAPTER_OBJ_PATH}' - {ERROR}.",
+ "ADAPTER_OBJ_PATH", adapterObjPath.c_str(), "ERROR", e);
+ }
+
+ return portObjects;
+}
} // namespace utils
} // namespace responder
} // namespace pldm
diff --git a/oem/ibm/libpldmresponder/utils.hpp b/oem/ibm/libpldmresponder/utils.hpp
index f2e2153..ac7549f 100644
--- a/oem/ibm/libpldmresponder/utils.hpp
+++ b/oem/ibm/libpldmresponder/utils.hpp
@@ -2,6 +2,7 @@
#include <cstdint>
#include <string>
+#include <vector>
namespace pldm
{
@@ -44,6 +45,14 @@
*/
bool checkIfIBMFru(const std::string& objPath);
+/** @brief finds the ports under an adapter
+ *
+ * @param[in] adapterObjPath - D-Bus object path for the adapter
+ *
+ * @return std::vector<std::string> - port object paths
+ */
+std::vector<std::string> findPortObjects(const std::string& adapterObjPath);
+
} // namespace utils
} // namespace responder
} // namespace pldm