blob: 6aec28c4fc67a535d8306c7c665479d6bdb7664d [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
PriyangaRamasamy0407b172020-03-31 13:57:18 +0530112 * supply fruPaths.
PriyangaRamasamycdf943c2020-03-18 02:25:30 +0530113 */
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 /**
PriyangaRamasamy0407b172020-03-31 13:57:18 +0530158 * @brief Force Reset
159 * Clearing the inventory cache data and restarting the
160 * phosphor inventory manager and also retriggering all the
161 * udev events.
162 *
163 * @param[in] jsObject - Inventory JSON specified in configure file.
164 */
165 void forceReset(const nlohmann::basic_json<>& jsObject);
166
167 /**
PriyangaRamasamycdf943c2020-03-18 02:25:30 +0530168 * @brief Constructor
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530169 * Constructor is called during the
PriyangaRamasamy0407b172020-03-31 13:57:18 +0530170 * object instantiation for dumpInventory option and
171 * forceReset option.
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530172 */
173 VpdTool()
174 {
175 }
176
177 /**
178 * @brief Constructor
179 * Constructor is called during the
180 * object instantiation for dumpObject option.
181 */
182 VpdTool(const std::string&& fru) : fruPath(std::move(fru))
183 {
184 }
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +0530185
186 /**
187 * @brief Constructor
188 * Constructor is called during the
189 * object instantiation for readKeyword option.
190 */
191 VpdTool(const std::string&& fru, const std::string&& recName,
192 const std::string&& kw) :
193 fruPath(std::move(fru)),
194 recordName(std::move(recName)), keyword(std::move(kw))
195 {
196 }
PriyangaRamasamyd09d2ec2020-03-12 14:11:50 +0530197
198 /**
199 * @brief Constructor
200 * Constructor is called during the
201 * object instantiation for updateKeyword option.
202 */
203
204 VpdTool(const std::string&& fru, const std::string&& recName,
205 const std::string&& kw, const std::string&& val) :
206 fruPath(std::move(fru)),
207 recordName(std::move(recName)), keyword(std::move(kw)),
208 value(std::move(val))
209 {
210 }
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530211};