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