1 #pragma once 2 3 #include "types.hpp" 4 5 #include <nlohmann/json.hpp> 6 7 #include <tuple> 8 9 namespace vpd 10 { 11 12 // Backup and restore operation status. 13 enum class BackupAndRestoreStatus : uint8_t 14 { 15 NotStarted, 16 Invoked, 17 Completed 18 }; 19 20 /** 21 * @brief class to implement backup and restore VPD. 22 * 23 */ 24 25 class BackupAndRestore 26 { 27 public: 28 // delete functions 29 BackupAndRestore() = delete; 30 BackupAndRestore(const BackupAndRestore&) = delete; 31 BackupAndRestore& operator=(const BackupAndRestore&) = delete; 32 BackupAndRestore(BackupAndRestore&&) = delete; 33 BackupAndRestore& operator=(BackupAndRestore&&) = delete; 34 35 /** 36 * @brief Constructor. 37 * 38 * @param[in] i_sysCfgJsonObj - System config JSON object. 39 * 40 * @throw std::runtime_error in case constructor failure. 41 */ 42 BackupAndRestore(const nlohmann::json& i_sysCfgJsonObj); 43 44 /** 45 * @brief Default destructor. 46 */ 47 ~BackupAndRestore() = default; 48 49 /** 50 * @brief An API to backup and restore VPD. 51 * 52 * Note: This API works on the keywords declared in the backup and restore 53 * config JSON. Restore or backup action could be triggered for each 54 * keyword, based on the keyword's value present in the source and 55 * destination keyword. 56 * 57 * Restore source keyword's value with destination keyword's value, 58 * when source keyword has default value but 59 * destination's keyword has non default value. 60 * 61 * Backup the source keyword value to the destination's keyword's value, 62 * when source keyword has non default value but 63 * destination's keyword has default value. 64 * 65 * @return Tuple of updated source and destination VPD map variant. 66 */ 67 std::tuple<types::VPDMapVariant, types::VPDMapVariant> backupAndRestore(); 68 69 /** 70 * @brief An API to set backup and restore status. 71 * 72 * @param[in] i_status - Status to set. 73 */ 74 static void setBackupAndRestoreStatus( 75 const BackupAndRestoreStatus& i_status); 76 77 /** 78 * @brief An API to update keyword's value on primary or backup path. 79 * 80 * Updates the keyword's value based on the following, 81 * 1. If provided i_fruPath is primary(source) path in the backup restore 82 * config JSON, then API updates VPD on the backup(destination) path. 83 * 2. If i_fruPath is backup path, then API updates the VPD on the 84 * primary path. 85 * 86 * Note: The above condition is only valid, 87 * 1. If system's primary & backup VPD is on EEPROM path(and should be found 88 * in the backup and restore config JSON). 89 * 2. If the input record and keyword are found in the backup and restore 90 * config JSON. 91 * 92 * @param[in] i_fruPath - EEPROM path of the FRU. 93 * @param[in] i_paramsToWriteData - Input details. 94 * 95 * @return On success returns number of bytes written, -1 on failure. 96 */ 97 int updateKeywordOnPrimaryOrBackupPath( 98 const std::string& i_fruPath, 99 const types::WriteVpdParams& i_paramsToWriteData) const noexcept; 100 101 private: 102 /** 103 * @brief An API to handle backup and restore of IPZ type VPD. 104 * 105 * @param[in,out] io_srcVpdMap - Source VPD map. 106 * @param[in,out] io_dstVpdMap - Destination VPD map. 107 * @param[in] i_srcPath - Source EEPROM file path or inventory path. 108 * @param[in] i_dstPath - Destination EEPROM file path or inventory path. 109 * 110 * @throw std::runtime_error 111 */ 112 void backupAndRestoreIpzVpd( 113 types::IPZVpdMap& io_srcVpdMap, types::IPZVpdMap& io_dstVpdMap, 114 const std::string& i_srcPath, const std::string& i_dstPath); 115 116 // System JSON config JSON object. 117 nlohmann::json m_sysCfgJsonObj{}; 118 119 // Backup and restore config JSON object. 120 nlohmann::json m_backupAndRestoreCfgJsonObj{}; 121 122 // Backup and restore status. 123 static BackupAndRestoreStatus m_backupAndRestoreStatus; 124 }; 125 126 } // namespace vpd 127