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