entity_association_tree: Keep tree always updated

This commit keeps the entity association tree updated across Host
reboots. It deletes the Host entries from the entity associaton
tree when Host is powered off.

Without this fix the entity association tree keeps on growing with
duplicate Host entries during each power on(PDR exchange) resulting
a crash of pldm daemon after few power on-off sequence

Change-Id: I8fdc258195aef998d10e33577f3ec98da48b3d40
Signed-off-by: Sampa Misra <sampmisr@in.ibm.com>
diff --git a/libpldmresponder/fru.cpp b/libpldmresponder/fru.cpp
index 1c04a12..ea19806 100644
--- a/libpldmresponder/fru.cpp
+++ b/libpldmresponder/fru.cpp
@@ -110,6 +110,8 @@
     }
 
     pldm_entity_association_pdr_add(entityTree, pdrRepo, false);
+    // save a copy of bmc's entity association tree
+    pldm_entity_association_tree_copy_root(entityTree, bmcEntityTree);
 
     if (table.size())
     {
diff --git a/libpldmresponder/fru.hpp b/libpldmresponder/fru.hpp
index 5ae593a..18c7882 100644
--- a/libpldmresponder/fru.hpp
+++ b/libpldmresponder/fru.hpp
@@ -57,11 +57,14 @@
      *                          for PLDM FRU
      *  @param[in] pdrRepo - opaque pointer to PDR repository
      *  @param[in] entityTree - opaque pointer to the entity association tree
+     *  @param[in] bmcEntityTree - opaque pointer to bmc's entity association
+     *                             tree
      */
     FruImpl(const std::string& configPath, pldm_pdr* pdrRepo,
-            pldm_entity_association_tree* entityTree) :
+            pldm_entity_association_tree* entityTree,
+            pldm_entity_association_tree* bmcEntityTree) :
         parser(configPath),
-        pdrRepo(pdrRepo), entityTree(entityTree)
+        pdrRepo(pdrRepo), entityTree(entityTree), bmcEntityTree(bmcEntityTree)
     {}
 
     /** @brief Total length of the FRU table in bytes, this excludes the pad
@@ -159,6 +162,7 @@
     fru_parser::FruParser parser;
     pldm_pdr* pdrRepo;
     pldm_entity_association_tree* entityTree;
+    pldm_entity_association_tree* bmcEntityTree;
 
     std::map<dbus::ObjectPath, pldm_entity_node*> objToEntityNode{};
 
@@ -187,8 +191,9 @@
 
   public:
     Handler(const std::string& configPath, pldm_pdr* pdrRepo,
-            pldm_entity_association_tree* entityTree) :
-        impl(configPath, pdrRepo, entityTree)
+            pldm_entity_association_tree* entityTree,
+            pldm_entity_association_tree* bmcEntityTree) :
+        impl(configPath, pdrRepo, entityTree, bmcEntityTree)
     {
         handlers.emplace(PLDM_GET_FRU_RECORD_TABLE_METADATA,
                          [this](const pldm_msg* request, size_t payloadLength) {