blob: 6c9cf1235c59df3f4fbadf8ea73e6c0f75028437 [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
107 public:
108 /**
109 * @brief Dump the complete inventory in JSON format
110 *
111 * @param[in] jsObject - Inventory JSON specified in configure file.
112 */
113 void dumpInventory(const nlohmann::basic_json<>& jsObject);
114
115 /**
116 * @brief Dump the given inventory object in JSON format
117 *
118 * @param[in] jsObject - Inventory JSON specified in configure file.
119 */
120 void dumpObject(const nlohmann::basic_json<>& jsObject);
121
122 /**
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +0530123 * @brief Read keyword
124 * Read the given object path, record name and keyword
125 * from the inventory and display the value of the keyword
126 * in JSON format.
127 */
128 void readKeyword();
129
130 /**
PriyangaRamasamyd09d2ec2020-03-12 14:11:50 +0530131 * @brief Update Keyword
132 * Update the given keyword with the given value.
133 *
134 * @return return code (Success(0)/Failure(-1))
135 */
136 int updateKeyword();
137
138 /**
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530139 * @brief A Constructor
140 * Constructor is called during the
141 * object instantiation for dumpInventory option.
142 */
143 VpdTool()
144 {
145 }
146
147 /**
148 * @brief Constructor
149 * Constructor is called during the
150 * object instantiation for dumpObject option.
151 */
152 VpdTool(const std::string&& fru) : fruPath(std::move(fru))
153 {
154 }
PriyangaRamasamy02d4d4e2020-02-24 14:54:45 +0530155
156 /**
157 * @brief Constructor
158 * Constructor is called during the
159 * object instantiation for readKeyword option.
160 */
161 VpdTool(const std::string&& fru, const std::string&& recName,
162 const std::string&& kw) :
163 fruPath(std::move(fru)),
164 recordName(std::move(recName)), keyword(std::move(kw))
165 {
166 }
PriyangaRamasamyd09d2ec2020-03-12 14:11:50 +0530167
168 /**
169 * @brief Constructor
170 * Constructor is called during the
171 * object instantiation for updateKeyword option.
172 */
173
174 VpdTool(const std::string&& fru, const std::string&& recName,
175 const std::string&& kw, const std::string&& val) :
176 fruPath(std::move(fru)),
177 recordName(std::move(recName)), keyword(std::move(kw)),
178 value(std::move(val))
179 {
180 }
PriyangaRamasamy1f0b1e62020-02-20 20:48:25 +0530181};