xref: /openbmc/openpower-vpd-parser/vpd-manager/include/event_logger.hpp (revision fa5e4d325ef9cea3c841fe89d202c340f92bd8c6)
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     /**
24      * @brief An API to create a PEL with inventory path callout.
25      *
26      * This API calls an async method to create PEL, and also handles inventory
27      * path callout.
28      *
29      * Note: If inventory path callout info is not provided, it will create a
30      * PEL without any callout. Currently only one callout is handled in this
31      * API.
32      *
33      * @todo: Symbolic FRU and procedure callout needs to be handled in this
34      * API.
35      *
36      * @param[in] i_errorType - Enum to map with event message name.
37      * @param[in] i_severity - Severity of the event.
38      * @param[in] i_callouts - Callout information, list of tuple having
39      * inventory path and priority as input [optional].
40      * @param[in] i_fileName - File name.
41      * @param[in] i_funcName - Function name.
42      * @param[in] i_internalRc - Internal return code.
43      * @param[in] i_description - Error description.
44      * @param[in] i_userData1 - Additional user data [optional].
45      * @param[in] i_userData2 - Additional user data [optional].
46      * @param[in] i_symFru - Symblolic FRU callout data [optional].
47      * @param[in] i_procedure - Procedure callout data [optional].
48      *
49      * @throw exception in case of error.
50      */
51     static void createAsyncPelWithInventoryCallout(
52         const types::ErrorType& i_errorType,
53         const types::SeverityType& i_severity,
54         const std::vector<types::InventoryCalloutData>& i_callouts,
55         const std::string& i_fileName, const std::string& i_funcName,
56         const uint8_t i_internalRc, const std::string& i_description,
57         const std::optional<std::string> i_userData1,
58         const std::optional<std::string> i_userData2,
59         const std::optional<std::string> i_symFru,
60         const std::optional<std::string> i_procedure);
61 
62     /**
63      * @brief An API to create a PEL with device path callout.
64      *
65      * @param[in] i_errorType - Enum to map with event message name.
66      * @param[in] i_severity - Severity of the event.
67      * @param[in] i_callouts - Callout information, list of tuple having device
68      * path and error number as input.
69      * @param[in] i_fileName - File name.
70      * @param[in] i_funcName - Function name.
71      * @param[in] i_internalRc - Internal return code.
72      * @param[in] i_userData1 - Additional user data [optional].
73      * @param[in] i_userData2 - Additional user data [optional].
74      */
75     static void createAsyncPelWithI2cDeviceCallout(
76         const types::ErrorType i_errorType,
77         const types::SeverityType i_severity,
78         const std::vector<types::DeviceCalloutData>& i_callouts,
79         const std::string& i_fileName, const std::string& i_funcName,
80         const uint8_t i_internalRc,
81         const std::optional<std::pair<std::string, std::string>> i_userData1,
82         const std::optional<std::pair<std::string, std::string>> i_userData2);
83 
84     /**
85      * @brief An API to create a PEL with I2c bus callout.
86      *
87      * @param[in] i_errorType - Enum to map with event message name.
88      * @param[in] i_severity - Severity of the event.
89      * @param[in] i_callouts - Callout information, list of tuple having i2c
90      * bus, i2c address and error number as input.
91      * @param[in] i_fileName - File name.
92      * @param[in] i_funcName - Function name.
93      * @param[in] i_internalRc - Internal return code.
94      * @param[in] i_userData1 - Additional user data [optional].
95      * @param[in] i_userData2 - Additional user data [optional].
96      */
97     static void createAsyncPelWithI2cBusCallout(
98         const types::ErrorType i_errorType,
99         const types::SeverityType i_severity,
100         const std::vector<types::I2cBusCalloutData>& i_callouts,
101         const std::string& i_fileName, const std::string& i_funcName,
102         const uint8_t i_internalRc,
103         const std::optional<std::pair<std::string, std::string>> i_userData1,
104         const std::optional<std::pair<std::string, std::string>> i_userData2);
105 
106     /**
107      * @brief An API to create a PEL.
108      *
109      * @param[in] i_errorType - Enum to map with event message name.
110      * @param[in] i_severity - Severity of the event.
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_description - Error description.
115      * @param[in] i_userData1 - Additional user data [optional].
116      * @param[in] i_userData2 - Additional user data [optional].
117      * @param[in] i_symFru - Symblolic FRU callout data [optional].
118      * @param[in] i_procedure - Procedure callout data [optional].
119      *
120      * @todo: Symbolic FRU and procedure callout needs to be handled in this
121      * API.
122      */
123     static void createAsyncPel(
124         const types::ErrorType& i_errorType,
125         const types::SeverityType& i_severity, const std::string& i_fileName,
126         const std::string& i_funcName, const uint8_t i_internalRc,
127         const std::string& i_description,
128         const std::optional<std::string> i_userData1,
129         const std::optional<std::string> i_userData2,
130         const std::optional<std::string> i_symFru,
131         const std::optional<std::string> i_procedure);
132 
133     /**
134      * @brief An API to create PEL.
135      *
136      * This API makes synchronous call to phosphor-logging Create method.
137      *
138      * @param[in] i_errorType - Enum to map with event message name.
139      * @param[in] i_severity - Severity of the event.
140      * @param[in] i_fileName - File name.
141      * @param[in] i_funcName - Function name.
142      * @param[in] i_internalRc - Internal return code.
143      * @param[in] i_description - Error description.
144      * @param[in] i_userData1 - Additional user data [optional].
145      * @param[in] i_userData2 - Additional user data [optional].
146      * @param[in] i_symFru - Symblolic FRU callout data [optional].s
147      * @param[in] i_procedure - Procedure callout data [optional].
148      *
149      * @todo: Symbolic FRU and procedure callout needs to be handled in this
150      * API.
151      */
152     static void createSyncPel(
153         const types::ErrorType& i_errorType,
154         const types::SeverityType& i_severity, const std::string& i_fileName,
155         const std::string& i_funcName, const uint8_t i_internalRc,
156         const std::string& i_description,
157         const std::optional<std::string> i_userData1,
158         const std::optional<std::string> i_userData2,
159         const std::optional<std::string> i_symFru,
160         const std::optional<std::string> i_procedure);
161 
162   private:
163     static const std::unordered_map<types::SeverityType, std::string>
164         m_severityMap;
165     static const std::unordered_map<types::ErrorType, std::string>
166         m_errorMsgMap;
167     static const std::unordered_map<types::CalloutPriority, std::string>
168         m_priorityMap;
169 };
170 } // namespace vpd
171