1 #pragma once 2 3 #include "elog_entry.hpp" 4 #include "log_manager.hpp" 5 6 #include <functional> 7 #include <vector> 8 9 namespace phosphor 10 { 11 namespace 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 */ 18 using StartupFunction = std::function<void(internal::Manager&)>; 19 20 using AdditionalDataArg = std::vector<std::string>; 21 using AssociationEndpointsArg = std::vector<std::string>; 22 using FFDCArg = FFDCEntries; 23 24 /** 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) 33 * @param[in] const FFDCArg& - A vector of FFDC file info. 34 */ 35 using CreateFunction = std::function<void( 36 const std::string&, uint32_t, uint64_t, Entry::Level, 37 const AdditionalDataArg&, const AssociationEndpointsArg&, const FFDCArg&)>; 38 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 */ 43 using 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 * 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 * 52 * @param[in] uint32_t - The event log ID 53 * @param[out] bool - set to true if the delete is prohibited 54 */ 55 using DeleteProhibitedFunction = std::function<void(uint32_t, bool&)>; 56 57 /** 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 */ 62 using LogIDWithHwIsolationFunction = 63 std::function<void(std::vector<uint32_t>&)>; 64 using LogIDsWithHwIsolationFunctions = 65 std::vector<LogIDWithHwIsolationFunction>; 66 67 using StartupFunctions = std::vector<StartupFunction>; 68 using CreateFunctions = std::vector<CreateFunction>; 69 using DeleteFunctions = std::vector<DeleteFunction>; 70 using 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 */ 106 class 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 */ Extensions(StartupFunction func)130 explicit Extensions(StartupFunction func) 131 { 132 getStartupFunctions().push_back(func); 133 } 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 */ Extensions(CreateFunction func)143 explicit Extensions(CreateFunction func) 144 { 145 getCreateFunctions().push_back(func); 146 } 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 */ Extensions(DeleteFunction func)156 explicit Extensions(DeleteFunction func) 157 { 158 getDeleteFunctions().push_back(func); 159 } 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 */ Extensions(DeleteProhibitedFunction func)170 explicit Extensions(DeleteProhibitedFunction func) 171 { 172 getDeleteProhibitedFunctions().push_back(func); 173 } 174 175 /** 176 * @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 */ Extensions(LogIDWithHwIsolationFunction func)183 explicit Extensions(LogIDWithHwIsolationFunction func) 184 { 185 getLogIDWithHwIsolationFunctions().emplace_back(func); 186 } 187 188 /** 189 * @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 */ Extensions(DefaultErrorCaps defaultCaps)197 explicit Extensions(DefaultErrorCaps defaultCaps) 198 { 199 getDefaultErrorCaps() = defaultCaps; 200 } 201 202 /** 203 * @brief Returns the Startup functions 204 * @return StartupFunctions - the Startup functions 205 */ 206 static StartupFunctions& getStartupFunctions(); 207 208 /** 209 * @brief Returns the Create functions 210 * @return CreateFunctions - the Create functions 211 */ 212 static CreateFunctions& getCreateFunctions(); 213 214 /** 215 * @brief Returns the Delete functions 216 * @return DeleteFunctions - the Delete functions 217 */ 218 static DeleteFunctions& getDeleteFunctions(); 219 220 /** 221 * @brief Returns the DeleteProhibited functions 222 * @return DeleteProhibitedFunctions - the DeleteProhibited functions 223 */ 224 static DeleteProhibitedFunctions& getDeleteProhibitedFunctions(); 225 226 /** 227 * @brief Returns the LogIDWithHwIsolationFunction functions 228 * @return LogIDsWithHwIsolationFunctions - the LogIDWithHwIsolationFunction 229 * functions 230 */ 231 static LogIDsWithHwIsolationFunctions& getLogIDWithHwIsolationFunctions(); 232 233 /** 234 * @brief Returns the DefaultErrorCaps value 235 * @return DefaultErrorCaps - the DefaultErrorCaps value 236 */ 237 static DefaultErrorCaps& getDefaultErrorCaps(); 238 239 /** 240 * @brief Say if the default log capping policy should be disabled 241 * @return bool - true if it should be disabled 242 */ disableDefaultLogCaps()243 static bool disableDefaultLogCaps() 244 { 245 return getDefaultErrorCaps() == DefaultErrorCaps::disable; 246 } 247 }; 248 249 } // namespace logging 250 } // namespace phosphor 251