Tom Joseph | 151d533 | 2019-11-17 22:21:45 +0530 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <filesystem> |
| 4 | #include <map> |
| 5 | #include <string> |
| 6 | #include <tuple> |
| 7 | #include <vector> |
| 8 | |
| 9 | namespace pldm |
| 10 | { |
| 11 | |
| 12 | namespace responder |
| 13 | { |
| 14 | |
| 15 | namespace dbus |
| 16 | { |
| 17 | |
| 18 | using Service = std::string; |
| 19 | using RootPath = std::string; |
| 20 | using Interface = std::string; |
| 21 | using Interfaces = std::vector<Interface>; |
| 22 | using Property = std::string; |
| 23 | using PropertyType = std::string; |
| 24 | |
| 25 | } // namespace dbus |
| 26 | |
| 27 | namespace fru |
| 28 | { |
| 29 | |
| 30 | using RecordType = uint8_t; |
| 31 | using EncodingType = uint8_t; |
| 32 | using FieldType = uint8_t; |
| 33 | |
| 34 | } // namespace fru |
| 35 | |
| 36 | namespace fru_parser |
| 37 | { |
| 38 | |
| 39 | namespace fs = std::filesystem; |
| 40 | using namespace dbus; |
| 41 | using namespace fru; |
| 42 | |
| 43 | // DBusLookupInfo contains info to lookup in the D-Bus inventory, D-Bus |
| 44 | // inventory service bus name, root path of the inventory D-Bus objects and list |
| 45 | // of xyz.openbmc_project.Inventory.Item.* interface names. |
| 46 | using DBusLookupInfo = std::tuple<Service, RootPath, Interfaces>; |
| 47 | using FieldInfo = std::tuple<Interface, Property, PropertyType, FieldType>; |
| 48 | |
| 49 | using FruRecordInfo = |
| 50 | std::tuple<RecordType, EncodingType, std::vector<FieldInfo>>; |
| 51 | using FruRecordInfos = std::vector<FruRecordInfo>; |
| 52 | |
| 53 | using ItemIntfName = std::string; |
| 54 | using FruRecordMap = std::map<ItemIntfName, FruRecordInfos>; |
| 55 | |
| 56 | /** @class FruParser |
| 57 | * |
| 58 | * @brief Parses the PLDM FRU configuration files to populate the data |
| 59 | * structure, containing the information needed to map the D-Bus |
| 60 | * inventory information into PLDM FRU Record. |
| 61 | */ |
| 62 | class FruParser |
| 63 | { |
| 64 | |
| 65 | public: |
| 66 | FruParser() = delete; |
| 67 | explicit FruParser(const std::string& dirPath); |
| 68 | virtual ~FruParser() = default; |
| 69 | FruParser(const FruParser&) = default; |
| 70 | FruParser& operator=(const FruParser&) = default; |
| 71 | FruParser(FruParser&&) = default; |
| 72 | FruParser& operator=(FruParser&&) = default; |
| 73 | |
| 74 | /** @brief Provides the service, root D-Bus path and the interfaces that is |
| 75 | * needed to build FRU record data table |
| 76 | * |
| 77 | * @return service and inventory interfaces needed to build the FRU records |
| 78 | */ |
| 79 | const DBusLookupInfo& inventoryLookup() const |
| 80 | { |
| 81 | return lookupInfo.value(); |
| 82 | } |
| 83 | |
| 84 | /** @brief Get the information need to create PLDM FRU records for a |
| 85 | * inventory item type. The parameter to this API is the inventory item |
| 86 | * type, for example xyz.openbmc_project.Inventory.Item.Cpu for CPU's |
| 87 | * |
| 88 | * @param[in] intf - name of the item interface |
| 89 | * |
| 90 | * @return return the info create the PLDM FRU records from inventory D-Bus |
| 91 | * objects |
| 92 | */ |
| 93 | const FruRecordInfos& getRecordInfo(const Interface& intf) const |
| 94 | { |
| 95 | return recordMap.at(intf); |
| 96 | } |
| 97 | |
| 98 | private: |
| 99 | /** @brief Parse the FRU_Master.json file and populate the D-Bus lookup |
| 100 | * information which provides the service, root D-Bus path and the |
| 101 | * item interfaces. |
| 102 | * |
| 103 | * @param[in] filePath - file path to FRU_Master.json |
| 104 | */ |
| 105 | void setupDBusLookup(const fs::path& filePath); |
| 106 | |
| 107 | /** @brief Parse the FRU Configuration JSON file in the directory path |
| 108 | * except the FRU_Master.json and build the FRU record information |
| 109 | * |
| 110 | * @param[in] dirPath - directory path where all the FRU configuration JSON |
| 111 | * files exist |
| 112 | */ |
| 113 | void setupFruRecordMap(const std::string& dirPath); |
| 114 | |
| 115 | std::optional<DBusLookupInfo> lookupInfo; |
| 116 | FruRecordMap recordMap; |
| 117 | }; |
| 118 | |
| 119 | } // namespace fru_parser |
| 120 | |
| 121 | } // namespace responder |
| 122 | |
| 123 | } // namespace pldm |