blob: a11610ad87d35dbc72f4eaf7052e32875c74c43a [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 Kodihalli3cd61812020-03-10 06:38:45 -050025using EntityType = uint8_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
122 std::optional<DBusLookupInfo> lookupInfo;
123 FruRecordMap recordMap;
Deepak Kodihalli3cd61812020-03-10 06:38:45 -0500124 std::map<Interface, EntityType> intfToEntityType;
Tom Joseph151d5332019-11-17 22:21:45 +0530125};
126
127} // namespace fru_parser
128
129} // namespace responder
130
131} // namespace pldm