blob: ff741374e118d950272ea94620a5ae6e3df91a8b [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.
48 * @param[in] uint32_t - The event log ID
49 * @param[out] bool - set to true if the delete is prohibited
50 */
51using DeleteProhibitedFunction = std::function<void(uint32_t, bool&)>;
52
harsh-agarwal1d763db32024-09-03 09:18:50 -050053/**
54 * @brief The function type that will return list of Hw Isolated
55 * log IDs
56 * @param[out] std::vector<uint32_t>& - Hw Isolated log IDs
57 */
58using LogIDWithHwIsolationFunction =
59 std::function<void(std::vector<uint32_t>&)>;
60using LogIDsWithHwIsolationFunctions =
61 std::vector<LogIDWithHwIsolationFunction>;
62
Matt Spinler99c2b402019-05-23 14:29:16 -050063using StartupFunctions = std::vector<StartupFunction>;
64using CreateFunctions = std::vector<CreateFunction>;
65using DeleteFunctions = std::vector<DeleteFunction>;
66using DeleteProhibitedFunctions = std::vector<DeleteProhibitedFunction>;
67
68/**
69 * @brief Register an extension hook function
70 *
71 * Call this macro at global scope to register a hook to call.
72 * Each hook point has a unique function prototype.
73 */
74#define REGISTER_EXTENSION_FUNCTION(func) \
75 namespace func##_ns \
76 { \
77 Extensions e{func}; \
78 }
79
80/**
81 * @brief Disable default error log capping
82 *
83 * Call this macro at global scope to tell phosphor-logging to disable its
84 * default error log capping algorithm, so that an extension can use its own
85 * instead.
86 */
87#define DISABLE_LOG_ENTRY_CAPS() \
88 namespace disable_caps##_ns \
89 { \
90 Extensions e{Extensions::DefaultErrorCaps::disable}; \
91 }
92
93/**
94 * @class Extensions
95 *
96 * This class manages any error log extensions. Extensions can register
97 * their hook functions with this class with the provided macros so that they
98 * are then able to create their own types of logs based on the native logs.
99 *
100 * The class should only be constructed at a global scope via the macros.
101 */
102class Extensions
103{
104 public:
105 Extensions() = delete;
106 ~Extensions() = default;
107 Extensions(const Extensions&) = delete;
108 Extensions& operator=(const Extensions&) = delete;
109 Extensions(Extensions&&) = delete;
110 Extensions& operator=(Extensions&&) = delete;
111
112 enum class DefaultErrorCaps
113 {
114 disable,
115 enable
116 };
117
118 /**
119 * @brief Constructor to register a startup function
120 *
121 * Functions registered with this contructor will be called
122 * when phosphor-log-manager starts up.
123 *
124 * @param[in] func - The startup function to register
125 */
126 explicit Extensions(StartupFunction func)
127 {
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700128 getStartupFunctions().push_back(func);
Matt Spinler99c2b402019-05-23 14:29:16 -0500129 }
130
131 /**
132 * @brief Constructor to register a create function
133 *
134 * Functions registered with this contructor will be called
135 * after phosphor-log-manager creates an event log.
136 *
137 * @param[in] func - The create function to register
138 */
139 explicit Extensions(CreateFunction func)
140 {
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700141 getCreateFunctions().push_back(func);
Matt Spinler99c2b402019-05-23 14:29:16 -0500142 }
143
144 /**
145 * @brief Constructor to register a delete function
146 *
147 * Functions registered with this contructor will be called
148 * after phosphor-log-manager deletes an event log.
149 *
150 * @param[in] func - The delete function to register
151 */
152 explicit Extensions(DeleteFunction func)
153 {
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700154 getDeleteFunctions().push_back(func);
Matt Spinler99c2b402019-05-23 14:29:16 -0500155 }
156
157 /**
158 * @brief Constructor to register a delete prohibition function
159 *
160 * Functions registered with this contructor will be called
161 * before phosphor-log-manager deletes an event log to ensure
162 * deleting the log is allowed.
163 *
164 * @param[in] func - The function to register
165 */
166 explicit Extensions(DeleteProhibitedFunction func)
167 {
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700168 getDeleteProhibitedFunctions().push_back(func);
Matt Spinler99c2b402019-05-23 14:29:16 -0500169 }
170
171 /**
harsh-agarwal1d763db32024-09-03 09:18:50 -0500172 * @brief Constructor to register a LogID with HwIsolation function
173 *
174 * Functions registered with this contructor will be called
175 * before phosphor-log-manager deletes all event log.
176 *
177 * @param[in] func - The function to register
178 */
179 explicit Extensions(LogIDWithHwIsolationFunction func)
180 {
181 getLogIDWithHwIsolationFunctions().emplace_back(func);
182 }
183
184 /**
Matt Spinler99c2b402019-05-23 14:29:16 -0500185 * @brief Constructor to disable event log capping
186 *
187 * This constructor should only be called by the
188 * DISABLE_LOG_ENTRY_CAPS macro to disable the default
189 * event log capping so that the extension can use their own.
190 *
191 * @param[in] defaultCaps - Enable or disable default capping.
192 */
193 explicit Extensions(DefaultErrorCaps defaultCaps)
194 {
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700195 getDefaultErrorCaps() = defaultCaps;
Matt Spinler99c2b402019-05-23 14:29:16 -0500196 }
197
198 /**
199 * @brief Returns the Startup functions
200 * @return StartupFunctions - the Startup functions
201 */
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700202 static StartupFunctions& getStartupFunctions();
Matt Spinler99c2b402019-05-23 14:29:16 -0500203
204 /**
205 * @brief Returns the Create functions
206 * @return CreateFunctions - the Create functions
207 */
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700208 static CreateFunctions& getCreateFunctions();
Matt Spinler99c2b402019-05-23 14:29:16 -0500209
210 /**
211 * @brief Returns the Delete functions
212 * @return DeleteFunctions - the Delete functions
213 */
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700214 static DeleteFunctions& getDeleteFunctions();
Matt Spinler99c2b402019-05-23 14:29:16 -0500215
216 /**
217 * @brief Returns the DeleteProhibited functions
218 * @return DeleteProhibitedFunctions - the DeleteProhibited functions
219 */
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700220 static DeleteProhibitedFunctions& getDeleteProhibitedFunctions();
221
222 /**
harsh-agarwal1d763db32024-09-03 09:18:50 -0500223 * @brief Returns the LogIDWithHwIsolationFunction functions
224 * @return LogIDsWithHwIsolationFunctions - the LogIDWithHwIsolationFunction
225 * functions
226 */
227 static LogIDsWithHwIsolationFunctions& getLogIDWithHwIsolationFunctions();
228
229 /**
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700230 * @brief Returns the DefaultErrorCaps value
231 * @return DefaultErrorCaps - the DefaultErrorCaps value
232 */
233 static DefaultErrorCaps& getDefaultErrorCaps();
Matt Spinler99c2b402019-05-23 14:29:16 -0500234
235 /**
236 * @brief Say if the default log capping policy should be disabled
237 * @return bool - true if it should be disabled
238 */
239 static bool disableDefaultLogCaps()
240 {
William A. Kennington IIIaeccabc2021-05-19 16:39:10 -0700241 return getDefaultErrorCaps() == DefaultErrorCaps::disable;
Matt Spinler99c2b402019-05-23 14:29:16 -0500242 }
Matt Spinler99c2b402019-05-23 14:29:16 -0500243};
244
245} // namespace logging
246} // namespace phosphor