PLDM: Handling modified PDRs

This commit handles the PDRs which are modified.
This also prevents the looping of host PDRs when we get
the modified PDR in between the PDR exchange. With this
change we will fetch only the modified PDRs and not all
the PDRs again.

Change-Id: If674f23ce83f44853c74139c9d3c4e5aea05259a
Signed-off-by: Pavithra Barithaya <pavithra.b@ibm.com>
diff --git a/host-bmc/host_pdr_handler.cpp b/host-bmc/host_pdr_handler.cpp
index 0cc8a1a..75d3e61 100644
--- a/host-bmc/host_pdr_handler.cpp
+++ b/host-bmc/host_pdr_handler.cpp
@@ -123,7 +123,16 @@
 void HostPDRHandler::fetchPDR(PDRRecordHandles&& recordHandles)
 {
     pdrRecordHandles.clear();
-    pdrRecordHandles = std::move(recordHandles);
+    modifiedPDRRecordHandles.clear();
+
+    if (isHostPdrModified)
+    {
+        modifiedPDRRecordHandles = std::move(recordHandles);
+    }
+    else
+    {
+        pdrRecordHandles = std::move(recordHandles);
+    }
 
     // Defer the actual fetch of PDRs from the host (by queuing the call on the
     // main event loop). That way, we can respond to the platform event msg from
@@ -146,13 +155,16 @@
                                     PLDM_GET_PDR_REQ_BYTES);
     auto request = reinterpret_cast<pldm_msg*>(requestMsg.data());
     uint32_t recordHandle{};
-    if (!nextRecordHandle)
+    if (!nextRecordHandle && (!modifiedPDRRecordHandles.empty()) &&
+        isHostPdrModified)
     {
-        if (!pdrRecordHandles.empty())
-        {
-            recordHandle = pdrRecordHandles.front();
-            pdrRecordHandles.pop_front();
-        }
+        recordHandle = modifiedPDRRecordHandles.front();
+        modifiedPDRRecordHandles.pop_front();
+    }
+    else if (!nextRecordHandle && (!pdrRecordHandles.empty()))
+    {
+        recordHandle = pdrRecordHandles.front();
+        pdrRecordHandles.pop_front();
     }
     else
     {
@@ -551,10 +563,19 @@
     }
     else
     {
-        deferredFetchPDREvent = std::make_unique<sdeventplus::source::Defer>(
-            event,
-            std::bind(std::mem_fn((&HostPDRHandler::_processFetchPDREvent)),
-                      this, nextRecordHandle, std::placeholders::_1));
+        if (modifiedPDRRecordHandles.empty() && isHostPdrModified)
+        {
+            isHostPdrModified = false;
+        }
+        else
+        {
+            deferredFetchPDREvent =
+                std::make_unique<sdeventplus::source::Defer>(
+                    event,
+                    std::bind(
+                        std::mem_fn((&HostPDRHandler::_processFetchPDREvent)),
+                        this, nextRecordHandle, std::placeholders::_1));
+        }
     }
 }
 
@@ -576,6 +597,11 @@
         nextRecordHandle = this->pdrRecordHandles.front();
         this->pdrRecordHandles.pop_front();
     }
+    if (isHostPdrModified && (!this->modifiedPDRRecordHandles.empty()))
+    {
+        nextRecordHandle = this->modifiedPDRRecordHandles.front();
+        this->modifiedPDRRecordHandles.pop_front();
+    }
     this->getHostPDR(nextRecordHandle);
 }