Update mergeEntityAssociations logic

- The intent behind this commit is to update the logic of
  the mergeEntityAssociations method.

- When we extract PDRs data to vector<entities>, according to
  DSP0248_1.2.0 Table 94, the first element in vector is
  `Container Entity`, and the others are `Contained Entity`.
  Therefore, for Contained Entity, their parent must be the first
  element(Container Entity), which does not need to be obtained from
  the getParent method, and only the first element Container Entity
  needs to be obtained from the getParent method(hosts-fru.json).

  This commit is dependant on the libpldm changes:
  https://gerrit.openbmc.org/c/openbmc/libpldm/+/60584

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I117a4fc465c8daabd72d5826fef788a03900e975
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index bcd3928..9409b30 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -55,6 +55,7 @@
     stateSensorHandler(eventsJsonsDir), entityTree(entityTree),
     bmcEntityTree(bmcEntityTree), instanceIdDb(instanceIdDb), handler(handler)
 {
+    mergedHostParents = false;
     fs::path hostFruJson(fs::path(HOST_JSONS_DIR) / fruJson);
     if (fs::exists(hostFruJson))
     {
@@ -115,6 +116,7 @@
                                                        entityTree);
                 this->sensorMap.clear();
                 this->responseReceived = false;
+                this->mergedHostParents = false;
             }
         }
         });
@@ -203,18 +205,6 @@
     }
     return PLDM_SUCCESS;
 }
-bool HostPDRHandler::getParent(EntityType type, pldm_entity& parent)
-{
-    auto found = parents.find(type);
-    if (found != parents.end())
-    {
-        parent.entity_type = found->second.entity_type;
-        parent.entity_instance_num = found->second.entity_instance_num;
-        return true;
-    }
-
-    return false;
-}
 
 void HostPDRHandler::mergeEntityAssociations(const std::vector<uint8_t>& pdr)
 {
@@ -226,21 +216,33 @@
 
     pldm_entity_association_pdr_extract(pdr.data(), pdr.size(), &numEntities,
                                         &entities);
-    for (size_t i = 0; i < numEntities; ++i)
+    if (numEntities > 0)
     {
-        pldm_entity parent{};
-        if (getParent(entities[i].entity_type, parent))
+        pldm_entity_node* pNode = nullptr;
+        if (!mergedHostParents)
         {
-            auto node = pldm_entity_association_tree_find_with_locality(
-                entityTree, &parent, true);
-            if (node)
-            {
-                pldm_entity_association_tree_add_entity(
-                    entityTree, &entities[i], 0xFFFF, node,
-                    entityPdr->association_type, false, true, 0xFFFF);
-                merged = true;
-            }
+            pNode = pldm_entity_association_tree_find_with_locality(
+                entityTree, &entities[0], false);
         }
+        else
+        {
+            pNode = pldm_entity_association_tree_find_with_locality(
+                entityTree, &entities[0], true);
+        }
+        if (!pNode)
+        {
+            return;
+        }
+
+        for (size_t i = 1; i < numEntities; ++i)
+        {
+            pldm_entity_association_tree_add_entity(
+                entityTree, &entities[i], entities[i].entity_instance_num,
+                pNode, entityPdr->association_type, true, true, 0xFFFF);
+            merged = true;
+        }
+
+        mergedHostParents = true;
     }
 
     if (merged)
diff --git a/host-bmc/host_pdr_handler.hpp b/host-bmc/host_pdr_handler.hpp
index 15ce1ac..facfeb1 100644
--- a/host-bmc/host_pdr_handler.hpp
+++ b/host-bmc/host_pdr_handler.hpp
@@ -184,14 +184,6 @@
      */
     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 process the Host's PDR and add to BMC's PDR repo
      *  @param[in] eid - MCTP id of Host
      *  @param[in] response - response from Host for GetPDR
@@ -264,6 +256,17 @@
 
     /** @brief whether response received from Host */
     bool responseReceived;
+
+    /** @brief variable that captures if the first entity association PDR
+     *         from host is merged into the BMC tree
+     */
+    bool mergedHostParents;
+
+    /** @brief whether timed out waiting for a response from Host */
+    bool timeOut;
+
+    /** @brief request message instance id */
+    uint8_t insId;
 };
 
 } // namespace pldm