Merge entity association PDRs

This commit enables merging entity association PDRs from the host into
the BMC's PDR repo. Entities from the host are inserted into the
appropriate location in the entity tree maintained by the BMC.

Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Change-Id: Ie9fa46d9f8512fad6c04069e4fc65785972fbf64
diff --git a/host_pdr_handler.hpp b/host_pdr_handler.hpp
index dc5462f..af1fbab 100644
--- a/host_pdr_handler.hpp
+++ b/host_pdr_handler.hpp
@@ -3,6 +3,7 @@
 #include "dbus_impl_requester.hpp"
 #include "utils.hpp"
 
+#include <map>
 #include <memory>
 #include <sdeventplus/event.hpp>
 #include <sdeventplus/source/event.hpp>
@@ -16,6 +17,7 @@
 namespace pldm
 {
 
+using EntityType = uint16_t;
 // vector which would hold the PDR record handle data returned by
 // pldmPDRRepositoryChgEvent event data
 using ChangeEntry = uint32_t;
@@ -45,15 +47,13 @@
      *  @param[in] mctp_eid - MCTP EID of host firmware
      *  @param[in] event - reference of main event loop of pldmd
      *  @param[in] repo - pointer to BMC's primary PDR repo
+     *  @param[in] tree - pointer to BMC's entity association tree
      *  @param[in] requester - reference to Requester object
      */
     explicit HostPDRHandler(int mctp_fd, uint8_t mctp_eid,
                             sdeventplus::Event& event, pldm_pdr* repo,
-                            Requester& requester) :
-        mctp_fd(mctp_fd),
-        mctp_eid(mctp_eid), event(event), repo(repo), requester(requester)
-    {
-    }
+                            pldm_entity_association_tree* entityTree,
+                            Requester& requester);
 
     /** @brief fetch PDRs from host firmware. See @class.
      *  @param[in] recordHandles - list of record handles pointing to host's
@@ -68,6 +68,21 @@
      */
     void _fetchPDR(sdeventplus::source::EventBase& source);
 
+    /** @brief Merge host firmware's entity association PDRs into BMC's
+     *  @details A merge operation involves adding a pldm_entity under the
+     *  appropriate parent, and updating container ids.
+     *  @param[in] pdr - entity association pdr
+     */
+    void mergeEntityAssociations(const std::vector<uint8_t>& pdr);
+
+    /** @brief Find parent of input entity type, from the entity association
+     *  tree
+     *  @param[in] type - PLDM entity type
+     *  @param[out] parent - PLDM entity information of parent
+     *  @return bool - true if parent found, false otherwise
+     */
+    bool getParent(EntityType type, pldm_entity& parent);
+
     /** @brief fd of MCTP communications socket */
     int mctp_fd;
     /** @brief MCTP EID of host firmware */
@@ -78,6 +93,8 @@
     sdeventplus::Event& event;
     /** @brief pointer to BMC's primary PDR repo, host PDRs are added here */
     pldm_pdr* repo;
+    /** @brief Pointer to BMC's entity association tree */
+    pldm_entity_association_tree* entityTree;
     /** @brief reference to Requester object, primarily used to access API to
      *  obtain PLDM instance id.
      */
@@ -86,6 +103,10 @@
     std::unique_ptr<sdeventplus::source::Defer> pdrFetchEvent;
     /** @brief list of PDR record handles pointing to host's PDRs */
     PDRRecordHandles pdrRecordHandles;
+    /** @brief maps an entity type to parent pldm_entity from the BMC's entity
+     *  association tree
+     */
+    std::map<EntityType, pldm_entity> parents;
 };
 
 } // namespace pldm