blob: 727e2887f4fc9c0451c846a76ab4f9e8bf1ef0b7 [file] [log] [blame]
Matt Spinler99c2b402019-05-23 14:29:16 -05001#pragma once
2
3#include "elog_entry.hpp"
4#include "log_manager.hpp"
5
6#include <functional>
7#include <vector>
8
9namespace phosphor
10{
11namespace logging
12{
13
14/**
15 * @brief The function type that will be called on start up.
16 * @param[in] internal::Manager& - A reference to the Manager class.
17 */
18using StartupFunction = std::function<void(internal::Manager&)>;
19
20using AdditionalDataArg = std::vector<std::string>;
21using AssociationEndpointsArg = std::vector<std::string>;
Matt Spinlerc64b7122020-03-26 10:55:01 -050022using FFDCArg = FFDCEntries;
23
Matt Spinler99c2b402019-05-23 14:29:16 -050024/**
25 * @brief The function type that will be called after an event log
26 * is created.
27 * @param[in] const std::string& - The Message property
28 * @param[in] uin32_t - The event log ID
29 * @param[in] uint64_t - The event log timestamp
30 * @param[in] Level - The event level
31 * @param[in] const AdditionalDataArg&) - the additional data
32 * @param[in] const AssociationEndpoints& - Association endpoints (callouts)
Matt Spinlerc64b7122020-03-26 10:55:01 -050033 * @param[in] const FFDCArg& - A vector of FFDC file info.
Matt Spinler99c2b402019-05-23 14:29:16 -050034 */
35using CreateFunction = std::function<void(
36 const std::string&, uint32_t, uint64_t, Entry::Level,
Matt Spinlerc64b7122020-03-26 10:55:01 -050037 const AdditionalDataArg&, const AssociationEndpointsArg&, const FFDCArg&)>;
Matt Spinler99c2b402019-05-23 14:29:16 -050038
39/**
40 * @brief The function type that will be called after an event log is deleted.
41 * @param[in] uint32_t - The event log ID
42 */
43using DeleteFunction = std::function<void(uint32_t)>;
44
45/**
46 * @brief The function type that will to check if an event log is prohibited
47 * from being deleted.
Arya K Padman916bb972024-09-26 01:39:26 -050048 * The same function is used to check if an event log is prohibited from
49 * setting Resolved flag, as Resolve is prohibited as long as Delete is
50 * prohibited.
51 *
Matt Spinler99c2b402019-05-23 14:29:16 -050052 * @param[in] uint32_t - The event log ID
53 * @param[out] bool - set to true if the delete is prohibited
54 */
55using DeleteProhibitedFunction = std::function<void(uint32_t, bool&)>;
56
harsh-agarwal1d763db32024-09-03 09:18:50 -050057/**
58 * @brief The function type that will return list of Hw Isolated
59 * log IDs
60 * @param[out] std::vector<uint32_t>& - Hw Isolated log IDs
61 */
62using LogIDWithHwIsolationFunction =
63 std::function<void(std::vector<uint32_t>&)>;
64using LogIDsWithHwIsolationFunctions =
65 std::vector<LogIDWithHwIsolationFunction>;
66
Matt Spinler99c2b402019-05-23 14:29:16 -050067using StartupFunctions = std::vector<StartupFunction>;
68using CreateFunctions = std::vector<CreateFunction>;
69using DeleteFunctions = std::vector<DeleteFunction>;
70using DeleteProhibitedFunctions = std::vector<DeleteProhibitedFunction>;
71
72/**
73 * @brief Register an extension hook function
74 *
75 * Call this macro at global scope to register a hook to call.
76 * Each hook point has a unique function prototype.
77 */
78#define REGISTER_EXTENSION_FUNCTION(func) \
79 namespace func##_ns \
80 { \
81 Extensions e{func}; \
82 }
83
84/**
85 * @brief Disable default error log capping
86 *
87 * Call this macro at global scope to tell phosphor-logging to disable its
88 * default error log capping algorithm, so that an extension can use its own
89 * instead.
90 */
91#define DISABLE_LOG_ENTRY_CAPS() \
92 namespace disable_caps##_ns \
93 { \
94 Extensions e{Extensions::DefaultErrorCaps::disable}; \
95 }
96
97/**
98 * @class Extensions
99 *
100 * This class manages any error log extensions. Extensions can register
101 * their hook functions with this class with the provided macros so that they
102 * are then able to create their own types of logs based on the native logs.
103 *
104 * The class should only be constructed at a global scope via the macros.
105 */
106class Extensions
107{
108 public:
109 Extensions() = delete;
110 ~Extensions() = default;
111 Extensions(const Extensions&) = delete;
112 Extensions& operator=(const Extensions&) = delete;
113 Extensions(Extensions&&) = delete;
114 Extensions& operator=(Extensions&&) = delete;
115
116 enum class DefaultErrorCaps
117 {
118 disable,
119 enable
120 };
121
122 /**
123 * @brief Constructor to register a startup function
124 *
125 * Functions registered with this contructor will be called
126 * when phosphor-log-manager starts up.
127 *
128 * @param[in] func - The startup function to register
129 */
130 explicit Extensions(StartupFunction func)
131 {
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700132 getStartupFunctions().push_back(func);
Matt Spinler99c2b402019-05-23 14:29:16 -0500133 }
134
135 /**
136 * @brief Constructor to register a create function
137 *
138 * Functions registered with this contructor will be called
139 * after phosphor-log-manager creates an event log.
140 *
141 * @param[in] func - The create function to register
142 */
143 explicit Extensions(CreateFunction func)
144 {
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700145 getCreateFunctions().push_back(func);
Matt Spinler99c2b402019-05-23 14:29:16 -0500146 }
147
148 /**
149 * @brief Constructor to register a delete function
150 *
151 * Functions registered with this contructor will be called
152 * after phosphor-log-manager deletes an event log.
153 *
154 * @param[in] func - The delete function to register
155 */
156 explicit Extensions(DeleteFunction func)
157 {
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700158 getDeleteFunctions().push_back(func);
Matt Spinler99c2b402019-05-23 14:29:16 -0500159 }
160
161 /**
162 * @brief Constructor to register a delete prohibition function
163 *
164 * Functions registered with this contructor will be called
165 * before phosphor-log-manager deletes an event log to ensure
166 * deleting the log is allowed.
167 *
168 * @param[in] func - The function to register
169 */
170 explicit Extensions(DeleteProhibitedFunction func)
171 {
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700172 getDeleteProhibitedFunctions().push_back(func);
Matt Spinler99c2b402019-05-23 14:29:16 -0500173 }
174
175 /**
harsh-agarwal1d763db32024-09-03 09:18:50 -0500176 * @brief Constructor to register a LogID with HwIsolation function
177 *
178 * Functions registered with this contructor will be called
179 * before phosphor-log-manager deletes all event log.
180 *
181 * @param[in] func - The function to register
182 */
183 explicit Extensions(LogIDWithHwIsolationFunction func)
184 {
185 getLogIDWithHwIsolationFunctions().emplace_back(func);
186 }
187
188 /**
Matt Spinler99c2b402019-05-23 14:29:16 -0500189 * @brief Constructor to disable event log capping
190 *
191 * This constructor should only be called by the
192 * DISABLE_LOG_ENTRY_CAPS macro to disable the default
193 * event log capping so that the extension can use their own.
194 *
195 * @param[in] defaultCaps - Enable or disable default capping.
196 */
197 explicit Extensions(DefaultErrorCaps defaultCaps)
198 {
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700199 getDefaultErrorCaps() = defaultCaps;
Matt Spinler99c2b402019-05-23 14:29:16 -0500200 }
201
202 /**
203 * @brief Returns the Startup functions
204 * @return StartupFunctions - the Startup functions
205 */
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700206 static StartupFunctions& getStartupFunctions();
Matt Spinler99c2b402019-05-23 14:29:16 -0500207
208 /**
209 * @brief Returns the Create functions
210 * @return CreateFunctions - the Create functions
211 */
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700212 static CreateFunctions& getCreateFunctions();
Matt Spinler99c2b402019-05-23 14:29:16 -0500213
214 /**
215 * @brief Returns the Delete functions
216 * @return DeleteFunctions - the Delete functions
217 */
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700218 static DeleteFunctions& getDeleteFunctions();
Matt Spinler99c2b402019-05-23 14:29:16 -0500219
220 /**
221 * @brief Returns the DeleteProhibited functions
222 * @return DeleteProhibitedFunctions - the DeleteProhibited functions
223 */
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700224 static DeleteProhibitedFunctions& getDeleteProhibitedFunctions();
225
226 /**
harsh-agarwal1d763db32024-09-03 09:18:50 -0500227 * @brief Returns the LogIDWithHwIsolationFunction functions
228 * @return LogIDsWithHwIsolationFunctions - the LogIDWithHwIsolationFunction
229 * functions
230 */
231 static LogIDsWithHwIsolationFunctions& getLogIDWithHwIsolationFunctions();
232
233 /**
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700234 * @brief Returns the DefaultErrorCaps value
235 * @return DefaultErrorCaps - the DefaultErrorCaps value
236 */
237 static DefaultErrorCaps& getDefaultErrorCaps();
Matt Spinler99c2b402019-05-23 14:29:16 -0500238
239 /**
240 * @brief Say if the default log capping policy should be disabled
241 * @return bool - true if it should be disabled
242 */
243 static bool disableDefaultLogCaps()
244 {
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700245 return getDefaultErrorCaps() == DefaultErrorCaps::disable;
Matt Spinler99c2b402019-05-23 14:29:16 -0500246 }
Matt Spinler99c2b402019-05-23 14:29:16 -0500247};
248
249} // namespace logging
250} // namespace phosphor