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 using StartupFunctions = std::vector<StartupFunction>; 54 using CreateFunctions = std::vector<CreateFunction>; 55 using DeleteFunctions = std::vector<DeleteFunction>; 56 using DeleteProhibitedFunctions = std::vector<DeleteProhibitedFunction>; 57 58 /** 59 * @brief Register an extension hook function 60 * 61 * Call this macro at global scope to register a hook to call. 62 * Each hook point has a unique function prototype. 63 */ 64 #define REGISTER_EXTENSION_FUNCTION(func) \ 65 namespace func##_ns \ 66 { \ 67 Extensions e{func}; \ 68 } 69 70 /** 71 * @brief Disable default error log capping 72 * 73 * Call this macro at global scope to tell phosphor-logging to disable its 74 * default error log capping algorithm, so that an extension can use its own 75 * instead. 76 */ 77 #define DISABLE_LOG_ENTRY_CAPS() \ 78 namespace disable_caps##_ns \ 79 { \ 80 Extensions e{Extensions::DefaultErrorCaps::disable}; \ 81 } 82 83 /** 84 * @class Extensions 85 * 86 * This class manages any error log extensions. Extensions can register 87 * their hook functions with this class with the provided macros so that they 88 * are then able to create their own types of logs based on the native logs. 89 * 90 * The class should only be constructed at a global scope via the macros. 91 */ 92 class Extensions 93 { 94 public: 95 Extensions() = delete; 96 ~Extensions() = default; 97 Extensions(const Extensions&) = delete; 98 Extensions& operator=(const Extensions&) = delete; 99 Extensions(Extensions&&) = delete; 100 Extensions& operator=(Extensions&&) = delete; 101 102 enum class DefaultErrorCaps 103 { 104 disable, 105 enable 106 }; 107 108 /** 109 * @brief Constructor to register a startup function 110 * 111 * Functions registered with this contructor will be called 112 * when phosphor-log-manager starts up. 113 * 114 * @param[in] func - The startup function to register 115 */ 116 explicit Extensions(StartupFunction func) 117 { 118 getStartupFunctions().push_back(func); 119 } 120 121 /** 122 * @brief Constructor to register a create function 123 * 124 * Functions registered with this contructor will be called 125 * after phosphor-log-manager creates an event log. 126 * 127 * @param[in] func - The create function to register 128 */ 129 explicit Extensions(CreateFunction func) 130 { 131 getCreateFunctions().push_back(func); 132 } 133 134 /** 135 * @brief Constructor to register a delete function 136 * 137 * Functions registered with this contructor will be called 138 * after phosphor-log-manager deletes an event log. 139 * 140 * @param[in] func - The delete function to register 141 */ 142 explicit Extensions(DeleteFunction func) 143 { 144 getDeleteFunctions().push_back(func); 145 } 146 147 /** 148 * @brief Constructor to register a delete prohibition function 149 * 150 * Functions registered with this contructor will be called 151 * before phosphor-log-manager deletes an event log to ensure 152 * deleting the log is allowed. 153 * 154 * @param[in] func - The function to register 155 */ 156 explicit Extensions(DeleteProhibitedFunction func) 157 { 158 getDeleteProhibitedFunctions().push_back(func); 159 } 160 161 /** 162 * @brief Constructor to disable event log capping 163 * 164 * This constructor should only be called by the 165 * DISABLE_LOG_ENTRY_CAPS macro to disable the default 166 * event log capping so that the extension can use their own. 167 * 168 * @param[in] defaultCaps - Enable or disable default capping. 169 */ 170 explicit Extensions(DefaultErrorCaps defaultCaps) 171 { 172 getDefaultErrorCaps() = defaultCaps; 173 } 174 175 /** 176 * @brief Returns the Startup functions 177 * @return StartupFunctions - the Startup functions 178 */ 179 static StartupFunctions& getStartupFunctions(); 180 181 /** 182 * @brief Returns the Create functions 183 * @return CreateFunctions - the Create functions 184 */ 185 static CreateFunctions& getCreateFunctions(); 186 187 /** 188 * @brief Returns the Delete functions 189 * @return DeleteFunctions - the Delete functions 190 */ 191 static DeleteFunctions& getDeleteFunctions(); 192 193 /** 194 * @brief Returns the DeleteProhibited functions 195 * @return DeleteProhibitedFunctions - the DeleteProhibited functions 196 */ 197 static DeleteProhibitedFunctions& getDeleteProhibitedFunctions(); 198 199 /** 200 * @brief Returns the DefaultErrorCaps value 201 * @return DefaultErrorCaps - the DefaultErrorCaps value 202 */ 203 static DefaultErrorCaps& getDefaultErrorCaps(); 204 205 /** 206 * @brief Say if the default log capping policy should be disabled 207 * @return bool - true if it should be disabled 208 */ 209 static bool disableDefaultLogCaps() 210 { 211 return getDefaultErrorCaps() == DefaultErrorCaps::disable; 212 } 213 }; 214 215 } // namespace logging 216 } // namespace phosphor 217