common: Add util APIs to find all the effecter IDs and PDRs

This util API is used to find all the effecter IDs based on
the pldm_entity given. Another util API is added to get all
the PDRs based on the entity type.

Change-Id: I4f5b0ca05dfbad641f1ecfbaec5ebf63f54e500d
Signed-off-by: Pavithra Barithaya <pavithrabarithaya07@gmail.com>
diff --git a/common/types.hpp b/common/types.hpp
index 68d3c3c..18542d9 100644
--- a/common/types.hpp
+++ b/common/types.hpp
@@ -187,6 +187,7 @@
 using SensorOffset = uint8_t;
 using EventState = uint8_t;
 using TerminusValidity = uint8_t;
+using EffecterID = uint16_t;
 
 //!< Subset of the State Set that is supported by a effecter/sensor
 using PossibleStates = std::set<uint8_t>;
diff --git a/common/utils.cpp b/common/utils.cpp
index 80e1401..06ae48b 100644
--- a/common/utils.cpp
+++ b/common/utils.cpp
@@ -868,5 +868,47 @@
     return sensorIDs;
 }
 
+EffecterPDRs getStateEffecterPDRsByType(uint16_t entityType,
+                                        const pldm_pdr* repo)
+{
+    uint8_t* outData = nullptr;
+    uint32_t size{};
+    const pldm_pdr_record* record = nullptr;
+    EffecterPDRs pdrs;
+    if (repo)
+    {
+        while ((record = pldm_pdr_find_record_by_type(
+                    repo, PLDM_STATE_EFFECTER_PDR, record, &outData, &size)))
+        {
+            auto pdr = new (outData) pldm_state_effecter_pdr;
+            if (pdr && pdr->entity_type == entityType)
+            {
+                pdrs.emplace_back(outData, outData + size);
+            }
+        }
+    }
+    return pdrs;
+}
+
+std::vector<pldm::pdr::EffecterID> findEffecterIds(
+    const pldm_pdr* pdrRepo, uint16_t entityType, uint16_t entityInstance,
+    uint16_t containerId)
+{
+    std::vector<uint16_t> effecterIDs;
+    auto pdrs = getStateEffecterPDRsByType(entityType, pdrRepo);
+    for (const auto& pdr : pdrs)
+    {
+        auto effecterPdr =
+            reinterpret_cast<const pldm_state_effecter_pdr*>(pdr.data());
+        if (effecterPdr && effecterPdr->entity_type == entityType &&
+            effecterPdr->entity_instance == entityInstance &&
+            effecterPdr->container_id == containerId)
+        {
+            effecterIDs.emplace_back(effecterPdr->effecter_id);
+        }
+    }
+    return effecterIDs;
+}
+
 } // namespace utils
 } // namespace pldm
diff --git a/common/utils.hpp b/common/utils.hpp
index b2b5c3c..23db119 100644
--- a/common/utils.hpp
+++ b/common/utils.hpp
@@ -205,6 +205,8 @@
 
 using SensorPDR = std::vector<uint8_t>;
 using SensorPDRs = std::vector<SensorPDR>;
+using EffecterPDR = std::vector<uint8_t>;
+using EffecterPDRs = std::vector<EffecterPDR>;
 
 /**
  * @brief The interface for DBusHandler
@@ -536,6 +538,29 @@
     const pldm_pdr* pdrRepo, uint16_t entityType, uint16_t entityInstance,
     uint16_t containerId);
 
+/** @brief Method to find all state effecter PDRs by type
+ *
+ *  @param[in] entityType - the entity type
+ *  @param[in] repo - opaque pointer acting as a PDR repo handle
+ *
+ *  @return vector of vector of all state effecter PDRs
+ */
+EffecterPDRs getStateEffecterPDRsByType(uint16_t entityType,
+                                        const pldm_pdr* repo);
+
+/** @brief method to find effecter IDs based on the pldm_entity
+ *
+ *  @param[in] pdrRepo - opaque pointer acting as a PDR repo handle
+ *  @param[in] entityType - the entity type
+ *  @param[in] entityInstance - the entity instance number
+ *  @param[in] containerId - the container ID
+ *
+ *  @return vector of all effecter IDs
+ */
+std::vector<pldm::pdr::EffecterID> findEffecterIds(
+    const pldm_pdr* pdrRepo, uint16_t entityType, uint16_t entityInstance,
+    uint16_t containerId);
+
 /** @brief Emit the sensor event signal
  *
  *	@param[in] tid - the terminus id