event: Handling pldmPDRRepositoryChgEvent

Added a handler to react to the "pldmPDRRepositoryChgEvent" event and
extract the data. If the eventDataFormat is "formatIsPDRHandles" then
the changeRecords are further extracted. If the eventDataOperation is
"recordAdded" then the PDRHandles are extracted from the changeEntry
data and stored in the "pdrRecordHandle" vector.

"decode_pldm_pdr_repository_chg_event_data" function will extract the
eventData and changeRecord from the pldmPDRRepositoryChgEvent class
while the "decode_pldm_pdr_repository_change_record_data" will extract
the changeEntries data from the changeRecord. Unit tests for the above
decode functions have been added.

Extracted PDR handles are used to fetch PDRs corresponding to the same
from the host.

Signed-off-by: Zahed Hossain <zahzahed@in.ibm.com>
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Change-Id: I32e8745e04ac82393e067c0f0ab48802809495a6
diff --git a/host_pdr_handler.hpp b/host_pdr_handler.hpp
index b590e7c..dc5462f 100644
--- a/host_pdr_handler.hpp
+++ b/host_pdr_handler.hpp
@@ -3,7 +3,9 @@
 #include "dbus_impl_requester.hpp"
 #include "utils.hpp"
 
+#include <memory>
 #include <sdeventplus/event.hpp>
+#include <sdeventplus/source/event.hpp>
 #include <vector>
 
 #include "libpldm/base.h"
@@ -14,6 +16,11 @@
 namespace pldm
 {
 
+// vector which would hold the PDR record handle data returned by
+// pldmPDRRepositoryChgEvent event data
+using ChangeEntry = uint32_t;
+using PDRRecordHandles = std::vector<ChangeEntry>;
+
 /** @class HostPDRHandler
  *  @brief This class can fetch and process PDRs from host firmware
  *  @details Provides an API to fetch PDRs from the host firmware. Upon
@@ -52,9 +59,15 @@
      *  @param[in] recordHandles - list of record handles pointing to host's
      *             PDRs that need to be fetched.
      */
-    void fetchPDR(const std::vector<uint32_t>& recordHandles);
+    void fetchPDR(std::vector<uint32_t>&& recordHandles);
 
   private:
+    /** @brief fetchPDR schedules work on the event loop, this method does the
+     *  actual work. This is so that the PDR exchg with the host is async.
+     *  @param[in] source - sdeventplus event source
+     */
+    void _fetchPDR(sdeventplus::source::EventBase& source);
+
     /** @brief fd of MCTP communications socket */
     int mctp_fd;
     /** @brief MCTP EID of host firmware */
@@ -69,6 +82,10 @@
      *  obtain PLDM instance id.
      */
     Requester& requester;
+    /** @brief sdeventplus event source */
+    std::unique_ptr<sdeventplus::source::Defer> pdrFetchEvent;
+    /** @brief list of PDR record handles pointing to host's PDRs */
+    PDRRecordHandles pdrRecordHandles;
 };
 
 } // namespace pldm