blob: 1ac96bd006b05d87a0444ffe8d84736d729ec8cf [file] [log] [blame]
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +05301#include "config.h"
2
3#include "types.hpp"
4
5#include <nlohmann/json.hpp>
6
7using json = nlohmann::json;
8
9class VpdTool
10{
11 private:
12 const std::string fruPath;
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +053013 const std::string recordName;
14 const std::string keyword;
PriyangaRamasamyd09d2ec2020-03-12 14:11:50 +053015 const std::string value;
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +053016
17 /**
18 * @brief Debugger
19 * Displays the output in JSON.
20 *
21 * @param[in] output - json output to be displayed
22 */
23 void debugger(json output);
24
25 /**
26 * @brief make Dbus Call
27 *
28 * @param[in] objectName - dbus Object
29 * @param[in] interface - dbus Interface
30 * @param[in] kw - keyword under the interface
31 *
32 * @return dbus call response
33 */
34 auto makeDBusCall(const std::string& objectName,
35 const std::string& interface, const std::string& kw);
36
37 /**
38 * @brief Adds FRU type and Location Code
39 * Appends the type of the FRU and location code to the output
40 *
41 * @param[in] exIntf - extraInterfaces json from INVENTORY_JSON
42 * @param[in] object - The D-Bus object to read the location code from
43 * @param[out] kwVal - JSON object into which the FRU type and location code
44 * are placed
45 */
46 void addFruTypeAndLocation(json exIntf, const std::string& object,
47 json& kwVal);
48
49 /**
50 * @brief Get VINI properties
51 * Making a dbus call for properties [SN, PN, CC, FN, DR]
52 * under VINI interface.
53 *
54 * @param[in] invPath - Value of inventory Path
55 * @param[in] exIntf - extraInterfaces json from INVENTORY_JSON
56 *
57 * @return json output which gives the properties under invPath's VINI
58 * interface
59 */
60 json getVINIProperties(std::string invPath, json exIntf);
61
62 /**
63 * @brief Get ExtraInterface Properties
64 * Making a dbus call for those properties under extraInterfaces.
65 *
66 * @param[in] invPath - Value of inventory path
67 * @param[in] extraInterface - One of the invPath's extraInterfaces whose
68 * value is not null
69 * @param[in] prop - All properties of the extraInterface.
70 *
71 * @return json output which gives the properties under invPath's
72 * extraInterface.
73 */
74 void getExtraInterfaceProperties(std::string invPath,
75 std::string extraInterface, json prop,
76 json exIntf, json& output);
77
78 /**
79 * @brief Interface Decider
80 * Decides whether to make the dbus call for
81 * getting properites from extraInterface or from
82 * VINI interface, depending on the value of
83 * extraInterfaces object in the inventory json.
84 *
85 * @param[in] itemEEPROM - holds the reference of one of the EEPROM objects.
86 *
87 * @return json output for one of the EEPROM objects.
88 */
89 json interfaceDecider(json& itemEEPROM);
90
91 /**
92 * @brief Parse Inventory JSON
93 * Parses the complete inventory json and depending upon
94 * the user option makes the dbuscall for the frus
95 * via interfaceDecider function.
96 *
97 * @param[in] jsObject - Inventory json object
98 * @param[in] flag - flag which tells about the user option(either
99 * dumpInventory or dumpObject)
100 * @param[in] fruPath - fruPath is empty for dumpInventory option and holds
101 * valid fruPath for dumpObject option.
102 *
103 * @return output json
104 */
105 json parseInvJson(const json& jsObject, char flag, std::string fruPath);
106
PriyangaRamasamycdf943c2020-03-18 02:25:30 +0530107 /**
108 * @brief getPowerSupplyFruPath
109 * Get the power supply fru paths from Object mapper service.
110 *
111 * @param[out] powSuppFrus - Reference to a vector which has the power
112 * supply fru paths.
113 */
114 void getPowerSupplyFruPath(std::vector<std::string>& powSuppFrus);
115
116 /**
117 * @brief eraseInventoryPath
118 * Remove the INVENTORY_PATH - "/xyz/openbmc_project/inventory"
119 * for code convenience.
120 *
121 * @param[out] fru - Reference to the fru path whose INVENTORY_PATH is
122 * stripped off.
123 */
124 void eraseInventoryPath(std::string& fru);
125
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530126 public:
127 /**
128 * @brief Dump the complete inventory in JSON format
129 *
130 * @param[in] jsObject - Inventory JSON specified in configure file.
131 */
132 void dumpInventory(const nlohmann::basic_json<>& jsObject);
133
134 /**
135 * @brief Dump the given inventory object in JSON format
136 *
137 * @param[in] jsObject - Inventory JSON specified in configure file.
138 */
139 void dumpObject(const nlohmann::basic_json<>& jsObject);
140
141 /**
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +0530142 * @brief Read keyword
143 * Read the given object path, record name and keyword
144 * from the inventory and display the value of the keyword
145 * in JSON format.
146 */
147 void readKeyword();
148
149 /**
PriyangaRamasamyd09d2ec2020-03-12 14:11:50 +0530150 * @brief Update Keyword
151 * Update the given keyword with the given value.
152 *
153 * @return return code (Success(0)/Failure(-1))
154 */
155 int updateKeyword();
156
157 /**
PriyangaRamasamycdf943c2020-03-18 02:25:30 +0530158 * @brief Constructor
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530159 * Constructor is called during the
160 * object instantiation for dumpInventory option.
161 */
162 VpdTool()
163 {
164 }
165
166 /**
167 * @brief Constructor
168 * Constructor is called during the
169 * object instantiation for dumpObject option.
170 */
171 VpdTool(const std::string&& fru) : fruPath(std::move(fru))
172 {
173 }
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +0530174
175 /**
176 * @brief Constructor
177 * Constructor is called during the
178 * object instantiation for readKeyword option.
179 */
180 VpdTool(const std::string&& fru, const std::string&& recName,
181 const std::string&& kw) :
182 fruPath(std::move(fru)),
183 recordName(std::move(recName)), keyword(std::move(kw))
184 {
185 }
PriyangaRamasamyd09d2ec2020-03-12 14:11:50 +0530186
187 /**
188 * @brief Constructor
189 * Constructor is called during the
190 * object instantiation for updateKeyword option.
191 */
192
193 VpdTool(const std::string&& fru, const std::string&& recName,
194 const std::string&& kw, const std::string&& val) :
195 fruPath(std::move(fru)),
196 recordName(std::move(recName)), keyword(std::move(kw)),
197 value(std::move(val))
198 {
199 }
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530200};