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