pdr: Update D-Bus mapping structure

For most PDR types, the D-Bus object structure(paths, interfaces, and
properties) should be defined in the JSON file instead of hard-coded.

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

     pldmtool platform GetPDR -d 1
     Encode request successfully
     Request Message:
     08 01 80 02 51 01 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 01 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: Ifc0cd1540b08e9b73e03d99d71a0980ef6353e72
diff --git a/libpldmresponder/pdr_utils.cpp b/libpldmresponder/pdr_utils.cpp
index 9a68ca9..185a6ce 100644
--- a/libpldmresponder/pdr_utils.cpp
+++ b/libpldmresponder/pdr_utils.cpp
@@ -65,6 +65,76 @@
     return !getRecordCount();
 }
 
+StatestoDbusVal populateMapping(const std::string& type, const Json& dBusValues,
+                                const PossibleValues& pv)
+{
+    size_t pos = 0;
+    pldm::utils::PropertyValue value;
+    StatestoDbusVal valueMap;
+    if (dBusValues.size() != pv.size())
+    {
+        std::cerr
+            << "dBusValues size is not equal to pv size, dBusValues Size: "
+            << dBusValues.size() << ", pv Size: " << pv.size() << "\n";
+
+        return {};
+    }
+
+    for (auto it = dBusValues.begin(); it != dBusValues.end(); ++it, ++pos)
+    {
+        if (type == "uint8_t")
+        {
+            value = static_cast<uint8_t>(it.value());
+        }
+        else if (type == "uint16_t")
+        {
+            value = static_cast<uint16_t>(it.value());
+        }
+        else if (type == "uint32_t")
+        {
+            value = static_cast<uint32_t>(it.value());
+        }
+        else if (type == "uint64_t")
+        {
+            value = static_cast<uint64_t>(it.value());
+        }
+        else if (type == "int16_t")
+        {
+            value = static_cast<int16_t>(it.value());
+        }
+        else if (type == "int32_t")
+        {
+            value = static_cast<int32_t>(it.value());
+        }
+        else if (type == "int64_t")
+        {
+            value = static_cast<int64_t>(it.value());
+        }
+        else if (type == "bool")
+        {
+            value = static_cast<bool>(it.value());
+        }
+        else if (type == "double")
+        {
+            value = static_cast<double>(it.value());
+        }
+        else if (type == "string")
+        {
+            value = static_cast<std::string>(it.value());
+        }
+        else
+        {
+            std::cerr << "Unknown D-Bus property type, TYPE=" << type.c_str()
+                      << "\n";
+            return {};
+        }
+
+        valueMap.emplace(pv[pos], value);
+    }
+
+    return valueMap;
+}
+
 } // namespace pdr_utils
 } // namespace responder
 } // namespace pldm