rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
action_s Class Reference

#include <scheduler.h>

Collaboration diagram for action_s:
Collaboration graph
[legend]

Public Member Functions

 action_s () noexcept=default
 
 action_s (action_s const &) noexcept=default
 
 action_s (action_s &&other) noexcept
 
action_soperator= (action_s const &) noexcept=default
 
action_soperator= (action_s &&other) noexcept
 
void execute () const
 
constexpr schfunc_t getCallback () const
 
constexpr scheduler_arg_t const & getArgumentRaw () const
 
template<typename T >
constexpr T getArgument () const
 
constexpr operator bool () const
 
bool constexpr operator== (const action_s &other) const
 
constexpr char const * getCallbackName () const
 

Static Public Member Functions

template<auto Func, typename Arg >
static constexpr action_s make (Arg arg) noexcept(std::is_nothrow_constructible_v< action_s, schfunc_t, scheduler_arg_t >)
 
template<auto Func>
static constexpr action_s make () noexcept(std::is_nothrow_constructible_v< action_s, schfunc_t >)
 

Private Types

using schfunc_t = void(*)(scheduler_arg_t)
 

Private Member Functions

constexpr action_s (const schfunc_t callback, char const *const fn_name_) noexcept
 
constexpr action_s (const schfunc_t callback, const scheduler_arg_t param, char const *const fn_name_) noexcept
 
constexpr action_s (const schfunc_t callback) noexcept
 
constexpr action_s (const schfunc_t callback, const scheduler_arg_t param) noexcept
 

Static Private Member Functions

template<typename T >
static constexpr T from_scheduler_arg_t (scheduler_arg_t raw) noexcept
 
template<typename T >
static constexpr scheduler_arg_t to_scheduler_arg_t (T val) noexcept
 
template<auto Func, typename Arg >
static constexpr void trampoline (scheduler_arg_t raw) noexcept
 
template<auto Func>
static constexpr void trampoline_no_arg (scheduler_arg_t) noexcept
 

Private Attributes

schfunc_t m_callback {}
 
scheduler_arg_t m_param {}
 
char const * fn_name {}
 

Detailed Description

Definition at line 98 of file scheduler.h.

Member Typedef Documentation

◆ schfunc_t

using action_s::schfunc_t = void (*)(scheduler_arg_t)
private

Definition at line 100 of file scheduler.h.

Constructor & Destructor Documentation

◆ action_s() [1/7]

constexpr action_s::action_s ( const schfunc_t  callback,
char const *const  fn_name_ 
)
inlineconstexprprivatenoexcept

Definition at line 108 of file scheduler.h.

108: m_callback(callback), fn_name{fn_name_} {}
schfunc_t m_callback
Definition scheduler.h:102
char const * fn_name
Definition scheduler.h:107

◆ action_s() [2/7]

constexpr action_s::action_s ( const schfunc_t  callback,
const scheduler_arg_t  param,
char const *const  fn_name_ 
)
inlineconstexprprivatenoexcept

Definition at line 109 of file scheduler.h.

109: m_callback(callback), m_param(param), fn_name{fn_name_} {}
scheduler_arg_t m_param
Definition scheduler.h:103
static tstrWifiInitParam param

◆ action_s() [3/7]

constexpr action_s::action_s ( const schfunc_t  callback)
inlineconstexprprivatenoexcept

Definition at line 111 of file scheduler.h.

111: m_callback(callback) {}

◆ action_s() [4/7]

constexpr action_s::action_s ( const schfunc_t  callback,
const scheduler_arg_t  param 
)
inlineconstexprprivatenoexcept

Definition at line 112 of file scheduler.h.

112: m_callback(callback), m_param(param) {}

◆ action_s() [5/7]

action_s::action_s ( )
defaultnoexcept

Referenced by make(), and make().

Here is the caller graph for this function:

◆ action_s() [6/7]

action_s::action_s ( action_s const &  )
defaultnoexcept

◆ action_s() [7/7]

action_s::action_s ( action_s &&  other)
inlinenoexcept

Definition at line 169 of file scheduler.h.

169 : m_callback{other.m_callback}, m_param{other.m_param}
170 #if EFI_UNIT_TEST
171 , fn_name {other.fn_name}
172 #endif
173 {
174 other.m_callback = nullptr;
175 other.m_param = 0;
176 #if EFI_UNIT_TEST
177 other.fn_name = "Moved";
178 #endif
179 }

Member Function Documentation

◆ execute()

void action_s::execute ( ) const
inline

Definition at line 230 of file scheduler.h.

230 {
231 if (m_callback) {
232 #if EFI_UNIT_TEST_VERBOSE_ACTION
233 std::cout << "action_s::execute: " << fn_name << "(" << reinterpret_cast<scheduler_arg_t>(m_callback) << ") "
234 "with raw arg = " << m_param << std::endl;
235 #endif
237 } else {
238 #ifdef WE_HAVE_CRITICAL_ERROR_METHOD
239 efiCriticalError("clear nullptr");
240 #endif
241
242 #if EFI_UNIT_TEST
243 assert(false);
244 #endif
245 }
246 }
void efiCriticalError(const char *message)
uintptr_t scheduler_arg_t
Definition scheduler.h:21
Here is the call graph for this function:

◆ from_scheduler_arg_t()

template<typename T >
static constexpr T action_s::from_scheduler_arg_t ( scheduler_arg_t  raw)
inlinestaticconstexprprivatenoexcept

Definition at line 118 of file scheduler.h.

118 {
119 static_assert(std::is_pointer_v<T> || std::is_integral_v<T>, "Unsupported type");
120 if constexpr (std::is_pointer_v<T>) {
121 return reinterpret_cast<T>(raw);
122 } else {
123 return static_cast<T>(raw);
124 }
125 }

◆ getArgument()

template<typename T >
constexpr T action_s::getArgument ( ) const
inlineconstexpr

Definition at line 252 of file scheduler.h.

252{ return from_scheduler_arg_t<T>(m_param); }

◆ getArgumentRaw()

constexpr scheduler_arg_t const & action_s::getArgumentRaw ( ) const
inlineconstexpr

Definition at line 249 of file scheduler.h.

249{ return m_param; }

◆ getCallback()

constexpr schfunc_t action_s::getCallback ( ) const
inlineconstexpr

Definition at line 248 of file scheduler.h.

248{ return m_callback; }

Referenced by EventQueue::insertTask().

Here is the caller graph for this function:

◆ getCallbackName()

constexpr char const * action_s::getCallbackName ( ) const
inlineconstexpr

Definition at line 261 of file scheduler.h.

261{ return fn_name ? fn_name : "nullptr"; }

◆ make() [1/2]

template<auto Func>
static constexpr action_s action_s::make ( )
inlinestaticconstexprnoexcept

Definition at line 221 of file scheduler.h.

221 {
222 static_assert(std::is_invocable_r_v<void, decltype(Func)>, "Function signature mismatch");
223 #if EFI_UNIT_TEST
224 return action_s(&trampoline_no_arg<Func>, __PRETTY_FUNCTION__);
225 #else
226 return action_s(&trampoline_no_arg<Func>);
227 #endif
228 }
action_s() noexcept=default
Here is the call graph for this function:

◆ make() [2/2]

template<auto Func, typename Arg >
static constexpr action_s action_s::make ( Arg  arg)
inlinestaticconstexprnoexcept

Definition at line 196 of file scheduler.h.

196 {
197 static_assert(std::is_invocable_r_v<void, decltype(Func), Arg>, "Function signature mismatch");
198 #if EFI_UNIT_TEST_VERBOSE_ACTION
199 std::cout << "action_s::make: " << __PRETTY_FUNCTION__ << "(" << reinterpret_cast<scheduler_arg_t>(Func) << ") "
200 "with raw arg = " << arg << "; is_ptr = " << std::is_pointer_v<Arg> << std::endl;
201 #endif
202 if constexpr (std::is_pointer_v<Arg>) {
203 // alignment is a must because pointers have to be dividable by 2 with no loss (i.e., no loss on bit shifts)
204 // if it is 1-aligned, there will be address data in the last bit, so it cannot be used for any flags
205 // There could be theoretic architectures where it is the case though I don't know what to do then,
206 // Maybe introduce some other member for flag here?
207 // Anyway, we have so much code relying on specific architecture, and we are not testing on some fancy
208 // PowerPC/mainframe/... machines so should always be true, but just in case...
209 static_assert(alignof(std::remove_pointer_t<Arg>) >= 2, "Pointer must be at least 2-aligned");
210 static_assert(sizeof(scheduler_arg_t) == sizeof(void*), "Unexpected scheduler_arg_t size");
211 }
212 #if EFI_UNIT_TEST
213 return action_s(&trampoline<Func, Arg>, to_scheduler_arg_t(arg), __PRETTY_FUNCTION__);
214 #else
215 return action_s(&trampoline<Func, Arg>, to_scheduler_arg_t(arg));
216 #endif
217 }
static constexpr scheduler_arg_t to_scheduler_arg_t(T val) noexcept
Definition scheduler.h:130
Here is the call graph for this function:

◆ operator bool()

constexpr action_s::operator bool ( ) const
inlineexplicitconstexpr

Definition at line 254 of file scheduler.h.

254{ return m_callback != nullptr; }

◆ operator=() [1/2]

action_s & action_s::operator= ( action_s &&  other)
inlinenoexcept

Definition at line 182 of file scheduler.h.

182 {
183 m_callback = other.m_callback;
184 m_param = other.m_param;
185 other.m_callback = nullptr;
186 other.m_param = 0;
187 #if EFI_UNIT_TEST
188 fn_name = other.fn_name;
189 other.fn_name = "Moved";
190 #endif
191 return *this;
192 }

◆ operator=() [2/2]

action_s & action_s::operator= ( action_s const &  )
defaultnoexcept

◆ operator==()

bool constexpr action_s::operator== ( const action_s other) const
inlineconstexpr

Definition at line 256 of file scheduler.h.

256 {
257 return m_callback == other.m_callback && m_param == other.m_param;
258 }

◆ to_scheduler_arg_t()

template<typename T >
static constexpr scheduler_arg_t action_s::to_scheduler_arg_t ( val)
inlinestaticconstexprprivatenoexcept

Definition at line 130 of file scheduler.h.

130 {
131 static_assert(std::is_pointer_v<T> || std::is_integral_v<T>, "Unsupported type");
132 if constexpr (std::is_pointer_v<T>) {
133 return reinterpret_cast<scheduler_arg_t>(val);
134 } else {
135 return static_cast<scheduler_arg_t>(val);
136 }
137 }

Referenced by make().

Here is the caller graph for this function:

◆ trampoline()

template<auto Func, typename Arg >
static constexpr void action_s::trampoline ( scheduler_arg_t  raw)
inlinestaticconstexprprivatenoexcept

Definition at line 142 of file scheduler.h.

142 {
143 static_assert(std::is_pointer_v<Arg> || std::is_integral_v<Arg>, "Unsupported type");
144 #if EFI_UNIT_TEST_VERBOSE_ACTION
145 std::cout << "action_s::trampoline: " << __PRETTY_FUNCTION__ << "(" << reinterpret_cast<scheduler_arg_t>(Func) << ") "
146 "with raw arg = " << raw << "; is_ptr = " << std::is_pointer_v<Arg> << std::endl;
147 #endif
148 if constexpr (std::is_pointer_v<Arg>) {
149 Func(reinterpret_cast<Arg>(raw));
150 } else {
151 Func(static_cast<Arg>(raw));
152 }
153 }

◆ trampoline_no_arg()

template<auto Func>
static constexpr void action_s::trampoline_no_arg ( scheduler_arg_t  )
inlinestaticconstexprprivatenoexcept

Definition at line 157 of file scheduler.h.

157 {
158 #if EFI_UNIT_TEST_VERBOSE_ACTION
159 std::cout << "action_s::trampoline_no_arg: " << __PRETTY_FUNCTION__ << "(" << reinterpret_cast<scheduler_arg_t>(Func) << ") with no arg" << std::endl;
160 #endif
161 Func(); // stored argument is ignored
162 }

Field Documentation

◆ fn_name

char const* action_s::fn_name {}
private

Definition at line 107 of file scheduler.h.

107{};

Referenced by execute(), getCallbackName(), and operator=().

◆ m_callback

schfunc_t action_s::m_callback {}
private

Definition at line 102 of file scheduler.h.

102{};

Referenced by action_s(), execute(), getCallback(), operator bool(), operator=(), and operator==().

◆ m_param

scheduler_arg_t action_s::m_param {}
private

Definition at line 103 of file scheduler.h.

103{};

Referenced by execute(), getArgument(), getArgumentRaw(), operator=(), and operator==().


The documentation for this class was generated from the following file: