From e08fbffcd9bd1976f7d26d48bf7a4c3e5843d4a8 Mon Sep 17 00:00:00 2001 From: Vernon Mauery Date: Wed, 3 Apr 2019 09:19:34 -0700 Subject: Only include ipmid/api.hpp for the new API After some feedback from users of the new IPMI API, they wanted to see two things: 1) don't require ipmid/api.hpp and ipmid/registration.hpp to be able to write new handlers 2) only require including ipmid/api.hpp (instead of ipmid/api.h) So now, by simply including ipmid/api.hpp instead of ipmid/api.h (deprecated), handlers incorporating the new IPMI API can be written. Change-Id: I446dcce70cff03d4ecc28c658292d052485f77fc Signed-off-by: Vernon Mauery --- include/ipmid/filter.hpp | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) (limited to 'include/ipmid/filter.hpp') diff --git a/include/ipmid/filter.hpp b/include/ipmid/filter.hpp index 3cd5d21..950e3c3 100644 --- a/include/ipmid/filter.hpp +++ b/include/ipmid/filter.hpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include @@ -91,4 +91,45 @@ static inline auto makeFilter(const Filter& filter) return makeFilter(std::forward(lFilter)); } +namespace impl +{ + +// IPMI command filter registration implementation +void registerFilter(int prio, ::ipmi::FilterBase::ptr filter); + +} // namespace impl + +/** + * @brief IPMI command filter registration function + * + * This function should be used to register IPMI command filter functions. + * This function just passes the callback to makeFilter, which creates a + * wrapper functor object that ultimately calls the callback. + * + * Filters are called with a ipmi::message::Request shared_ptr on all IPMI + * commands in priority order and each filter has the opportunity to reject the + * command (by returning an IPMI error competion code.) If all the filters + * return success, the actual IPMI command will be executed. Filters can reject + * the command for any reason, based on system state, the context, the command + * payload, etc. + * + * @param prio - priority at which to register; see api.hpp + * @param filter - the callback function that will handle this request + * + * @return bool - success of registering the handler + */ +template +void registerFilter(int prio, Filter&& filter) +{ + auto f = ipmi::makeFilter(std::forward(filter)); + impl::registerFilter(prio, f); +} + +template +void registerFilter(int prio, const Filter& filter) +{ + auto f = ipmi::makeFilter(filter); + impl::registerFilter(prio, f); +} + } // namespace ipmi -- cgit v1.2.1