host-bmc: handle PDR repo change event from remote endpoint

When the PDR repository change event is initiated with the
event data operation as RECORDS_DELETED, we need to delete the
PDRs from the repository based on the record handles.

Change-Id: Ia484b7a0465169bc471f93bda0baa3c4b8ed5f63
Signed-off-by: Pavithra Barithaya <pavithrabarithaya07@gmail.com>
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index 079c6dc..de828ec 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -1228,4 +1228,17 @@
     getFRURecordTableMetadataByRemote(fruRecordSetPDRs);
 }
 
+void HostPDRHandler::deletePDRFromRepo(PDRRecordHandles&& recordHandles)
+{
+    for (auto& recordHandle : recordHandles)
+    {
+        int rc = pldm_pdr_delete_by_record_handle(repo, recordHandle, true);
+        if (rc)
+        {
+            error("Failed to delete the record handle: {REC_HANDLE}",
+                  "REC_HANDLE", recordHandle);
+        }
+    }
+}
+
 } // namespace pldm
diff --git a/host-bmc/host_pdr_handler.hpp b/host-bmc/host_pdr_handler.hpp
index 87da96c..8c97693 100644
--- a/host-bmc/host_pdr_handler.hpp
+++ b/host-bmc/host_pdr_handler.hpp
@@ -104,6 +104,12 @@
 
     void fetchPDR(PDRRecordHandles&& recordHandles);
 
+    /** @brief delete PDRs from remote pldm endpoint.
+     *  @param[in] recordHandles - list of record handles pointing to remote
+     *             PDRs that need to be deleted.
+     */
+    void deletePDRFromRepo(PDRRecordHandles&& recordHandles);
+
     /** @brief Send a PLDM event to host firmware containing a list of record
      *  handles of PDRs that the host firmware has to fetch.
      *  @param[in] pdrTypes - list of PDR types that need to be looked up in the
diff --git a/libpldmresponder/platform.cpp b/libpldmresponder/platform.cpp
index 7a3b63c..5ffc572 100644
--- a/libpldmresponder/platform.cpp
+++ b/libpldmresponder/platform.cpp
@@ -524,6 +524,7 @@
     uint8_t tid, size_t eventDataOffset)
 {
     uint8_t eventDataFormat{};
+    uint8_t eventDataOperation{};
     uint8_t numberOfChangeRecords{};
     size_t dataOffset{};
 
@@ -548,7 +549,6 @@
 
     if (eventDataFormat == FORMAT_IS_PDR_HANDLES)
     {
-        uint8_t eventDataOperation{};
         uint8_t numberOfChangeEntries{};
 
         auto changeRecordData = eventData + dataOffset;
@@ -613,7 +613,14 @@
                 }
             }
         }
-        hostPDRHandler->fetchPDR(std::move(pdrRecordHandles));
+        if (eventDataOperation == PLDM_RECORDS_DELETED)
+        {
+            hostPDRHandler->deletePDRFromRepo(std::move(pdrRecordHandles));
+        }
+        else
+        {
+            hostPDRHandler->fetchPDR(std::move(pdrRecordHandles));
+        }
     }
 
     return PLDM_SUCCESS;