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