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