blob: ce6f6192f046ada5fd459ec2dbab932e1d100dc5 [file] [log] [blame]
Tom Joseph151d5332019-11-17 22:21:45 +05301#pragma once
2
3#include <filesystem>
4#include <map>
Tom Josepha459fea2021-05-12 22:12:06 -07005#include <optional>
Deepak Kodihalli3cd61812020-03-10 06:38:45 -05006#include <set>
Tom Joseph151d5332019-11-17 22:21:45 +05307#include <string>
8#include <tuple>
9#include <vector>
10
11namespace pldm
12{
13
14namespace responder
15{
16
17namespace dbus
18{
19
20using Service = std::string;
21using RootPath = std::string;
22using Interface = std::string;
Deepak Kodihalli3cd61812020-03-10 06:38:45 -050023using Interfaces = std::set<Interface>;
Tom Joseph151d5332019-11-17 22:21:45 +053024using Property = std::string;
25using PropertyType = std::string;
Deepak Kodihallia556eb22020-04-14 02:29:11 -050026using EntityType = uint16_t;
Tom Joseph151d5332019-11-17 22:21:45 +053027
28} // namespace dbus
29
30namespace fru
31{
32
33using RecordType = uint8_t;
34using EncodingType = uint8_t;
35using FieldType = uint8_t;
36
37} // namespace fru
38
39namespace fru_parser
40{
41
42namespace fs = std::filesystem;
Tom Joseph151d5332019-11-17 22:21:45 +053043
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 Bishop5079ac42021-08-19 18:35:06 -040047using DBusLookupInfo =
48 std::tuple<pldm::responder::dbus::Service, pldm::responder::dbus::RootPath,
49 pldm::responder::dbus::Interfaces>;
50using FieldInfo = std::tuple<
51 pldm::responder::dbus::Interface, pldm::responder::dbus::Property,
52 pldm::responder::dbus::PropertyType, pldm::responder::fru::FieldType>;
Tom Joseph151d5332019-11-17 22:21:45 +053053
54using FruRecordInfo =
Brad Bishop5079ac42021-08-19 18:35:06 -040055 std::tuple<pldm::responder::fru::RecordType,
56 pldm::responder::fru::EncodingType, std::vector<FieldInfo>>;
Tom Joseph151d5332019-11-17 22:21:45 +053057using FruRecordInfos = std::vector<FruRecordInfo>;
58
59using ItemIntfName = std::string;
60using 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 */
68class FruParser
69{
70
71 public:
72 FruParser() = delete;
Manojkiran Eda03b01ca2021-06-29 08:55:09 +053073 explicit FruParser(const std::string& dirPath,
74 const std::filesystem::path& fruMasterJsonPath);
Tom Joseph151d5332019-11-17 22:21:45 +053075 virtual ~FruParser() = default;
76 FruParser(const FruParser&) = default;
77 FruParser& operator=(const FruParser&) = default;
78 FruParser(FruParser&&) = default;
79 FruParser& operator=(FruParser&&) = default;
80
81 /** @brief Provides the service, root D-Bus path and the interfaces that is
82 * needed to build FRU record data table
83 *
84 * @return service and inventory interfaces needed to build the FRU records
85 */
86 const DBusLookupInfo& inventoryLookup() const
87 {
88 return lookupInfo.value();
89 }
90
91 /** @brief Get the information need to create PLDM FRU records for a
92 * inventory item type. The parameter to this API is the inventory item
93 * type, for example xyz.openbmc_project.Inventory.Item.Cpu for CPU's
94 *
95 * @param[in] intf - name of the item interface
96 *
97 * @return return the info create the PLDM FRU records from inventory D-Bus
98 * objects
99 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400100 const FruRecordInfos&
101 getRecordInfo(const pldm::responder::dbus::Interface& intf) const
Tom Joseph151d5332019-11-17 22:21:45 +0530102 {
103 return recordMap.at(intf);
104 }
105
Brad Bishop5079ac42021-08-19 18:35:06 -0400106 pldm::responder::dbus::EntityType
107 getEntityType(const pldm::responder::dbus::Interface& intf) const
Deepak Kodihalli3cd61812020-03-10 06:38:45 -0500108 {
109 return intfToEntityType.at(intf);
110 }
111
Tom Joseph151d5332019-11-17 22:21:45 +0530112 private:
113 /** @brief Parse the FRU_Master.json file and populate the D-Bus lookup
114 * information which provides the service, root D-Bus path and the
115 * item interfaces.
116 *
117 * @param[in] filePath - file path to FRU_Master.json
118 */
119 void setupDBusLookup(const fs::path& filePath);
120
121 /** @brief Parse the FRU Configuration JSON file in the directory path
122 * except the FRU_Master.json and build the FRU record information
123 *
124 * @param[in] dirPath - directory path where all the FRU configuration JSON
125 * files exist
126 */
127 void setupFruRecordMap(const std::string& dirPath);
128
John Wang55732c22020-05-14 10:33:00 +0800129 /** @brief Set the default service root D-Bus path and the item interfaces.
Manojkiran Eda03b01ca2021-06-29 08:55:09 +0530130 *
131 * @param[in] fruMasterJsonPath - json file path that contains the FRU
132 * D-Bus lookup map
John Wang55732c22020-05-14 10:33:00 +0800133 */
Manojkiran Eda03b01ca2021-06-29 08:55:09 +0530134 void setupDefaultDBusLookup(const std::filesystem::path& fruMasterJsonPath);
John Wang55732c22020-05-14 10:33:00 +0800135
136 /** @brief Build the default FRU record informations
137 */
138 void setupDefaultFruRecordMap();
139
Tom Joseph151d5332019-11-17 22:21:45 +0530140 std::optional<DBusLookupInfo> lookupInfo;
141 FruRecordMap recordMap;
Brad Bishop5079ac42021-08-19 18:35:06 -0400142 std::map<pldm::responder::dbus::Interface,
143 pldm::responder::dbus::EntityType>
144 intfToEntityType;
Tom Joseph151d5332019-11-17 22:21:45 +0530145};
146
147} // namespace fru_parser
148
149} // namespace responder
150
151} // namespace pldm