xref: /openbmc/openpower-vpd-parser/vpd-manager/include/backup_restore.hpp (revision fa5e4d325ef9cea3c841fe89d202c340f92bd8c6)
1*fa5e4d32SSunny Srivastava #pragma once
2*fa5e4d32SSunny Srivastava 
3*fa5e4d32SSunny Srivastava #include "types.hpp"
4*fa5e4d32SSunny Srivastava 
5*fa5e4d32SSunny Srivastava #include <nlohmann/json.hpp>
6*fa5e4d32SSunny Srivastava 
7*fa5e4d32SSunny Srivastava #include <tuple>
8*fa5e4d32SSunny Srivastava 
9*fa5e4d32SSunny Srivastava namespace vpd
10*fa5e4d32SSunny Srivastava {
11*fa5e4d32SSunny Srivastava 
12*fa5e4d32SSunny Srivastava // Backup and restore operation status.
13*fa5e4d32SSunny Srivastava enum class BackupAndRestoreStatus : uint8_t
14*fa5e4d32SSunny Srivastava {
15*fa5e4d32SSunny Srivastava     NotStarted,
16*fa5e4d32SSunny Srivastava     Invoked,
17*fa5e4d32SSunny Srivastava     Completed
18*fa5e4d32SSunny Srivastava };
19*fa5e4d32SSunny Srivastava 
20*fa5e4d32SSunny Srivastava /**
21*fa5e4d32SSunny Srivastava  * @brief class to implement backup and restore VPD.
22*fa5e4d32SSunny Srivastava  *
23*fa5e4d32SSunny Srivastava  */
24*fa5e4d32SSunny Srivastava 
25*fa5e4d32SSunny Srivastava class BackupAndRestore
26*fa5e4d32SSunny Srivastava {
27*fa5e4d32SSunny Srivastava   public:
28*fa5e4d32SSunny Srivastava     // delete functions
29*fa5e4d32SSunny Srivastava     BackupAndRestore() = delete;
30*fa5e4d32SSunny Srivastava     BackupAndRestore(const BackupAndRestore&) = delete;
31*fa5e4d32SSunny Srivastava     BackupAndRestore& operator=(const BackupAndRestore&) = delete;
32*fa5e4d32SSunny Srivastava     BackupAndRestore(BackupAndRestore&&) = delete;
33*fa5e4d32SSunny Srivastava     BackupAndRestore& operator=(BackupAndRestore&&) = delete;
34*fa5e4d32SSunny Srivastava 
35*fa5e4d32SSunny Srivastava     /**
36*fa5e4d32SSunny Srivastava      * @brief Constructor.
37*fa5e4d32SSunny Srivastava      *
38*fa5e4d32SSunny Srivastava      * @param[in] i_sysCfgJsonObj - System config JSON object.
39*fa5e4d32SSunny Srivastava      *
40*fa5e4d32SSunny Srivastava      * @throw std::runtime_error in case constructor failure.
41*fa5e4d32SSunny Srivastava      */
42*fa5e4d32SSunny Srivastava     BackupAndRestore(const nlohmann::json& i_sysCfgJsonObj);
43*fa5e4d32SSunny Srivastava 
44*fa5e4d32SSunny Srivastava     /**
45*fa5e4d32SSunny Srivastava      * @brief Default destructor.
46*fa5e4d32SSunny Srivastava      */
47*fa5e4d32SSunny Srivastava     ~BackupAndRestore() = default;
48*fa5e4d32SSunny Srivastava 
49*fa5e4d32SSunny Srivastava     /**
50*fa5e4d32SSunny Srivastava      * @brief An API to backup and restore VPD.
51*fa5e4d32SSunny Srivastava      *
52*fa5e4d32SSunny Srivastava      * Note: This API works on the keywords declared in the backup and restore
53*fa5e4d32SSunny Srivastava      * config JSON. Restore or backup action could be triggered for each
54*fa5e4d32SSunny Srivastava      * keyword, based on the keyword's value present in the source and
55*fa5e4d32SSunny Srivastava      * destination keyword.
56*fa5e4d32SSunny Srivastava      *
57*fa5e4d32SSunny Srivastava      * Restore source keyword's value with destination keyword's value,
58*fa5e4d32SSunny Srivastava      * when source keyword has default value but
59*fa5e4d32SSunny Srivastava      * destination's keyword has non default value.
60*fa5e4d32SSunny Srivastava      *
61*fa5e4d32SSunny Srivastava      * Backup the source keyword value to the destination's keyword's value,
62*fa5e4d32SSunny Srivastava      * when source keyword has non default value but
63*fa5e4d32SSunny Srivastava      * destination's keyword has default value.
64*fa5e4d32SSunny Srivastava      *
65*fa5e4d32SSunny Srivastava      * @return Tuple of updated source and destination VPD map variant.
66*fa5e4d32SSunny Srivastava      */
67*fa5e4d32SSunny Srivastava     std::tuple<types::VPDMapVariant, types::VPDMapVariant> backupAndRestore();
68*fa5e4d32SSunny Srivastava 
69*fa5e4d32SSunny Srivastava     /**
70*fa5e4d32SSunny Srivastava      * @brief An API to set backup and restore status.
71*fa5e4d32SSunny Srivastava      *
72*fa5e4d32SSunny Srivastava      * @param[in] i_status - Status to set.
73*fa5e4d32SSunny Srivastava      */
74*fa5e4d32SSunny Srivastava     static void
75*fa5e4d32SSunny Srivastava         setBackupAndRestoreStatus(const BackupAndRestoreStatus& i_status);
76*fa5e4d32SSunny Srivastava 
77*fa5e4d32SSunny Srivastava   private:
78*fa5e4d32SSunny Srivastava     /**
79*fa5e4d32SSunny Srivastava      * @brief An API to handle backup and restore of IPZ type VPD.
80*fa5e4d32SSunny Srivastava      *
81*fa5e4d32SSunny Srivastava      * @param[in,out] io_srcVpdMap - Source VPD map.
82*fa5e4d32SSunny Srivastava      * @param[in,out] io_dstVpdMap - Destination VPD map.
83*fa5e4d32SSunny Srivastava      * @param[in] i_srcPath - Source EEPROM file path or inventory path.
84*fa5e4d32SSunny Srivastava      * @param[in] i_dstPath - Destination EEPROM file path or inventory path.
85*fa5e4d32SSunny Srivastava      *
86*fa5e4d32SSunny Srivastava      * @throw std::runtime_error
87*fa5e4d32SSunny Srivastava      */
88*fa5e4d32SSunny Srivastava     void backupAndRestoreIpzVpd(
89*fa5e4d32SSunny Srivastava         types::IPZVpdMap& io_srcVpdMap, types::IPZVpdMap& io_dstVpdMap,
90*fa5e4d32SSunny Srivastava         const std::string& i_srcPath, const std::string& i_dstPath);
91*fa5e4d32SSunny Srivastava 
92*fa5e4d32SSunny Srivastava     // System JSON config JSON object.
93*fa5e4d32SSunny Srivastava     nlohmann::json m_sysCfgJsonObj{};
94*fa5e4d32SSunny Srivastava 
95*fa5e4d32SSunny Srivastava     // Backup and restore config JSON object.
96*fa5e4d32SSunny Srivastava     nlohmann::json m_backupAndRestoreCfgJsonObj{};
97*fa5e4d32SSunny Srivastava 
98*fa5e4d32SSunny Srivastava     // Backup and restore status.
99*fa5e4d32SSunny Srivastava     static BackupAndRestoreStatus m_backupAndRestoreStatus;
100*fa5e4d32SSunny Srivastava };
101*fa5e4d32SSunny Srivastava 
102*fa5e4d32SSunny Srivastava } // namespace vpd
103