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 * @param[in] uint32_t - The event log ID 49 * @param[out] bool - set to true if the delete is prohibited 50 */ 51 using DeleteProhibitedFunction = std::function<void(uint32_t, bool&)>; 52 53 /** 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 */ 58 using LogIDWithHwIsolationFunction = 59 std::function<void(std::vector<uint32_t>&)>; 60 using LogIDsWithHwIsolationFunctions = 61 std::vector<LogIDWithHwIsolationFunction>; 62 63 using StartupFunctions = std::vector<StartupFunction>; 64 using CreateFunctions = std::vector<CreateFunction>; 65 using DeleteFunctions = std::vector<DeleteFunction>; 66 using 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 */ 102 class 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 { 128 getStartupFunctions().push_back(func); 129 } 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 { 141 getCreateFunctions().push_back(func); 142 } 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 { 154 getDeleteFunctions().push_back(func); 155 } 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 { 168 getDeleteProhibitedFunctions().push_back(func); 169 } 170 171 /** 172 * @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 /** 185 * @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 { 195 getDefaultErrorCaps() = defaultCaps; 196 } 197 198 /** 199 * @brief Returns the Startup functions 200 * @return StartupFunctions - the Startup functions 201 */ 202 static StartupFunctions& getStartupFunctions(); 203 204 /** 205 * @brief Returns the Create functions 206 * @return CreateFunctions - the Create functions 207 */ 208 static CreateFunctions& getCreateFunctions(); 209 210 /** 211 * @brief Returns the Delete functions 212 * @return DeleteFunctions - the Delete functions 213 */ 214 static DeleteFunctions& getDeleteFunctions(); 215 216 /** 217 * @brief Returns the DeleteProhibited functions 218 * @return DeleteProhibitedFunctions - the DeleteProhibited functions 219 */ 220 static DeleteProhibitedFunctions& getDeleteProhibitedFunctions(); 221 222 /** 223 * @brief Returns the LogIDWithHwIsolationFunction functions 224 * @return LogIDsWithHwIsolationFunctions - the LogIDWithHwIsolationFunction 225 * functions 226 */ 227 static LogIDsWithHwIsolationFunctions& getLogIDWithHwIsolationFunctions(); 228 229 /** 230 * @brief Returns the DefaultErrorCaps value 231 * @return DefaultErrorCaps - the DefaultErrorCaps value 232 */ 233 static DefaultErrorCaps& getDefaultErrorCaps(); 234 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 { 241 return getDefaultErrorCaps() == DefaultErrorCaps::disable; 242 } 243 }; 244 245 } // namespace logging 246 } // namespace phosphor 247