pldm: Refector PDR repo based on the new PDR APIs

The related APIs for PDR operations is implemented in
pldm/libpldm/pdr.h and pldm/libpldm/pdr.c, we need to use this instead
of pdr::Repo(defined in libpldmresponder/pdr.hpp).
pdr::Repo is now a C++ wrapper around the PDR APIs in libpldm.

Tested with unit tests, with JSON files:
 https://gist.github.com/lxwinspur/2c3fd68cdb35e06480c4a5f7890e3a06#file-effecter_pdr-json.

 $ pldmtool platform GetPDR -d 0
 Encode request successfully
 Request Message:
 08 01 80 02 51 00 00 00 00 00 00 00 00 01 80 00 00 00
 Success in creating the socket : RC = 3
 Success in connecting to socket : RC = 0
 Success in sending message type as pldm to mctp : RC = 0
 Write to socket successful : RC = 18
 Total length:18
 Loopback response message:
 08 01 80 02 51 00 00 00 00 00 00 00 00 01 80 00 00 00
 On first recv(),response == request : RC = 0
 Total length: 46
 Shutdown Socket successful :  RC = 0
 Response Message:
 08 01 00 02 51 00 02 00 00 00 00 00 00 00 01 1d 00 01 00 00 00 01 0b 00 00 13 00 00 00 01 00 21 00 00 00 00 00 00 00 00 00 01 c4 00 01 06
 Parsed Response Msg:
 nextRecordHandle: 2
 responseCount: 29
 recordHandle: 1
 PDRHeaderVersion: 1
 PDRType: 11
 recordChangeNumber: 0
 dataLength: 19
 PLDMTerminusHandle: 0
 effecterID: 1
 entityType: 33
 entityInstanceNumber: 0
 containerID: 0
 effecterSemanticID: 0
 effecterInit: 0
 effecterDescriptionPDR: false
 compositeEffecterCount: 1
 stateSetID: 196
 possibleStatesSize: 1
 possibleStates: 6

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I0c41f888b2e36a5a49968dff190ad8d53255b9ed
diff --git a/libpldmresponder/platform.hpp b/libpldmresponder/platform.hpp
index 3de0e1f..dde51e0 100644
--- a/libpldmresponder/platform.hpp
+++ b/libpldmresponder/platform.hpp
@@ -4,6 +4,7 @@
 
 #include "handler.hpp"
 #include "libpldmresponder/pdr.hpp"
+#include "libpldmresponder/pdr_utils.hpp"
 #include "utils.hpp"
 
 #include <stdint.h>
@@ -66,6 +67,7 @@
         const DBusInterface& dBusIntf, effecter::Id effecterId,
         const std::vector<set_effecter_state_field>& stateField)
     {
+        using namespace pldm::responder::pdr;
         using namespace std::string_literals;
         using DBusProperty = std::variant<std::string, bool>;
         using StateSetId = uint16_t;
@@ -89,46 +91,42 @@
         state_effecter_possible_states* states = nullptr;
         pldm_state_effecter_pdr* pdr = nullptr;
         uint8_t compEffecterCnt = stateField.size();
-        uint32_t recordHndl{};
-        Repo& pdrRepo = get(PDR_JSONS_DIR);
-        pdr::Entry pdrEntry{};
 
-        while (!pdr)
+        pdr_utils::Repo repo =
+            getRepoByType(PDR_JSONS_DIR, PLDM_STATE_EFFECTER_PDR);
+        if (repo.empty())
         {
-            pdrEntry = pdrRepo.at(recordHndl);
-            pldm_pdr_hdr* header =
-                reinterpret_cast<pldm_pdr_hdr*>(pdrEntry.data());
-            if (header->type != PLDM_STATE_EFFECTER_PDR)
+            std::cerr << "Failed to get record by PDR type\n";
+            return PLDM_PLATFORM_INVALID_EFFECTER_ID;
+        }
+        PdrEntry pdrEntry{};
+        auto pdrRecord = repo.getFirstRecord(pdrEntry);
+        while (pdrRecord)
+        {
+            pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data);
+            if (pdr->effecter_id != effecterId)
             {
-                recordHndl = pdrRepo.getNextRecordHandle(recordHndl);
-                if (recordHndl)
-                {
-                    continue;
-                }
-                return PLDM_PLATFORM_INVALID_EFFECTER_ID;
+                pdr = nullptr;
+                pdrRecord = repo.getNextRecord(pdrRecord, pdrEntry);
+                continue;
             }
-            pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrEntry.data());
-            recordHndl = pdr->hdr.record_handle;
-            if (pdr->effecter_id == effecterId)
+
+            states = reinterpret_cast<state_effecter_possible_states*>(
+                pdr->possible_states);
+            if (compEffecterCnt > pdr->composite_effecter_count)
             {
-                states = reinterpret_cast<state_effecter_possible_states*>(
-                    pdr->possible_states);
-                if (compEffecterCnt > pdr->composite_effecter_count)
-                {
-                    std::cerr
-                        << "The requester sent wrong composite effecter"
-                        << " count for the effecter, EFFECTER_ID=" << effecterId
-                        << "COMP_EFF_CNT=" << compEffecterCnt << "\n";
-                    return PLDM_ERROR_INVALID_DATA;
-                }
-                break;
+                std::cerr << "The requester sent wrong composite effecter"
+                          << " count for the effecter, EFFECTER_ID="
+                          << effecterId << "COMP_EFF_CNT=" << compEffecterCnt
+                          << "\n";
+                return PLDM_ERROR_INVALID_DATA;
             }
-            recordHndl = pdrRepo.getNextRecordHandle(recordHndl);
-            if (!recordHndl)
-            {
-                return PLDM_PLATFORM_INVALID_EFFECTER_ID;
-            }
-            pdr = nullptr;
+            break;
+        }
+
+        if (!pdr)
+        {
+            return PLDM_PLATFORM_INVALID_EFFECTER_ID;
         }
 
         std::map<StateSetId, std::function<int(const std::string& objPath,