1 #pragma once 2 3 #include "constants.hpp" 4 #include "logger.hpp" 5 6 #include <filesystem> 7 8 /** 9 * @brief Class to handle backup inventory data. 10 * 11 * This class is used for handling inventory backup data. This contains methods 12 * to handle checking inventory backed up data, restoring said data and 13 * restarting inventory manager service if needed 14 */ 15 class InventoryBackupHandler 16 { 17 public: 18 /* 19 * Deleted methods 20 */ 21 InventoryBackupHandler() = delete; 22 InventoryBackupHandler(const InventoryBackupHandler&) = delete; 23 InventoryBackupHandler operator=(const InventoryBackupHandler&) = delete; 24 InventoryBackupHandler(const InventoryBackupHandler&&) = delete; 25 InventoryBackupHandler operator=(const InventoryBackupHandler&&) = delete; 26 27 /** 28 * @brief Parameterized Constructor 29 * 30 * @param[in] i_inventoryServiceName - Inventory manager service name 31 * @param[in] i_inventoryPrimaryPath - Absolute file path to inventory 32 * manager primary data location 33 * @param[in] i_inventoryBackupPath - Absolute file path to inventory 34 * manager backup data location 35 */ InventoryBackupHandler(const std::string_view i_inventoryServiceName,const std::filesystem::path i_inventoryPrimaryPath,const std::filesystem::path i_inventoryBackupPath)36 InventoryBackupHandler(const std::string_view i_inventoryServiceName, 37 const std::filesystem::path i_inventoryPrimaryPath, 38 const std::filesystem::path i_inventoryBackupPath) : 39 m_inventoryManagerServiceName{i_inventoryServiceName}, 40 m_inventoryPrimaryPath{i_inventoryPrimaryPath}, 41 m_inventoryBackupPath{i_inventoryBackupPath}, 42 m_logger{vpd::Logger::getLoggerInstance()} 43 {} 44 45 /** 46 * @brief API to restore inventory data from backup file path to inventory 47 * persisted path 48 * 49 * @param[out] o_errCode - To set error code in case of error. 50 * 51 * @return true if the restoration is successful, false otherwise 52 * 53 */ 54 bool restoreInventoryBackupData(uint16_t& o_errCode) const noexcept; 55 56 /** 57 * @brief API to clear inventory backup data from backup file path 58 * 59 * @param[out] o_errCode - To set error code in case of error. 60 * 61 * @return true if backup data has been cleared, false otherwise 62 * 63 */ 64 bool clearInventoryBackupData(uint16_t& o_errCode) const noexcept; 65 66 /** 67 * @brief API to restart inventory manager service 68 * 69 * @param[out] o_errCode - To set error code in case of error. 70 * 71 * @return true if inventory manager service is successfully restarted, 72 * false otherwise 73 * 74 */ 75 bool restartInventoryManagerService(uint16_t& o_errCode) const noexcept; 76 77 private: 78 /** 79 * @brief API to check if inventory backup path has data 80 * 81 * @param[out] o_errCode - To set error code in case of error. 82 * 83 * @return true if inventory backup data is found, false otherwise 84 * 85 */ 86 bool checkInventoryBackupPath(uint16_t& o_errCode) const noexcept; 87 88 /* Members */ 89 // inventory manager service name 90 std::string m_inventoryManagerServiceName; 91 92 // inventory data primary path 93 std::filesystem::path m_inventoryPrimaryPath; 94 95 // inventory data backup path 96 std::filesystem::path m_inventoryBackupPath; 97 98 // logger instance 99 std::shared_ptr<vpd::Logger> m_logger{nullptr}; 100 }; 101