blob: 852638cd463c95254b948cb5b1d68647a68cf394 [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 /**
PriyangaRamasamycdf943c2020-03-18 02:25:30 +0530108 * @brief eraseInventoryPath
109 * Remove the INVENTORY_PATH - "/xyz/openbmc_project/inventory"
110 * for code convenience.
111 *
112 * @param[out] fru - Reference to the fru path whose INVENTORY_PATH is
113 * stripped off.
114 */
115 void eraseInventoryPath(std::string& fru);
116
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530117 public:
118 /**
119 * @brief Dump the complete inventory in JSON format
120 *
121 * @param[in] jsObject - Inventory JSON specified in configure file.
122 */
123 void dumpInventory(const nlohmann::basic_json<>& jsObject);
124
125 /**
126 * @brief Dump the given inventory object in JSON format
127 *
128 * @param[in] jsObject - Inventory JSON specified in configure file.
129 */
130 void dumpObject(const nlohmann::basic_json<>& jsObject);
131
132 /**
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +0530133 * @brief Read keyword
134 * Read the given object path, record name and keyword
135 * from the inventory and display the value of the keyword
136 * in JSON format.
137 */
138 void readKeyword();
139
140 /**
PriyangaRamasamyd09d2ec2020-03-12 14:11:50 +0530141 * @brief Update Keyword
142 * Update the given keyword with the given value.
143 *
144 * @return return code (Success(0)/Failure(-1))
145 */
146 int updateKeyword();
147
148 /**
PriyangaRamasamy0407b172020-03-31 13:57:18 +0530149 * @brief Force Reset
150 * Clearing the inventory cache data and restarting the
151 * phosphor inventory manager and also retriggering all the
152 * udev events.
153 *
154 * @param[in] jsObject - Inventory JSON specified in configure file.
155 */
156 void forceReset(const nlohmann::basic_json<>& jsObject);
157
158 /**
PriyangaRamasamycdf943c2020-03-18 02:25:30 +0530159 * @brief Constructor
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530160 * Constructor is called during the
PriyangaRamasamy0407b172020-03-31 13:57:18 +0530161 * object instantiation for dumpInventory option and
162 * forceReset option.
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530163 */
164 VpdTool()
165 {
166 }
167
168 /**
169 * @brief Constructor
170 * Constructor is called during the
171 * object instantiation for dumpObject option.
172 */
173 VpdTool(const std::string&& fru) : fruPath(std::move(fru))
174 {
175 }
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +0530176
177 /**
178 * @brief Constructor
179 * Constructor is called during the
180 * object instantiation for readKeyword option.
181 */
182 VpdTool(const std::string&& fru, const std::string&& recName,
183 const std::string&& kw) :
184 fruPath(std::move(fru)),
185 recordName(std::move(recName)), keyword(std::move(kw))
186 {
187 }
PriyangaRamasamyd09d2ec2020-03-12 14:11:50 +0530188
189 /**
190 * @brief Constructor
191 * Constructor is called during the
192 * object instantiation for updateKeyword option.
193 */
194
195 VpdTool(const std::string&& fru, const std::string&& recName,
196 const std::string&& kw, const std::string&& val) :
197 fruPath(std::move(fru)),
198 recordName(std::move(recName)), keyword(std::move(kw)),
199 value(std::move(val))
200 {
201 }
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530202};