199c2b405SMatt Spinler #pragma once 299c2b405SMatt Spinler 399c2b405SMatt Spinler #include "elog_entry.hpp" 499c2b405SMatt Spinler #include "log_manager.hpp" 599c2b405SMatt Spinler 699c2b405SMatt Spinler #include <functional> 799c2b405SMatt Spinler #include <vector> 899c2b405SMatt Spinler 999c2b405SMatt Spinler namespace phosphor 1099c2b405SMatt Spinler { 1199c2b405SMatt Spinler namespace logging 1299c2b405SMatt Spinler { 1399c2b405SMatt Spinler 1499c2b405SMatt Spinler /** 1599c2b405SMatt Spinler * @brief The function type that will be called on start up. 1699c2b405SMatt Spinler * @param[in] internal::Manager& - A reference to the Manager class. 1799c2b405SMatt Spinler */ 1899c2b405SMatt Spinler using StartupFunction = std::function<void(internal::Manager&)>; 1999c2b405SMatt Spinler 20*e5940634SPatrick Williams using AdditionalDataArg = std::map<std::string, std::string>; 2199c2b405SMatt Spinler using AssociationEndpointsArg = std::vector<std::string>; 22c64b7122SMatt Spinler using FFDCArg = FFDCEntries; 23c64b7122SMatt Spinler 2499c2b405SMatt Spinler /** 2599c2b405SMatt Spinler * @brief The function type that will be called after an event log 2699c2b405SMatt Spinler * is created. 2799c2b405SMatt Spinler * @param[in] const std::string& - The Message property 2899c2b405SMatt Spinler * @param[in] uin32_t - The event log ID 2999c2b405SMatt Spinler * @param[in] uint64_t - The event log timestamp 3099c2b405SMatt Spinler * @param[in] Level - The event level 3199c2b405SMatt Spinler * @param[in] const AdditionalDataArg&) - the additional data 3299c2b405SMatt Spinler * @param[in] const AssociationEndpoints& - Association endpoints (callouts) 33c64b7122SMatt Spinler * @param[in] const FFDCArg& - A vector of FFDC file info. 3499c2b405SMatt Spinler */ 3599c2b405SMatt Spinler using CreateFunction = std::function<void( 3699c2b405SMatt Spinler const std::string&, uint32_t, uint64_t, Entry::Level, 37c64b7122SMatt Spinler const AdditionalDataArg&, const AssociationEndpointsArg&, const FFDCArg&)>; 3899c2b405SMatt Spinler 3999c2b405SMatt Spinler /** 4099c2b405SMatt Spinler * @brief The function type that will be called after an event log is deleted. 4199c2b405SMatt Spinler * @param[in] uint32_t - The event log ID 4299c2b405SMatt Spinler */ 4399c2b405SMatt Spinler using DeleteFunction = std::function<void(uint32_t)>; 4499c2b405SMatt Spinler 4599c2b405SMatt Spinler /** 4699c2b405SMatt Spinler * @brief The function type that will to check if an event log is prohibited 4799c2b405SMatt Spinler * from being deleted. 48916bb97eSArya K Padman * The same function is used to check if an event log is prohibited from 49916bb97eSArya K Padman * setting Resolved flag, as Resolve is prohibited as long as Delete is 50916bb97eSArya K Padman * prohibited. 51916bb97eSArya K Padman * 5299c2b405SMatt Spinler * @param[in] uint32_t - The event log ID 5399c2b405SMatt Spinler * @param[out] bool - set to true if the delete is prohibited 5499c2b405SMatt Spinler */ 5599c2b405SMatt Spinler using DeleteProhibitedFunction = std::function<void(uint32_t, bool&)>; 5699c2b405SMatt Spinler 57d763db35Sharsh-agarwal1 /** 58d763db35Sharsh-agarwal1 * @brief The function type that will return list of Hw Isolated 59d763db35Sharsh-agarwal1 * log IDs 60d763db35Sharsh-agarwal1 * @param[out] std::vector<uint32_t>& - Hw Isolated log IDs 61d763db35Sharsh-agarwal1 */ 62d763db35Sharsh-agarwal1 using LogIDWithHwIsolationFunction = 63d763db35Sharsh-agarwal1 std::function<void(std::vector<uint32_t>&)>; 64d763db35Sharsh-agarwal1 using LogIDsWithHwIsolationFunctions = 65d763db35Sharsh-agarwal1 std::vector<LogIDWithHwIsolationFunction>; 66d763db35Sharsh-agarwal1 6799c2b405SMatt Spinler using StartupFunctions = std::vector<StartupFunction>; 6899c2b405SMatt Spinler using CreateFunctions = std::vector<CreateFunction>; 6999c2b405SMatt Spinler using DeleteFunctions = std::vector<DeleteFunction>; 7099c2b405SMatt Spinler using DeleteProhibitedFunctions = std::vector<DeleteProhibitedFunction>; 7199c2b405SMatt Spinler 7299c2b405SMatt Spinler /** 7399c2b405SMatt Spinler * @brief Register an extension hook function 7499c2b405SMatt Spinler * 7599c2b405SMatt Spinler * Call this macro at global scope to register a hook to call. 7699c2b405SMatt Spinler * Each hook point has a unique function prototype. 7799c2b405SMatt Spinler */ 7899c2b405SMatt Spinler #define REGISTER_EXTENSION_FUNCTION(func) \ 7999c2b405SMatt Spinler namespace func##_ns \ 8099c2b405SMatt Spinler { \ 8199c2b405SMatt Spinler Extensions e{func}; \ 8299c2b405SMatt Spinler } 8399c2b405SMatt Spinler 8499c2b405SMatt Spinler /** 8599c2b405SMatt Spinler * @brief Disable default error log capping 8699c2b405SMatt Spinler * 8799c2b405SMatt Spinler * Call this macro at global scope to tell phosphor-logging to disable its 8899c2b405SMatt Spinler * default error log capping algorithm, so that an extension can use its own 8999c2b405SMatt Spinler * instead. 9099c2b405SMatt Spinler */ 9199c2b405SMatt Spinler #define DISABLE_LOG_ENTRY_CAPS() \ 9299c2b405SMatt Spinler namespace disable_caps##_ns \ 9399c2b405SMatt Spinler { \ 9499c2b405SMatt Spinler Extensions e{Extensions::DefaultErrorCaps::disable}; \ 9599c2b405SMatt Spinler } 9699c2b405SMatt Spinler 9799c2b405SMatt Spinler /** 9899c2b405SMatt Spinler * @class Extensions 9999c2b405SMatt Spinler * 10099c2b405SMatt Spinler * This class manages any error log extensions. Extensions can register 10199c2b405SMatt Spinler * their hook functions with this class with the provided macros so that they 10299c2b405SMatt Spinler * are then able to create their own types of logs based on the native logs. 10399c2b405SMatt Spinler * 10499c2b405SMatt Spinler * The class should only be constructed at a global scope via the macros. 10599c2b405SMatt Spinler */ 10699c2b405SMatt Spinler class Extensions 10799c2b405SMatt Spinler { 10899c2b405SMatt Spinler public: 10999c2b405SMatt Spinler Extensions() = delete; 11099c2b405SMatt Spinler ~Extensions() = default; 11199c2b405SMatt Spinler Extensions(const Extensions&) = delete; 11299c2b405SMatt Spinler Extensions& operator=(const Extensions&) = delete; 11399c2b405SMatt Spinler Extensions(Extensions&&) = delete; 11499c2b405SMatt Spinler Extensions& operator=(Extensions&&) = delete; 11599c2b405SMatt Spinler 11699c2b405SMatt Spinler enum class DefaultErrorCaps 11799c2b405SMatt Spinler { 11899c2b405SMatt Spinler disable, 11999c2b405SMatt Spinler enable 12099c2b405SMatt Spinler }; 12199c2b405SMatt Spinler 12299c2b405SMatt Spinler /** 12399c2b405SMatt Spinler * @brief Constructor to register a startup function 12499c2b405SMatt Spinler * 12599c2b405SMatt Spinler * Functions registered with this contructor will be called 12699c2b405SMatt Spinler * when phosphor-log-manager starts up. 12799c2b405SMatt Spinler * 12899c2b405SMatt Spinler * @param[in] func - The startup function to register 12999c2b405SMatt Spinler */ Extensions(StartupFunction func)13099c2b405SMatt Spinler explicit Extensions(StartupFunction func) 13199c2b405SMatt Spinler { 132aeccabc4SWilliam A. Kennington III getStartupFunctions().push_back(func); 13399c2b405SMatt Spinler } 13499c2b405SMatt Spinler 13599c2b405SMatt Spinler /** 13699c2b405SMatt Spinler * @brief Constructor to register a create function 13799c2b405SMatt Spinler * 13899c2b405SMatt Spinler * Functions registered with this contructor will be called 13999c2b405SMatt Spinler * after phosphor-log-manager creates an event log. 14099c2b405SMatt Spinler * 14199c2b405SMatt Spinler * @param[in] func - The create function to register 14299c2b405SMatt Spinler */ Extensions(CreateFunction func)14399c2b405SMatt Spinler explicit Extensions(CreateFunction func) 14499c2b405SMatt Spinler { 145aeccabc4SWilliam A. Kennington III getCreateFunctions().push_back(func); 14699c2b405SMatt Spinler } 14799c2b405SMatt Spinler 14899c2b405SMatt Spinler /** 14999c2b405SMatt Spinler * @brief Constructor to register a delete function 15099c2b405SMatt Spinler * 15199c2b405SMatt Spinler * Functions registered with this contructor will be called 15299c2b405SMatt Spinler * after phosphor-log-manager deletes an event log. 15399c2b405SMatt Spinler * 15499c2b405SMatt Spinler * @param[in] func - The delete function to register 15599c2b405SMatt Spinler */ Extensions(DeleteFunction func)15699c2b405SMatt Spinler explicit Extensions(DeleteFunction func) 15799c2b405SMatt Spinler { 158aeccabc4SWilliam A. Kennington III getDeleteFunctions().push_back(func); 15999c2b405SMatt Spinler } 16099c2b405SMatt Spinler 16199c2b405SMatt Spinler /** 16299c2b405SMatt Spinler * @brief Constructor to register a delete prohibition function 16399c2b405SMatt Spinler * 16499c2b405SMatt Spinler * Functions registered with this contructor will be called 16599c2b405SMatt Spinler * before phosphor-log-manager deletes an event log to ensure 16699c2b405SMatt Spinler * deleting the log is allowed. 16799c2b405SMatt Spinler * 16899c2b405SMatt Spinler * @param[in] func - The function to register 16999c2b405SMatt Spinler */ Extensions(DeleteProhibitedFunction func)17099c2b405SMatt Spinler explicit Extensions(DeleteProhibitedFunction func) 17199c2b405SMatt Spinler { 172aeccabc4SWilliam A. Kennington III getDeleteProhibitedFunctions().push_back(func); 17399c2b405SMatt Spinler } 17499c2b405SMatt Spinler 17599c2b405SMatt Spinler /** 176d763db35Sharsh-agarwal1 * @brief Constructor to register a LogID with HwIsolation function 177d763db35Sharsh-agarwal1 * 178d763db35Sharsh-agarwal1 * Functions registered with this contructor will be called 179d763db35Sharsh-agarwal1 * before phosphor-log-manager deletes all event log. 180d763db35Sharsh-agarwal1 * 181d763db35Sharsh-agarwal1 * @param[in] func - The function to register 182d763db35Sharsh-agarwal1 */ Extensions(LogIDWithHwIsolationFunction func)183d763db35Sharsh-agarwal1 explicit Extensions(LogIDWithHwIsolationFunction func) 184d763db35Sharsh-agarwal1 { 185d763db35Sharsh-agarwal1 getLogIDWithHwIsolationFunctions().emplace_back(func); 186d763db35Sharsh-agarwal1 } 187d763db35Sharsh-agarwal1 188d763db35Sharsh-agarwal1 /** 18999c2b405SMatt Spinler * @brief Constructor to disable event log capping 19099c2b405SMatt Spinler * 19199c2b405SMatt Spinler * This constructor should only be called by the 19299c2b405SMatt Spinler * DISABLE_LOG_ENTRY_CAPS macro to disable the default 19399c2b405SMatt Spinler * event log capping so that the extension can use their own. 19499c2b405SMatt Spinler * 19599c2b405SMatt Spinler * @param[in] defaultCaps - Enable or disable default capping. 19699c2b405SMatt Spinler */ Extensions(DefaultErrorCaps defaultCaps)19799c2b405SMatt Spinler explicit Extensions(DefaultErrorCaps defaultCaps) 19899c2b405SMatt Spinler { 199aeccabc4SWilliam A. Kennington III getDefaultErrorCaps() = defaultCaps; 20099c2b405SMatt Spinler } 20199c2b405SMatt Spinler 20299c2b405SMatt Spinler /** 20399c2b405SMatt Spinler * @brief Returns the Startup functions 20499c2b405SMatt Spinler * @return StartupFunctions - the Startup functions 20599c2b405SMatt Spinler */ 206aeccabc4SWilliam A. Kennington III static StartupFunctions& getStartupFunctions(); 20799c2b405SMatt Spinler 20899c2b405SMatt Spinler /** 20999c2b405SMatt Spinler * @brief Returns the Create functions 21099c2b405SMatt Spinler * @return CreateFunctions - the Create functions 21199c2b405SMatt Spinler */ 212aeccabc4SWilliam A. Kennington III static CreateFunctions& getCreateFunctions(); 21399c2b405SMatt Spinler 21499c2b405SMatt Spinler /** 21599c2b405SMatt Spinler * @brief Returns the Delete functions 21699c2b405SMatt Spinler * @return DeleteFunctions - the Delete functions 21799c2b405SMatt Spinler */ 218aeccabc4SWilliam A. Kennington III static DeleteFunctions& getDeleteFunctions(); 21999c2b405SMatt Spinler 22099c2b405SMatt Spinler /** 22199c2b405SMatt Spinler * @brief Returns the DeleteProhibited functions 22299c2b405SMatt Spinler * @return DeleteProhibitedFunctions - the DeleteProhibited functions 22399c2b405SMatt Spinler */ 224aeccabc4SWilliam A. Kennington III static DeleteProhibitedFunctions& getDeleteProhibitedFunctions(); 225aeccabc4SWilliam A. Kennington III 226aeccabc4SWilliam A. Kennington III /** 227d763db35Sharsh-agarwal1 * @brief Returns the LogIDWithHwIsolationFunction functions 228d763db35Sharsh-agarwal1 * @return LogIDsWithHwIsolationFunctions - the LogIDWithHwIsolationFunction 229d763db35Sharsh-agarwal1 * functions 230d763db35Sharsh-agarwal1 */ 231d763db35Sharsh-agarwal1 static LogIDsWithHwIsolationFunctions& getLogIDWithHwIsolationFunctions(); 232d763db35Sharsh-agarwal1 233d763db35Sharsh-agarwal1 /** 234aeccabc4SWilliam A. Kennington III * @brief Returns the DefaultErrorCaps value 235aeccabc4SWilliam A. Kennington III * @return DefaultErrorCaps - the DefaultErrorCaps value 236aeccabc4SWilliam A. Kennington III */ 237aeccabc4SWilliam A. Kennington III static DefaultErrorCaps& getDefaultErrorCaps(); 23899c2b405SMatt Spinler 23999c2b405SMatt Spinler /** 24099c2b405SMatt Spinler * @brief Say if the default log capping policy should be disabled 24199c2b405SMatt Spinler * @return bool - true if it should be disabled 24299c2b405SMatt Spinler */ disableDefaultLogCaps()24399c2b405SMatt Spinler static bool disableDefaultLogCaps() 24499c2b405SMatt Spinler { 245aeccabc4SWilliam A. Kennington III return getDefaultErrorCaps() == DefaultErrorCaps::disable; 24699c2b405SMatt Spinler } 24799c2b405SMatt Spinler }; 24899c2b405SMatt Spinler 24999c2b405SMatt Spinler } // namespace logging 25099c2b405SMatt Spinler } // namespace phosphor 251