blob: 378ece2734c70a09723a28c26a3a16bc117e2781 [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;
13
14 /**
15 * @brief Debugger
16 * Displays the output in JSON.
17 *
18 * @param[in] output - json output to be displayed
19 */
20 void debugger(json output);
21
22 /**
23 * @brief make Dbus Call
24 *
25 * @param[in] objectName - dbus Object
26 * @param[in] interface - dbus Interface
27 * @param[in] kw - keyword under the interface
28 *
29 * @return dbus call response
30 */
31 auto makeDBusCall(const std::string& objectName,
32 const std::string& interface, const std::string& kw);
33
34 /**
35 * @brief Adds FRU type and Location Code
36 * Appends the type of the FRU and location code to the output
37 *
38 * @param[in] exIntf - extraInterfaces json from INVENTORY_JSON
39 * @param[in] object - The D-Bus object to read the location code from
40 * @param[out] kwVal - JSON object into which the FRU type and location code
41 * are placed
42 */
43 void addFruTypeAndLocation(json exIntf, const std::string& object,
44 json& kwVal);
45
46 /**
47 * @brief Get VINI properties
48 * Making a dbus call for properties [SN, PN, CC, FN, DR]
49 * under VINI interface.
50 *
51 * @param[in] invPath - Value of inventory Path
52 * @param[in] exIntf - extraInterfaces json from INVENTORY_JSON
53 *
54 * @return json output which gives the properties under invPath's VINI
55 * interface
56 */
57 json getVINIProperties(std::string invPath, json exIntf);
58
59 /**
60 * @brief Get ExtraInterface Properties
61 * Making a dbus call for those properties under extraInterfaces.
62 *
63 * @param[in] invPath - Value of inventory path
64 * @param[in] extraInterface - One of the invPath's extraInterfaces whose
65 * value is not null
66 * @param[in] prop - All properties of the extraInterface.
67 *
68 * @return json output which gives the properties under invPath's
69 * extraInterface.
70 */
71 void getExtraInterfaceProperties(std::string invPath,
72 std::string extraInterface, json prop,
73 json exIntf, json& output);
74
75 /**
76 * @brief Interface Decider
77 * Decides whether to make the dbus call for
78 * getting properites from extraInterface or from
79 * VINI interface, depending on the value of
80 * extraInterfaces object in the inventory json.
81 *
82 * @param[in] itemEEPROM - holds the reference of one of the EEPROM objects.
83 *
84 * @return json output for one of the EEPROM objects.
85 */
86 json interfaceDecider(json& itemEEPROM);
87
88 /**
89 * @brief Parse Inventory JSON
90 * Parses the complete inventory json and depending upon
91 * the user option makes the dbuscall for the frus
92 * via interfaceDecider function.
93 *
94 * @param[in] jsObject - Inventory json object
95 * @param[in] flag - flag which tells about the user option(either
96 * dumpInventory or dumpObject)
97 * @param[in] fruPath - fruPath is empty for dumpInventory option and holds
98 * valid fruPath for dumpObject option.
99 *
100 * @return output json
101 */
102 json parseInvJson(const json& jsObject, char flag, std::string fruPath);
103
104 public:
105 /**
106 * @brief Dump the complete inventory in JSON format
107 *
108 * @param[in] jsObject - Inventory JSON specified in configure file.
109 */
110 void dumpInventory(const nlohmann::basic_json<>& jsObject);
111
112 /**
113 * @brief Dump the given inventory object in JSON format
114 *
115 * @param[in] jsObject - Inventory JSON specified in configure file.
116 */
117 void dumpObject(const nlohmann::basic_json<>& jsObject);
118
119 /**
120 * @brief A Constructor
121 * Constructor is called during the
122 * object instantiation for dumpInventory option.
123 */
124 VpdTool()
125 {
126 }
127
128 /**
129 * @brief Constructor
130 * Constructor is called during the
131 * object instantiation for dumpObject option.
132 */
133 VpdTool(const std::string&& fru) : fruPath(std::move(fru))
134 {
135 }
136};