PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 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; |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 13 | const std::string recordName; |
| 14 | const std::string keyword; |
PriyangaRamasamy | d09d2ec | 2020-03-12 14:11:50 +0530 | [diff] [blame] | 15 | const std::string value; |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 16 | |
Alpana Kumari | b6965f1 | 2020-06-01 00:32:21 -0500 | [diff] [blame] | 17 | // Store Type of FRU |
| 18 | std::string fruType; |
| 19 | |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 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 | |
PriyangaRamasamy | cdf943c | 2020-03-18 02:25:30 +0530 | [diff] [blame] | 110 | /** |
PriyangaRamasamy | cdf943c | 2020-03-18 02:25:30 +0530 | [diff] [blame] | 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 | |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 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 | /** |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 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 | /** |
PriyangaRamasamy | d09d2ec | 2020-03-12 14:11:50 +0530 | [diff] [blame] | 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 | /** |
PriyangaRamasamy | 0407b17 | 2020-03-31 13:57:18 +0530 | [diff] [blame] | 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 | /** |
PriyangaRamasamy | cdf943c | 2020-03-18 02:25:30 +0530 | [diff] [blame] | 162 | * @brief Constructor |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 163 | * Constructor is called during the |
PriyangaRamasamy | 0407b17 | 2020-03-31 13:57:18 +0530 | [diff] [blame] | 164 | * object instantiation for dumpInventory option and |
| 165 | * forceReset option. |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 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 | } |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 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 | } |
PriyangaRamasamy | d09d2ec | 2020-03-12 14:11:50 +0530 | [diff] [blame] | 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 | } |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 205 | }; |