FRU Parsing for platform specific config files

This patch adds the parsing for the platform specific config
files need to build the PLDM FRU records. The BMC FRU info is
populated in the D-Bus inventory namespace and these config JSON's
provide the necessary mapping to translate D-Bus properties into
PLDM record information.

Change-Id: I600cfb7c6dcf529465b2618a2e040aa1e66c1607
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/libpldmresponder/fru_parser.hpp b/libpldmresponder/fru_parser.hpp
new file mode 100644
index 0000000..f49c04b
--- /dev/null
+++ b/libpldmresponder/fru_parser.hpp
@@ -0,0 +1,123 @@
+#pragma once
+
+#include <filesystem>
+#include <map>
+#include <string>
+#include <tuple>
+#include <vector>
+
+namespace pldm
+{
+
+namespace responder
+{
+
+namespace dbus
+{
+
+using Service = std::string;
+using RootPath = std::string;
+using Interface = std::string;
+using Interfaces = std::vector<Interface>;
+using Property = std::string;
+using PropertyType = std::string;
+
+} // namespace dbus
+
+namespace fru
+{
+
+using RecordType = uint8_t;
+using EncodingType = uint8_t;
+using FieldType = uint8_t;
+
+} // namespace fru
+
+namespace fru_parser
+{
+
+namespace fs = std::filesystem;
+using namespace dbus;
+using namespace fru;
+
+// DBusLookupInfo contains info to lookup in the D-Bus inventory, D-Bus
+// inventory service bus name, root path of the inventory D-Bus objects and list
+//  of xyz.openbmc_project.Inventory.Item.* interface names.
+using DBusLookupInfo = std::tuple<Service, RootPath, Interfaces>;
+using FieldInfo = std::tuple<Interface, Property, PropertyType, FieldType>;
+
+using FruRecordInfo =
+    std::tuple<RecordType, EncodingType, std::vector<FieldInfo>>;
+using FruRecordInfos = std::vector<FruRecordInfo>;
+
+using ItemIntfName = std::string;
+using FruRecordMap = std::map<ItemIntfName, FruRecordInfos>;
+
+/** @class FruParser
+ *
+ *  @brief Parses the PLDM FRU configuration files to populate the data
+ *         structure, containing the information needed to map the D-Bus
+ *         inventory information into PLDM FRU Record.
+ */
+class FruParser
+{
+
+  public:
+    FruParser() = delete;
+    explicit FruParser(const std::string& dirPath);
+    virtual ~FruParser() = default;
+    FruParser(const FruParser&) = default;
+    FruParser& operator=(const FruParser&) = default;
+    FruParser(FruParser&&) = default;
+    FruParser& operator=(FruParser&&) = default;
+
+    /** @brief Provides the service, root D-Bus path and the interfaces that is
+     *         needed to build FRU record data table
+     *
+     *  @return service and inventory interfaces needed to build the FRU records
+     */
+    const DBusLookupInfo& inventoryLookup() const
+    {
+        return lookupInfo.value();
+    }
+
+    /** @brief Get the information need to create PLDM FRU records for a
+     * inventory item type. The parameter to this API is the inventory item
+     * type, for example xyz.openbmc_project.Inventory.Item.Cpu for CPU's
+     *
+     *  @param[in] intf - name of the item interface
+     *
+     *  @return return the info create the PLDM FRU records from inventory D-Bus
+     *          objects
+     */
+    const FruRecordInfos& getRecordInfo(const Interface& intf) const
+    {
+        return recordMap.at(intf);
+    }
+
+  private:
+    /** @brief Parse the FRU_Master.json file and populate the D-Bus lookup
+     *         information which provides the service, root D-Bus path and the
+     *         item interfaces.
+     *
+     *  @param[in] filePath - file path to FRU_Master.json
+     */
+    void setupDBusLookup(const fs::path& filePath);
+
+    /** @brief Parse the FRU Configuration JSON file in the directory path
+     *         except the FRU_Master.json and build the FRU record information
+     *
+     *  @param[in] dirPath - directory path where all the FRU configuration JSON
+     *                       files exist
+     */
+    void setupFruRecordMap(const std::string& dirPath);
+
+    std::optional<DBusLookupInfo> lookupInfo;
+    FruRecordMap recordMap;
+};
+
+} // namespace fru_parser
+
+} // namespace responder
+
+} // namespace pldm