1fa5e4d32SSunny Srivastava #pragma once 2fa5e4d32SSunny Srivastava 3fa5e4d32SSunny Srivastava #include "constants.hpp" 4fa5e4d32SSunny Srivastava #include "types.hpp" 5fa5e4d32SSunny Srivastava 6fa5e4d32SSunny Srivastava #include <iostream> 7fa5e4d32SSunny Srivastava #include <optional> 8fa5e4d32SSunny Srivastava #include <string> 9fa5e4d32SSunny Srivastava #include <unordered_map> 10fa5e4d32SSunny Srivastava 11fa5e4d32SSunny Srivastava namespace vpd 12fa5e4d32SSunny Srivastava { 13fa5e4d32SSunny Srivastava /** 14fa5e4d32SSunny Srivastava * @brief Class for logging events. 15fa5e4d32SSunny Srivastava * 16fa5e4d32SSunny Srivastava * Class handles logging PEL under 'logging' service. 17fa5e4d32SSunny Srivastava * Provide separate async API's for calling out inventory_path, device_path and 18fa5e4d32SSunny Srivastava * i2c bus. 19fa5e4d32SSunny Srivastava */ 20fa5e4d32SSunny Srivastava class EventLogger 21fa5e4d32SSunny Srivastava { 22fa5e4d32SSunny Srivastava public: 23fa5e4d32SSunny Srivastava /** 24*15a189a9SSunny Srivastava * @brief API to get Error type. 25*15a189a9SSunny Srivastava * 26*15a189a9SSunny Srivastava * @param[in] i_exception - Exception object. 27*15a189a9SSunny Srivastava * 28*15a189a9SSunny Srivastava * @return Error type set for the exception. 29*15a189a9SSunny Srivastava * types::ErrorType::InternalFailure otherwise. 30*15a189a9SSunny Srivastava */ 31*15a189a9SSunny Srivastava static types::ErrorType getErrorType(const std::exception& i_exception); 32*15a189a9SSunny Srivastava 33*15a189a9SSunny Srivastava /** 34*15a189a9SSunny Srivastava * @brief API to get Error msg. 35*15a189a9SSunny Srivastava * 36*15a189a9SSunny Srivastava * @param[in] i_exception - Exception object. 37*15a189a9SSunny Srivastava * 38*15a189a9SSunny Srivastava * @return Error msg set for the specific exception. Default error msg 39*15a189a9SSunny Srivastava * otherwise. 40*15a189a9SSunny Srivastava */ 41*15a189a9SSunny Srivastava static std::string getErrorMsg(const std::exception& i_exception); 42*15a189a9SSunny Srivastava 43*15a189a9SSunny Srivastava /** 44fa5e4d32SSunny Srivastava * @brief An API to create a PEL with inventory path callout. 45fa5e4d32SSunny Srivastava * 46fa5e4d32SSunny Srivastava * This API calls an async method to create PEL, and also handles inventory 47fa5e4d32SSunny Srivastava * path callout. 48fa5e4d32SSunny Srivastava * 49fa5e4d32SSunny Srivastava * Note: If inventory path callout info is not provided, it will create a 50fa5e4d32SSunny Srivastava * PEL without any callout. Currently only one callout is handled in this 51fa5e4d32SSunny Srivastava * API. 52fa5e4d32SSunny Srivastava * 53fa5e4d32SSunny Srivastava * @todo: Symbolic FRU and procedure callout needs to be handled in this 54fa5e4d32SSunny Srivastava * API. 55fa5e4d32SSunny Srivastava * 56fa5e4d32SSunny Srivastava * @param[in] i_errorType - Enum to map with event message name. 57fa5e4d32SSunny Srivastava * @param[in] i_severity - Severity of the event. 58fa5e4d32SSunny Srivastava * @param[in] i_callouts - Callout information, list of tuple having 59fa5e4d32SSunny Srivastava * inventory path and priority as input [optional]. 60fa5e4d32SSunny Srivastava * @param[in] i_fileName - File name. 61fa5e4d32SSunny Srivastava * @param[in] i_funcName - Function name. 62fa5e4d32SSunny Srivastava * @param[in] i_internalRc - Internal return code. 63fa5e4d32SSunny Srivastava * @param[in] i_description - Error description. 64fa5e4d32SSunny Srivastava * @param[in] i_userData1 - Additional user data [optional]. 65fa5e4d32SSunny Srivastava * @param[in] i_userData2 - Additional user data [optional]. 66fa5e4d32SSunny Srivastava * @param[in] i_symFru - Symblolic FRU callout data [optional]. 67fa5e4d32SSunny Srivastava * @param[in] i_procedure - Procedure callout data [optional]. 68fa5e4d32SSunny Srivastava * 69fa5e4d32SSunny Srivastava * @throw exception in case of error. 70fa5e4d32SSunny Srivastava */ 71fa5e4d32SSunny Srivastava static void createAsyncPelWithInventoryCallout( 72fa5e4d32SSunny Srivastava const types::ErrorType& i_errorType, 73fa5e4d32SSunny Srivastava const types::SeverityType& i_severity, 74fa5e4d32SSunny Srivastava const std::vector<types::InventoryCalloutData>& i_callouts, 75fa5e4d32SSunny Srivastava const std::string& i_fileName, const std::string& i_funcName, 76fa5e4d32SSunny Srivastava const uint8_t i_internalRc, const std::string& i_description, 77fa5e4d32SSunny Srivastava const std::optional<std::string> i_userData1, 78fa5e4d32SSunny Srivastava const std::optional<std::string> i_userData2, 79fa5e4d32SSunny Srivastava const std::optional<std::string> i_symFru, 80fa5e4d32SSunny Srivastava const std::optional<std::string> i_procedure); 81fa5e4d32SSunny Srivastava 82fa5e4d32SSunny Srivastava /** 83fa5e4d32SSunny Srivastava * @brief An API to create a PEL with device path callout. 84fa5e4d32SSunny Srivastava * 85fa5e4d32SSunny Srivastava * @param[in] i_errorType - Enum to map with event message name. 86fa5e4d32SSunny Srivastava * @param[in] i_severity - Severity of the event. 87fa5e4d32SSunny Srivastava * @param[in] i_callouts - Callout information, list of tuple having device 88fa5e4d32SSunny Srivastava * path and error number as input. 89fa5e4d32SSunny Srivastava * @param[in] i_fileName - File name. 90fa5e4d32SSunny Srivastava * @param[in] i_funcName - Function name. 91fa5e4d32SSunny Srivastava * @param[in] i_internalRc - Internal return code. 92fa5e4d32SSunny Srivastava * @param[in] i_userData1 - Additional user data [optional]. 93fa5e4d32SSunny Srivastava * @param[in] i_userData2 - Additional user data [optional]. 94fa5e4d32SSunny Srivastava */ 95fa5e4d32SSunny Srivastava static void createAsyncPelWithI2cDeviceCallout( 96fa5e4d32SSunny Srivastava const types::ErrorType i_errorType, 97fa5e4d32SSunny Srivastava const types::SeverityType i_severity, 98fa5e4d32SSunny Srivastava const std::vector<types::DeviceCalloutData>& i_callouts, 99fa5e4d32SSunny Srivastava const std::string& i_fileName, const std::string& i_funcName, 100fa5e4d32SSunny Srivastava const uint8_t i_internalRc, 101fa5e4d32SSunny Srivastava const std::optional<std::pair<std::string, std::string>> i_userData1, 102fa5e4d32SSunny Srivastava const std::optional<std::pair<std::string, std::string>> i_userData2); 103fa5e4d32SSunny Srivastava 104fa5e4d32SSunny Srivastava /** 105fa5e4d32SSunny Srivastava * @brief An API to create a PEL with I2c bus callout. 106fa5e4d32SSunny Srivastava * 107fa5e4d32SSunny Srivastava * @param[in] i_errorType - Enum to map with event message name. 108fa5e4d32SSunny Srivastava * @param[in] i_severity - Severity of the event. 109fa5e4d32SSunny Srivastava * @param[in] i_callouts - Callout information, list of tuple having i2c 110fa5e4d32SSunny Srivastava * bus, i2c address and error number as input. 111fa5e4d32SSunny Srivastava * @param[in] i_fileName - File name. 112fa5e4d32SSunny Srivastava * @param[in] i_funcName - Function name. 113fa5e4d32SSunny Srivastava * @param[in] i_internalRc - Internal return code. 114fa5e4d32SSunny Srivastava * @param[in] i_userData1 - Additional user data [optional]. 115fa5e4d32SSunny Srivastava * @param[in] i_userData2 - Additional user data [optional]. 116fa5e4d32SSunny Srivastava */ 117fa5e4d32SSunny Srivastava static void createAsyncPelWithI2cBusCallout( 118fa5e4d32SSunny Srivastava const types::ErrorType i_errorType, 119fa5e4d32SSunny Srivastava const types::SeverityType i_severity, 120fa5e4d32SSunny Srivastava const std::vector<types::I2cBusCalloutData>& i_callouts, 121fa5e4d32SSunny Srivastava const std::string& i_fileName, const std::string& i_funcName, 122fa5e4d32SSunny Srivastava const uint8_t i_internalRc, 123fa5e4d32SSunny Srivastava const std::optional<std::pair<std::string, std::string>> i_userData1, 124fa5e4d32SSunny Srivastava const std::optional<std::pair<std::string, std::string>> i_userData2); 125fa5e4d32SSunny Srivastava 126fa5e4d32SSunny Srivastava /** 127fa5e4d32SSunny Srivastava * @brief An API to create a PEL. 128fa5e4d32SSunny Srivastava * 129fa5e4d32SSunny Srivastava * @param[in] i_errorType - Enum to map with event message name. 130fa5e4d32SSunny Srivastava * @param[in] i_severity - Severity of the event. 131fa5e4d32SSunny Srivastava * @param[in] i_fileName - File name. 132fa5e4d32SSunny Srivastava * @param[in] i_funcName - Function name. 133fa5e4d32SSunny Srivastava * @param[in] i_internalRc - Internal return code. 134fa5e4d32SSunny Srivastava * @param[in] i_description - Error description. 135fa5e4d32SSunny Srivastava * @param[in] i_userData1 - Additional user data [optional]. 136fa5e4d32SSunny Srivastava * @param[in] i_userData2 - Additional user data [optional]. 137fa5e4d32SSunny Srivastava * @param[in] i_symFru - Symblolic FRU callout data [optional]. 138fa5e4d32SSunny Srivastava * @param[in] i_procedure - Procedure callout data [optional]. 139fa5e4d32SSunny Srivastava * 140fa5e4d32SSunny Srivastava * @todo: Symbolic FRU and procedure callout needs to be handled in this 141fa5e4d32SSunny Srivastava * API. 142fa5e4d32SSunny Srivastava */ 143fa5e4d32SSunny Srivastava static void createAsyncPel( 144fa5e4d32SSunny Srivastava const types::ErrorType& i_errorType, 145fa5e4d32SSunny Srivastava const types::SeverityType& i_severity, const std::string& i_fileName, 146fa5e4d32SSunny Srivastava const std::string& i_funcName, const uint8_t i_internalRc, 147fa5e4d32SSunny Srivastava const std::string& i_description, 148fa5e4d32SSunny Srivastava const std::optional<std::string> i_userData1, 149fa5e4d32SSunny Srivastava const std::optional<std::string> i_userData2, 150fa5e4d32SSunny Srivastava const std::optional<std::string> i_symFru, 151fa5e4d32SSunny Srivastava const std::optional<std::string> i_procedure); 152fa5e4d32SSunny Srivastava 153fa5e4d32SSunny Srivastava /** 154fa5e4d32SSunny Srivastava * @brief An API to create PEL. 155fa5e4d32SSunny Srivastava * 156fa5e4d32SSunny Srivastava * This API makes synchronous call to phosphor-logging Create method. 157fa5e4d32SSunny Srivastava * 158fa5e4d32SSunny Srivastava * @param[in] i_errorType - Enum to map with event message name. 159fa5e4d32SSunny Srivastava * @param[in] i_severity - Severity of the event. 160fa5e4d32SSunny Srivastava * @param[in] i_fileName - File name. 161fa5e4d32SSunny Srivastava * @param[in] i_funcName - Function name. 162fa5e4d32SSunny Srivastava * @param[in] i_internalRc - Internal return code. 163fa5e4d32SSunny Srivastava * @param[in] i_description - Error description. 164fa5e4d32SSunny Srivastava * @param[in] i_userData1 - Additional user data [optional]. 165fa5e4d32SSunny Srivastava * @param[in] i_userData2 - Additional user data [optional]. 166fa5e4d32SSunny Srivastava * @param[in] i_symFru - Symblolic FRU callout data [optional].s 167fa5e4d32SSunny Srivastava * @param[in] i_procedure - Procedure callout data [optional]. 168fa5e4d32SSunny Srivastava * 169fa5e4d32SSunny Srivastava * @todo: Symbolic FRU and procedure callout needs to be handled in this 170fa5e4d32SSunny Srivastava * API. 171fa5e4d32SSunny Srivastava */ 172fa5e4d32SSunny Srivastava static void createSyncPel( 173fa5e4d32SSunny Srivastava const types::ErrorType& i_errorType, 174fa5e4d32SSunny Srivastava const types::SeverityType& i_severity, const std::string& i_fileName, 175fa5e4d32SSunny Srivastava const std::string& i_funcName, const uint8_t i_internalRc, 176fa5e4d32SSunny Srivastava const std::string& i_description, 177fa5e4d32SSunny Srivastava const std::optional<std::string> i_userData1, 178fa5e4d32SSunny Srivastava const std::optional<std::string> i_userData2, 179fa5e4d32SSunny Srivastava const std::optional<std::string> i_symFru, 180fa5e4d32SSunny Srivastava const std::optional<std::string> i_procedure); 181fa5e4d32SSunny Srivastava 182fa5e4d32SSunny Srivastava private: 183b53d97c9SAnupama B R /** 184b53d97c9SAnupama B R * @brief API to get error info based on the exception. 185b53d97c9SAnupama B R * 186b53d97c9SAnupama B R * @param[in] i_exception - Exception object. 187b53d97c9SAnupama B R * 188b53d97c9SAnupama B R * @return - Valid ExceptionDataMap on success, otherwise map having default 189b53d97c9SAnupama B R * value. 190b53d97c9SAnupama B R */ 191b53d97c9SAnupama B R static types::ExceptionDataMap getExceptionData( 192b53d97c9SAnupama B R const std::exception& i_exception); 193b53d97c9SAnupama B R 194fa5e4d32SSunny Srivastava static const std::unordered_map<types::SeverityType, std::string> 195fa5e4d32SSunny Srivastava m_severityMap; 196fa5e4d32SSunny Srivastava static const std::unordered_map<types::ErrorType, std::string> 197fa5e4d32SSunny Srivastava m_errorMsgMap; 198fa5e4d32SSunny Srivastava static const std::unordered_map<types::CalloutPriority, std::string> 199fa5e4d32SSunny Srivastava m_priorityMap; 200fa5e4d32SSunny Srivastava }; 201fa5e4d32SSunny Srivastava } // namespace vpd 202