1 #include "config.h" 2 3 #include "types.hpp" 4 5 #include <nlohmann/json.hpp> 6 7 using json = nlohmann::json; 8 9 class VpdTool 10 { 11 private: 12 const std::string fruPath; 13 const std::string recordName; 14 const std::string keyword; 15 const std::string value; 16 17 // Store Type of FRU 18 std::string fruType; 19 20 /** 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 110 /** 111 * @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 120 public: 121 /** 122 * @brief Dump the complete inventory in JSON format 123 * 124 * @param[in] jsObject - Inventory JSON specified in configure file. 125 */ 126 void dumpInventory(const nlohmann::basic_json<>& jsObject); 127 128 /** 129 * @brief Dump the given inventory object in JSON format 130 * 131 * @param[in] jsObject - Inventory JSON specified in configure file. 132 */ 133 void dumpObject(const nlohmann::basic_json<>& jsObject); 134 135 /** 136 * @brief Read keyword 137 * Read the given object path, record name and keyword 138 * from the inventory and display the value of the keyword 139 * in JSON format. 140 */ 141 void readKeyword(); 142 143 /** 144 * @brief Update Keyword 145 * Update the given keyword with the given value. 146 * 147 * @return return code (Success(0)/Failure(-1)) 148 */ 149 int updateKeyword(); 150 151 /** 152 * @brief Force Reset 153 * Clearing the inventory cache data and restarting the 154 * phosphor inventory manager and also retriggering all the 155 * udev events. 156 * 157 * @param[in] jsObject - Inventory JSON specified in configure file. 158 */ 159 void forceReset(const nlohmann::basic_json<>& jsObject); 160 161 /** 162 * @brief Constructor 163 * Constructor is called during the 164 * object instantiation for dumpInventory option and 165 * forceReset option. 166 */ 167 VpdTool() 168 { 169 } 170 171 /** 172 * @brief Constructor 173 * Constructor is called during the 174 * object instantiation for dumpObject option. 175 */ 176 VpdTool(const std::string&& fru) : fruPath(std::move(fru)) 177 { 178 } 179 180 /** 181 * @brief Constructor 182 * Constructor is called during the 183 * object instantiation for readKeyword option. 184 */ 185 VpdTool(const std::string&& fru, const std::string&& recName, 186 const std::string&& kw) : 187 fruPath(std::move(fru)), 188 recordName(std::move(recName)), keyword(std::move(kw)) 189 { 190 } 191 192 /** 193 * @brief Constructor 194 * Constructor is called during the 195 * object instantiation for updateKeyword option. 196 */ 197 198 VpdTool(const std::string&& fru, const std::string&& recName, 199 const std::string&& kw, const std::string&& val) : 200 fruPath(std::move(fru)), 201 recordName(std::move(recName)), keyword(std::move(kw)), 202 value(std::move(val)) 203 { 204 } 205 }; 206