1fa5e4d32SSunny Srivastava #pragma once 2fa5e4d32SSunny Srivastava 3*f2dbe2efSPriyanga Ramasamy #include "types.hpp" 4*f2dbe2efSPriyanga Ramasamy 5fa5e4d32SSunny Srivastava #include <stdexcept> 6fa5e4d32SSunny Srivastava 7fa5e4d32SSunny Srivastava namespace vpd 8fa5e4d32SSunny Srivastava { 9fa5e4d32SSunny Srivastava /** @class Exception 10fa5e4d32SSunny Srivastava * @brief This class inherits std::runtime_error and overrrides "what" method 11fa5e4d32SSunny Srivastava * to return the description of exception. 12fa5e4d32SSunny Srivastava * This class also works as base class for custom exception classes for 13fa5e4d32SSunny Srivastava * VPD repository. 14fa5e4d32SSunny Srivastava */ 15fa5e4d32SSunny Srivastava class Exception : public std::runtime_error 16fa5e4d32SSunny Srivastava { 17fa5e4d32SSunny Srivastava public: 18fa5e4d32SSunny Srivastava // deleted methods 19fa5e4d32SSunny Srivastava Exception() = delete; 20fa5e4d32SSunny Srivastava Exception(const Exception&) = delete; 21fa5e4d32SSunny Srivastava Exception(Exception&&) = delete; 22fa5e4d32SSunny Srivastava Exception& operator=(const Exception&) = delete; 23fa5e4d32SSunny Srivastava 24fa5e4d32SSunny Srivastava // default destructor 25fa5e4d32SSunny Srivastava ~Exception() = default; 26fa5e4d32SSunny Srivastava 27fa5e4d32SSunny Srivastava /** @brief constructor 28fa5e4d32SSunny Srivastava * 29fa5e4d32SSunny Srivastava * @param[in] msg - Information w.r.t exception. 30fa5e4d32SSunny Srivastava */ Exception(const std::string & msg)31fa5e4d32SSunny Srivastava explicit Exception(const std::string& msg) : 32fa5e4d32SSunny Srivastava std::runtime_error(msg), m_errMsg(msg) 33fa5e4d32SSunny Srivastava {} 34fa5e4d32SSunny Srivastava 35fa5e4d32SSunny Srivastava /** @brief inline method to return exception string. 36fa5e4d32SSunny Srivastava * 37fa5e4d32SSunny Srivastava * This is overridden method of std::runtime class. 38fa5e4d32SSunny Srivastava */ what() const39fa5e4d32SSunny Srivastava inline const char* what() const noexcept override 40fa5e4d32SSunny Srivastava { 41fa5e4d32SSunny Srivastava return m_errMsg.c_str(); 42fa5e4d32SSunny Srivastava } 43fa5e4d32SSunny Srivastava 44*f2dbe2efSPriyanga Ramasamy // TODO: Create getErrorType api by defining VPD default error type 45*f2dbe2efSPriyanga Ramasamy 46fa5e4d32SSunny Srivastava private: 47fa5e4d32SSunny Srivastava /** @brief string to hold the reason of exception */ 48fa5e4d32SSunny Srivastava std::string m_errMsg; 49fa5e4d32SSunny Srivastava 50fa5e4d32SSunny Srivastava }; // class Exception 51fa5e4d32SSunny Srivastava 52fa5e4d32SSunny Srivastava /** @class EccException 53fa5e4d32SSunny Srivastava * 54fa5e4d32SSunny Srivastava * @brief This class extends Exceptions class and define type for ECC related 55fa5e4d32SSunny Srivastava * exception in VPD. 56fa5e4d32SSunny Srivastava */ 57fa5e4d32SSunny Srivastava class EccException : public Exception 58fa5e4d32SSunny Srivastava { 59fa5e4d32SSunny Srivastava public: 60fa5e4d32SSunny Srivastava // deleted methods 61fa5e4d32SSunny Srivastava EccException() = delete; 62fa5e4d32SSunny Srivastava EccException(const EccException&) = delete; 63fa5e4d32SSunny Srivastava EccException(EccException&&) = delete; 64fa5e4d32SSunny Srivastava EccException& operator=(const EccException&) = delete; 65fa5e4d32SSunny Srivastava 66fa5e4d32SSunny Srivastava // default destructor 67fa5e4d32SSunny Srivastava ~EccException() = default; 68fa5e4d32SSunny Srivastava 69fa5e4d32SSunny Srivastava /** @brief constructor 70fa5e4d32SSunny Srivastava * 71fa5e4d32SSunny Srivastava * @param[in] msg - Information w.r.t exception. 72fa5e4d32SSunny Srivastava */ EccException(const std::string & msg)73fa5e4d32SSunny Srivastava explicit EccException(const std::string& msg) : Exception(msg) {} 74fa5e4d32SSunny Srivastava 75*f2dbe2efSPriyanga Ramasamy /** @brief Method to get error type 76*f2dbe2efSPriyanga Ramasamy * 77*f2dbe2efSPriyanga Ramasamy * @return Error type which has to be logged for errors of type 78*f2dbe2efSPriyanga Ramasamy * EccException. 79*f2dbe2efSPriyanga Ramasamy */ getErrorType() const80*f2dbe2efSPriyanga Ramasamy types::ErrorType getErrorType() const 81*f2dbe2efSPriyanga Ramasamy { 82*f2dbe2efSPriyanga Ramasamy return types::ErrorType::EccCheckFailed; 83*f2dbe2efSPriyanga Ramasamy } 84*f2dbe2efSPriyanga Ramasamy 85fa5e4d32SSunny Srivastava }; // class EccException 86fa5e4d32SSunny Srivastava 87fa5e4d32SSunny Srivastava /** @class DataException 88fa5e4d32SSunny Srivastava * 89fa5e4d32SSunny Srivastava * @brief This class extends Exceptions class and define type for data related 90fa5e4d32SSunny Srivastava * exception in VPD 91fa5e4d32SSunny Srivastava */ 92fa5e4d32SSunny Srivastava class DataException : public Exception 93fa5e4d32SSunny Srivastava { 94fa5e4d32SSunny Srivastava public: 95fa5e4d32SSunny Srivastava // deleted methods 96fa5e4d32SSunny Srivastava DataException() = delete; 97fa5e4d32SSunny Srivastava DataException(const DataException&) = delete; 98fa5e4d32SSunny Srivastava DataException(DataException&&) = delete; 99fa5e4d32SSunny Srivastava DataException& operator=(const DataException&) = delete; 100fa5e4d32SSunny Srivastava 101fa5e4d32SSunny Srivastava // default destructor 102fa5e4d32SSunny Srivastava ~DataException() = default; 103fa5e4d32SSunny Srivastava 104fa5e4d32SSunny Srivastava /** @brief constructor 105fa5e4d32SSunny Srivastava * 106fa5e4d32SSunny Srivastava * @param[in] msg - string to define exception 107fa5e4d32SSunny Srivastava */ DataException(const std::string & msg)108fa5e4d32SSunny Srivastava explicit DataException(const std::string& msg) : Exception(msg) {} 109fa5e4d32SSunny Srivastava 110*f2dbe2efSPriyanga Ramasamy /** @brief Method to get error type 111*f2dbe2efSPriyanga Ramasamy * 112*f2dbe2efSPriyanga Ramasamy * @return Error type which has to be logged for errors of type 113*f2dbe2efSPriyanga Ramasamy * DataException. 114*f2dbe2efSPriyanga Ramasamy */ getErrorType() const115*f2dbe2efSPriyanga Ramasamy types::ErrorType getErrorType() const 116*f2dbe2efSPriyanga Ramasamy { 117*f2dbe2efSPriyanga Ramasamy return types::ErrorType::InvalidVpdMessage; 118*f2dbe2efSPriyanga Ramasamy } 119fa5e4d32SSunny Srivastava }; // class DataException 120fa5e4d32SSunny Srivastava 121fa5e4d32SSunny Srivastava class JsonException : public Exception 122fa5e4d32SSunny Srivastava { 123fa5e4d32SSunny Srivastava public: 124fa5e4d32SSunny Srivastava // deleted methods 125fa5e4d32SSunny Srivastava JsonException() = delete; 126fa5e4d32SSunny Srivastava JsonException(const JsonException&) = delete; 127fa5e4d32SSunny Srivastava JsonException(JsonException&&) = delete; 128fa5e4d32SSunny Srivastava JsonException& operator=(const JsonException&) = delete; 129fa5e4d32SSunny Srivastava 130fa5e4d32SSunny Srivastava // default destructor 131fa5e4d32SSunny Srivastava ~JsonException() = default; 132fa5e4d32SSunny Srivastava 133fa5e4d32SSunny Srivastava /** @brief constructor 134fa5e4d32SSunny Srivastava * @param[in] msg - Information w.r.t. exception. 135fa5e4d32SSunny Srivastava * @param[in] path - Json path 136fa5e4d32SSunny Srivastava */ JsonException(const std::string & msg,const std::string & path)137fa5e4d32SSunny Srivastava JsonException(const std::string& msg, const std::string& path) : 138fa5e4d32SSunny Srivastava Exception(msg), m_jsonPath(path) 139fa5e4d32SSunny Srivastava {} 140fa5e4d32SSunny Srivastava 141fa5e4d32SSunny Srivastava /** @brief Json path getter method. 142fa5e4d32SSunny Srivastava * 143fa5e4d32SSunny Srivastava * @return - Json path 144fa5e4d32SSunny Srivastava */ getJsonPath() const145fa5e4d32SSunny Srivastava inline std::string getJsonPath() const 146fa5e4d32SSunny Srivastava { 147fa5e4d32SSunny Srivastava return m_jsonPath; 148fa5e4d32SSunny Srivastava } 149fa5e4d32SSunny Srivastava 150*f2dbe2efSPriyanga Ramasamy /** @brief Method to get error type 151*f2dbe2efSPriyanga Ramasamy * 152*f2dbe2efSPriyanga Ramasamy * @return Error type which has to be logged for errors of type 153*f2dbe2efSPriyanga Ramasamy * JsonException. 154*f2dbe2efSPriyanga Ramasamy */ getErrorType() const155*f2dbe2efSPriyanga Ramasamy types::ErrorType getErrorType() const 156*f2dbe2efSPriyanga Ramasamy { 157*f2dbe2efSPriyanga Ramasamy return types::ErrorType::JsonFailure; 158*f2dbe2efSPriyanga Ramasamy } 159*f2dbe2efSPriyanga Ramasamy 160fa5e4d32SSunny Srivastava private: 161fa5e4d32SSunny Srivastava /** To hold the path of Json that failed*/ 162fa5e4d32SSunny Srivastava std::string m_jsonPath; 163fa5e4d32SSunny Srivastava 164fa5e4d32SSunny Srivastava }; // class JSonException 165fa5e4d32SSunny Srivastava 166fa5e4d32SSunny Srivastava /** @class GpioException 167fa5e4d32SSunny Srivastava * @brief Custom handler for GPIO exception. 168fa5e4d32SSunny Srivastava * 169fa5e4d32SSunny Srivastava * This class extends Exceptions class and define 170fa5e4d32SSunny Srivastava * type for GPIO related exception in VPD. 171fa5e4d32SSunny Srivastava */ 172fa5e4d32SSunny Srivastava class GpioException : public Exception 173fa5e4d32SSunny Srivastava { 174fa5e4d32SSunny Srivastava public: 175fa5e4d32SSunny Srivastava // deleted methods 176fa5e4d32SSunny Srivastava GpioException() = delete; 177fa5e4d32SSunny Srivastava GpioException(const GpioException&) = delete; 178fa5e4d32SSunny Srivastava GpioException(GpioException&&) = delete; 179fa5e4d32SSunny Srivastava GpioException& operator=(const GpioException&) = delete; 180fa5e4d32SSunny Srivastava 181fa5e4d32SSunny Srivastava // default destructor 182fa5e4d32SSunny Srivastava ~GpioException() = default; 183fa5e4d32SSunny Srivastava 184fa5e4d32SSunny Srivastava /** @brief constructor 185fa5e4d32SSunny Srivastava * @param[in] msg - string to define exception 186fa5e4d32SSunny Srivastava */ GpioException(const std::string & msg)187fa5e4d32SSunny Srivastava explicit GpioException(const std::string& msg) : Exception(msg) {} 188*f2dbe2efSPriyanga Ramasamy 189*f2dbe2efSPriyanga Ramasamy /** @brief Method to get error type 190*f2dbe2efSPriyanga Ramasamy * 191*f2dbe2efSPriyanga Ramasamy * @return Error type which has to be logged for errors of type 192*f2dbe2efSPriyanga Ramasamy * GpioException. 193*f2dbe2efSPriyanga Ramasamy */ getErrorType() const194*f2dbe2efSPriyanga Ramasamy types::ErrorType getErrorType() const 195*f2dbe2efSPriyanga Ramasamy { 196*f2dbe2efSPriyanga Ramasamy return types::ErrorType::GpioError; 197*f2dbe2efSPriyanga Ramasamy } 198fa5e4d32SSunny Srivastava }; 199fa5e4d32SSunny Srivastava 200a88a298fSSunny Srivastava /** @class DbusException 201a88a298fSSunny Srivastava * @brief Custom handler for Dbus exception. 202a88a298fSSunny Srivastava * 203a88a298fSSunny Srivastava * This class extends Exceptions class and define 204a88a298fSSunny Srivastava * type for DBus related exception in VPD. 205a88a298fSSunny Srivastava */ 206a88a298fSSunny Srivastava class DbusException : public Exception 207a88a298fSSunny Srivastava { 208a88a298fSSunny Srivastava public: 209a88a298fSSunny Srivastava // deleted methods 210a88a298fSSunny Srivastava DbusException() = delete; 211a88a298fSSunny Srivastava DbusException(const DbusException&) = delete; 212a88a298fSSunny Srivastava DbusException(DbusException&&) = delete; 213a88a298fSSunny Srivastava DbusException& operator=(const DbusException&) = delete; 214a88a298fSSunny Srivastava 215a88a298fSSunny Srivastava // default destructor 216a88a298fSSunny Srivastava ~DbusException() = default; 217a88a298fSSunny Srivastava 218a88a298fSSunny Srivastava /** @brief constructor 219a88a298fSSunny Srivastava * @param[in] msg - string to define exception 220a88a298fSSunny Srivastava */ DbusException(const std::string & msg)221a88a298fSSunny Srivastava explicit DbusException(const std::string& msg) : Exception(msg) {} 222*f2dbe2efSPriyanga Ramasamy 223*f2dbe2efSPriyanga Ramasamy /** @brief Method to get error type 224*f2dbe2efSPriyanga Ramasamy * 225*f2dbe2efSPriyanga Ramasamy * @return Error type which has to be logged for errors of type 226*f2dbe2efSPriyanga Ramasamy * DbusException. 227*f2dbe2efSPriyanga Ramasamy */ getErrorType() const228*f2dbe2efSPriyanga Ramasamy types::ErrorType getErrorType() const 229*f2dbe2efSPriyanga Ramasamy { 230*f2dbe2efSPriyanga Ramasamy return types::ErrorType::DbusFailure; 231*f2dbe2efSPriyanga Ramasamy } 232a88a298fSSunny Srivastava }; 233a88a298fSSunny Srivastava 234a88a298fSSunny Srivastava /** @class FirmwareException 235a88a298fSSunny Srivastava * @brief Custom handler for firmware exception. 236a88a298fSSunny Srivastava * 237a88a298fSSunny Srivastava * This class extends Exceptions class and define 238a88a298fSSunny Srivastava * type for generic firmware related exception in VPD. 239a88a298fSSunny Srivastava */ 240a88a298fSSunny Srivastava class FirmwareException : public Exception 241a88a298fSSunny Srivastava { 242a88a298fSSunny Srivastava public: 243a88a298fSSunny Srivastava // deleted methods 244a88a298fSSunny Srivastava FirmwareException() = delete; 245a88a298fSSunny Srivastava FirmwareException(const FirmwareException&) = delete; 246a88a298fSSunny Srivastava FirmwareException(FirmwareException&&) = delete; 247a88a298fSSunny Srivastava FirmwareException& operator=(const FirmwareException&) = delete; 248a88a298fSSunny Srivastava 249a88a298fSSunny Srivastava // default destructor 250a88a298fSSunny Srivastava ~FirmwareException() = default; 251a88a298fSSunny Srivastava 252a88a298fSSunny Srivastava /** @brief constructor 253a88a298fSSunny Srivastava * @param[in] msg - string to define exception 254a88a298fSSunny Srivastava */ FirmwareException(const std::string & msg)255a88a298fSSunny Srivastava explicit FirmwareException(const std::string& msg) : Exception(msg) {} 256*f2dbe2efSPriyanga Ramasamy 257*f2dbe2efSPriyanga Ramasamy /** @brief Method to get error type 258*f2dbe2efSPriyanga Ramasamy * 259*f2dbe2efSPriyanga Ramasamy * @return Error type which has to be logged for errors of type 260*f2dbe2efSPriyanga Ramasamy * FirmwareException. 261*f2dbe2efSPriyanga Ramasamy */ getErrorType() const262*f2dbe2efSPriyanga Ramasamy types::ErrorType getErrorType() const 263*f2dbe2efSPriyanga Ramasamy { 264*f2dbe2efSPriyanga Ramasamy return types::ErrorType::InternalFailure; 265*f2dbe2efSPriyanga Ramasamy } 266a88a298fSSunny Srivastava }; 267a88a298fSSunny Srivastava 268a88a298fSSunny Srivastava /** @class EepromException 269a88a298fSSunny Srivastava * @brief Custom handler for EEPROM exception. 270a88a298fSSunny Srivastava * 271a88a298fSSunny Srivastava * This class extends Exceptions class and define 272a88a298fSSunny Srivastava * type for EEPROM related exception in VPD. 273a88a298fSSunny Srivastava */ 274a88a298fSSunny Srivastava class EepromException : public Exception 275a88a298fSSunny Srivastava { 276a88a298fSSunny Srivastava public: 277a88a298fSSunny Srivastava // deleted methods 278a88a298fSSunny Srivastava EepromException() = delete; 279a88a298fSSunny Srivastava EepromException(const EepromException&) = delete; 280a88a298fSSunny Srivastava EepromException(EepromException&&) = delete; 281a88a298fSSunny Srivastava EepromException& operator=(const EepromException&) = delete; 282a88a298fSSunny Srivastava 283a88a298fSSunny Srivastava // default destructor 284a88a298fSSunny Srivastava ~EepromException() = default; 285a88a298fSSunny Srivastava 286a88a298fSSunny Srivastava /** @brief constructor 287a88a298fSSunny Srivastava * @param[in] msg - string to define exception 288a88a298fSSunny Srivastava */ EepromException(const std::string & msg)289a88a298fSSunny Srivastava explicit EepromException(const std::string& msg) : Exception(msg) {} 290*f2dbe2efSPriyanga Ramasamy 291*f2dbe2efSPriyanga Ramasamy /** @brief Method to get error type 292*f2dbe2efSPriyanga Ramasamy * 293*f2dbe2efSPriyanga Ramasamy * @return Error type which has to be logged for errors of type 294*f2dbe2efSPriyanga Ramasamy * EepromException. 295*f2dbe2efSPriyanga Ramasamy */ getErrorType() const296*f2dbe2efSPriyanga Ramasamy types::ErrorType getErrorType() const 297*f2dbe2efSPriyanga Ramasamy { 298*f2dbe2efSPriyanga Ramasamy return types::ErrorType::InvalidEeprom; 299*f2dbe2efSPriyanga Ramasamy } 300a88a298fSSunny Srivastava }; 301a88a298fSSunny Srivastava 302fa5e4d32SSunny Srivastava } // namespace vpd 303