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/platform.cpp b/libpldmresponder/platform.cpp
index 6ace46b..45bd041 100644
--- a/libpldmresponder/platform.cpp
+++ b/libpldmresponder/platform.cpp
@@ -13,16 +13,28 @@
 using InternalFailure =
     sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
 
+static const Json empty{};
+
+void Handler::addDbusObjMaps(uint16_t effecterId,
+                             std::tuple<DbusMappings, DbusValMaps> dbusObj)
+{
+    dbusObjMaps.emplace(effecterId, dbusObj);
+}
+
+const std::tuple<DbusMappings, DbusValMaps>&
+    Handler::getDbusObjMaps(uint16_t effecterId) const
+{
+    return dbusObjMaps.at(effecterId);
+}
+
 void Handler::generateStateEffecterRepo(const Json& json, Repo& repo)
 {
     static const std::vector<Json> emptyList{};
-    static const Json empty{};
     auto entries = json.value("entries", emptyList);
     for (const auto& e : entries)
     {
         size_t pdrSize = 0;
         auto effecters = e.value("effecters", emptyList);
-        static const Json empty{};
         for (const auto& effecter : effecters)
         {
             auto set = effecter.value("set", empty);
@@ -61,7 +73,8 @@
         pdr->has_description_pdr = false;
         pdr->composite_effecter_count = effecters.size();
 
-        EffecterObjs paths{};
+        DbusMappings dbusMappings{};
+        DbusValMaps dbusValMaps{};
         uint8_t* start =
             entry.data() + sizeof(pldm_state_effecter_pdr) - sizeof(uint8_t);
         for (const auto& effecter : effecters)
@@ -75,6 +88,7 @@
             start += sizeof(possibleStates->state_set_id) +
                      sizeof(possibleStates->possible_states_size);
             static const std::vector<uint8_t> emptyStates{};
+            PossibleValues stateValues;
             auto states = set.value("states", emptyStates);
             for (const auto& state : states)
             {
@@ -82,13 +96,31 @@
                 auto bit = state - (index * 8);
                 bitfield8_t* bf = reinterpret_cast<bitfield8_t*>(start + index);
                 bf->byte |= 1 << bit;
+                stateValues.emplace_back(std::move(state));
             }
             start += possibleStates->possible_states_size;
 
-            auto dbus = effecter.value("dbus", empty);
-            paths.emplace_back(std::move(dbus));
+            auto dbusEntry = effecter.value("dbus", empty);
+            auto objectPath = dbusEntry.value("path", "");
+            auto interface = dbusEntry.value("interface", "");
+            auto propertyName = dbusEntry.value("property_name", "");
+            auto propertyType = dbusEntry.value("property_type", "");
+            pldm::utils::DBusMapping dbusMapping{objectPath, interface,
+                                                 propertyName, propertyType};
+            dbusMappings.emplace_back(std::move(dbusMapping));
+
+            Json propValues = dbusEntry["property_values"];
+            StatestoDbusVal dbusIdToValMap =
+                populateMapping(propertyType, propValues, stateValues);
+            if (!dbusIdToValMap.empty())
+            {
+                dbusValMaps.emplace_back(std::move(dbusIdToValMap));
+            }
         }
-        addEffecterObjs(pdr->effecter_id, std::move(paths));
+
+        addDbusObjMaps(
+            pdr->effecter_id,
+            std::make_tuple(std::move(dbusMappings), std::move(dbusValMaps)));
         PdrEntry pdrEntry{};
         pdrEntry.data = entry.data();
         pdrEntry.size = pdrSize;
@@ -116,8 +148,12 @@
             auto json = readJson(dirEntry.path().string());
             if (!json.empty())
             {
-                pdrType = json.value("pdrType", 0);
-                generators.at(pdrType)(json, repo);
+                auto effecterPDRs = json.value("effecterPDRs", empty);
+                for (const auto& effecter : effecterPDRs)
+                {
+                    pdrType = effecter.value("pdrType", 0);
+                    generators.at(pdrType)(effecter, repo);
+                }
             }
         }
         catch (const InternalFailure& e)