blob: 8757c31048641c0bc90e18d27f26fb0165171315 [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
Alpana Kumarib6965f12020-06-01 00:32:21 -050017 // Store Type of FRU
18 std::string fruType;
19
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +053020 /**
21 * @brief Debugger
22 * Displays the output in JSON.
23 *
24 * @param[in] output - json output to be displayed
25 */
26 void debugger(json output);
27
28 /**
29 * @brief make Dbus Call
30 *
31 * @param[in] objectName - dbus Object
32 * @param[in] interface - dbus Interface
33 * @param[in] kw - keyword under the interface
34 *
35 * @return dbus call response
36 */
37 auto makeDBusCall(const std::string& objectName,
38 const std::string& interface, const std::string& kw);
39
40 /**
41 * @brief Adds FRU type and Location Code
42 * Appends the type of the FRU and location code to the output
43 *
44 * @param[in] exIntf - extraInterfaces json from INVENTORY_JSON
45 * @param[in] object - The D-Bus object to read the location code from
46 * @param[out] kwVal - JSON object into which the FRU type and location code
47 * are placed
48 */
49 void addFruTypeAndLocation(json exIntf, const std::string& object,
50 json& kwVal);
51
52 /**
53 * @brief Get VINI properties
54 * Making a dbus call for properties [SN, PN, CC, FN, DR]
55 * under VINI interface.
56 *
57 * @param[in] invPath - Value of inventory Path
58 * @param[in] exIntf - extraInterfaces json from INVENTORY_JSON
59 *
60 * @return json output which gives the properties under invPath's VINI
61 * interface
62 */
63 json getVINIProperties(std::string invPath, json exIntf);
64
65 /**
66 * @brief Get ExtraInterface Properties
67 * Making a dbus call for those properties under extraInterfaces.
68 *
69 * @param[in] invPath - Value of inventory path
70 * @param[in] extraInterface - One of the invPath's extraInterfaces whose
71 * value is not null
72 * @param[in] prop - All properties of the extraInterface.
73 *
74 * @return json output which gives the properties under invPath's
75 * extraInterface.
76 */
77 void getExtraInterfaceProperties(std::string invPath,
78 std::string extraInterface, json prop,
79 json exIntf, json& output);
80
81 /**
82 * @brief Interface Decider
83 * Decides whether to make the dbus call for
84 * getting properites from extraInterface or from
85 * VINI interface, depending on the value of
86 * extraInterfaces object in the inventory json.
87 *
88 * @param[in] itemEEPROM - holds the reference of one of the EEPROM objects.
89 *
90 * @return json output for one of the EEPROM objects.
91 */
92 json interfaceDecider(json& itemEEPROM);
93
94 /**
95 * @brief Parse Inventory JSON
96 * Parses the complete inventory json and depending upon
97 * the user option makes the dbuscall for the frus
98 * via interfaceDecider function.
99 *
100 * @param[in] jsObject - Inventory json object
101 * @param[in] flag - flag which tells about the user option(either
102 * dumpInventory or dumpObject)
103 * @param[in] fruPath - fruPath is empty for dumpInventory option and holds
104 * valid fruPath for dumpObject option.
105 *
106 * @return output json
107 */
108 json parseInvJson(const json& jsObject, char flag, std::string fruPath);
109
PriyangaRamasamycdf943c2020-03-18 02:25:30 +0530110 /**
PriyangaRamasamycdf943c2020-03-18 02:25:30 +0530111 * @brief eraseInventoryPath
112 * Remove the INVENTORY_PATH - "/xyz/openbmc_project/inventory"
113 * for code convenience.
114 *
115 * @param[out] fru - Reference to the fru path whose INVENTORY_PATH is
116 * stripped off.
117 */
118 void eraseInventoryPath(std::string& fru);
119
PriyangaRamasamy6ee637a2021-02-12 04:49:02 -0600120 /** @brief printReturnCode */
121 void printReturnCode(int returnCode);
122
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530123 public:
124 /**
125 * @brief Dump the complete inventory in JSON format
126 *
127 * @param[in] jsObject - Inventory JSON specified in configure file.
128 */
129 void dumpInventory(const nlohmann::basic_json<>& jsObject);
130
131 /**
132 * @brief Dump the given inventory object in JSON format
133 *
134 * @param[in] jsObject - Inventory JSON specified in configure file.
135 */
136 void dumpObject(const nlohmann::basic_json<>& jsObject);
137
138 /**
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +0530139 * @brief Read keyword
140 * Read the given object path, record name and keyword
141 * from the inventory and display the value of the keyword
142 * in JSON format.
143 */
144 void readKeyword();
145
146 /**
PriyangaRamasamyd09d2ec2020-03-12 14:11:50 +0530147 * @brief Update Keyword
148 * Update the given keyword with the given value.
149 *
150 * @return return code (Success(0)/Failure(-1))
151 */
152 int updateKeyword();
153
154 /**
PriyangaRamasamy0407b172020-03-31 13:57:18 +0530155 * @brief Force Reset
156 * Clearing the inventory cache data and restarting the
157 * phosphor inventory manager and also retriggering all the
158 * udev events.
159 *
160 * @param[in] jsObject - Inventory JSON specified in configure file.
161 */
162 void forceReset(const nlohmann::basic_json<>& jsObject);
163
164 /**
PriyangaRamasamycdf943c2020-03-18 02:25:30 +0530165 * @brief Constructor
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530166 * Constructor is called during the
PriyangaRamasamy0407b172020-03-31 13:57:18 +0530167 * object instantiation for dumpInventory option and
168 * forceReset option.
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530169 */
170 VpdTool()
171 {
172 }
173
174 /**
175 * @brief Constructor
176 * Constructor is called during the
177 * object instantiation for dumpObject option.
178 */
179 VpdTool(const std::string&& fru) : fruPath(std::move(fru))
180 {
181 }
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +0530182
183 /**
184 * @brief Constructor
185 * Constructor is called during the
186 * object instantiation for readKeyword option.
187 */
188 VpdTool(const std::string&& fru, const std::string&& recName,
189 const std::string&& kw) :
190 fruPath(std::move(fru)),
191 recordName(std::move(recName)), keyword(std::move(kw))
192 {
193 }
PriyangaRamasamyd09d2ec2020-03-12 14:11:50 +0530194
195 /**
196 * @brief Constructor
197 * Constructor is called during the
198 * object instantiation for updateKeyword option.
199 */
200
201 VpdTool(const std::string&& fru, const std::string&& recName,
202 const std::string&& kw, const std::string&& val) :
203 fruPath(std::move(fru)),
204 recordName(std::move(recName)), keyword(std::move(kw)),
205 value(std::move(val))
206 {
207 }
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530208};