blob: ce099868e559b334f659ce5195e1b4cfd8768bee [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;
43using namespace dbus;
44using 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.
49using DBusLookupInfo = std::tuple<Service, RootPath, Interfaces>;
50using FieldInfo = std::tuple<Interface, Property, PropertyType, FieldType>;
51
52using FruRecordInfo =
53 std::tuple<RecordType, EncodingType, std::vector<FieldInfo>>;
54using FruRecordInfos = std::vector<FruRecordInfo>;
55
56using ItemIntfName = std::string;
57using 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 */
65class FruParser
66{
67
68 public:
69 FruParser() = delete;
70 explicit FruParser(const std::string& dirPath);
71 virtual ~FruParser() = default;
72 FruParser(const FruParser&) = default;
73 FruParser& operator=(const FruParser&) = default;
74 FruParser(FruParser&&) = default;
75 FruParser& operator=(FruParser&&) = default;
76
77 /** @brief Provides the service, root D-Bus path and the interfaces that is
78 * needed to build FRU record data table
79 *
80 * @return service and inventory interfaces needed to build the FRU records
81 */
82 const DBusLookupInfo& inventoryLookup() const
83 {
84 return lookupInfo.value();
85 }
86
87 /** @brief Get the information need to create PLDM FRU records for a
88 * inventory item type. The parameter to this API is the inventory item
89 * type, for example xyz.openbmc_project.Inventory.Item.Cpu for CPU's
90 *
91 * @param[in] intf - name of the item interface
92 *
93 * @return return the info create the PLDM FRU records from inventory D-Bus
94 * objects
95 */
96 const FruRecordInfos& getRecordInfo(const Interface& intf) const
97 {
98 return recordMap.at(intf);
99 }
100
Deepak Kodihalli3cd61812020-03-10 06:38:45 -0500101 EntityType getEntityType(const Interface& intf) const
102 {
103 return intfToEntityType.at(intf);
104 }
105
Tom Joseph151d5332019-11-17 22:21:45 +0530106 private:
107 /** @brief Parse the FRU_Master.json file and populate the D-Bus lookup
108 * information which provides the service, root D-Bus path and the
109 * item interfaces.
110 *
111 * @param[in] filePath - file path to FRU_Master.json
112 */
113 void setupDBusLookup(const fs::path& filePath);
114
115 /** @brief Parse the FRU Configuration JSON file in the directory path
116 * except the FRU_Master.json and build the FRU record information
117 *
118 * @param[in] dirPath - directory path where all the FRU configuration JSON
119 * files exist
120 */
121 void setupFruRecordMap(const std::string& dirPath);
122
John Wang55732c22020-05-14 10:33:00 +0800123 /** @brief Set the default service root D-Bus path and the item interfaces.
124 */
125 void setupDefaultDBusLookup();
126
127 /** @brief Build the default FRU record informations
128 */
129 void setupDefaultFruRecordMap();
130
Tom Joseph151d5332019-11-17 22:21:45 +0530131 std::optional<DBusLookupInfo> lookupInfo;
132 FruRecordMap recordMap;
Deepak Kodihalli3cd61812020-03-10 06:38:45 -0500133 std::map<Interface, EntityType> intfToEntityType;
Tom Joseph151d5332019-11-17 22:21:45 +0530134};
135
136} // namespace fru_parser
137
138} // namespace responder
139
140} // namespace pldm