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