20template <
typename ArgType,
typename... Args>
44 template <
typename FunType,
typename ArgT>
46 :
fun_(std::forward<FunType>(fun)),
arg_(std::forward<ArgT>(arg))
59 void Call(
bool in_isr, Args &&...args)
64 fun_(in_isr,
arg_, std::forward<Args>(args)...);
81 :
fun_(std::exchange(other.fun_,
nullptr)),
82 arg_(std::move(other.arg_)),
100 fun_ = std::exchange(other.fun_,
nullptr);
101 arg_ = std::move(other.arg_);
123template <
typename... Args>
142 template <
typename FunType,
typename ArgType>
145 void (*fun_ptr)(bool, ArgType, Args...) = fun;
146 auto cb_block =
new CallbackBlock<ArgType, Args...>(fun_ptr, arg);
148 auto cb_fun = [](
bool in_isr,
void *cb_block, Args... args)
150 auto *cb =
static_cast<CallbackBlock<ArgType, Args...
> *>(cb_block);
151 cb->
Call(in_isr, std::forward<Args>(args)...);
174 :
cb_block_(std::exchange(other.cb_block_,
nullptr)),
175 cb_fun_(std::exchange(other.cb_fun_,
nullptr))
192 cb_block_ = std::exchange(other.cb_block_,
nullptr);
193 cb_fun_ = std::exchange(other.cb_fun_,
nullptr);
207 template <
typename... PassArgs>
208 void Run(
bool in_isr, PassArgs &&...args)
const
235 Callback(
void *cb_block,
void (*cb_fun)(
bool,
void *, Args...))
提供一个回调函数的封装,实现参数绑定和回调执行。 Provides a wrapper for callback functions, enabling argument binding and inv...
void(*)(bool, ArgType, Args...) FunctionType
定义回调函数类型。 Defines the type of the callback function.
CallbackBlock(FunType &&fun, ArgT &&arg)
构造回调块,绑定回调函数和参数。 Constructs a callback block, binding a function and an argument.
CallbackBlock & operator=(CallbackBlock &&other) noexcept
移动赋值运算符,转移回调函数与参数。 Move assignment operator, transferring the callback function and argument.
void Call(bool in_isr, Args &&...args)
调用回调函数,并传递额外参数。 Calls the callback function, passing additional arguments.
CallbackBlock(CallbackBlock &&other) noexcept
移动构造函数,转移回调函数与参数。 Move constructor, transferring the callback function and argument.
ArgType arg_
绑定的参数。 The bound argument.
void(* fun_)(bool, ArgType, Args...)
绑定的回调函数。 The bound callback function.
提供一个通用的回调包装,支持动态参数传递。 Provides a generic callback wrapper, supporting dynamic argument passing.
void * cb_block_
存储回调块的指针。 Pointer to the callback block.
Callback(void *cb_block, void(*cb_fun)(bool, void *, Args...))
私有构造函数,仅用于内部创建回调实例。 Private constructor, used internally for creating callback instances.
Callback & operator=(Callback &&other) noexcept
移动赋值运算符,转移回调对象的所有权。 Move assignment operator, transferring ownership of the callback object.
void Run(bool in_isr, PassArgs &&...args) const
执行回调函数,并传递参数。 Executes the callback function, passing the arguments.
static Callback Create(FunType fun, ArgType arg)
创建一个新的回调对象,并绑定回调函数和参数。 Creates a new callback instance, binding a function and an argument.
Callback(Callback &&other) noexcept
移动构造函数,转移回调对象的所有权。 Move constructor, transferring ownership of the callback object.
bool Empty() const
检查回调是否为空。 Checks if the callback is empty.
void(* cb_fun_)(bool, void *, Args...)
存储回调执行的函数指针。 Pointer to the callback execution function.
Callback()
默认构造函数,创建空回调对象。 Default constructor, creating an empty callback instance.