libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::CallbackBlock< ArgType, Args > Class Template Reference

回调函数封装块,提供参数绑定与擦除调用入口 / Callback block with bound argument and erased invoke entry More...

#include <libxr_cb.hpp>

Inheritance diagram for LibXR::CallbackBlock< ArgType, Args >:
[legend]
Collaboration diagram for LibXR::CallbackBlock< ArgType, Args >:
[legend]

Public Types

using FunctionType = void (*)(bool, ArgType, Args...)
 回调函数类型定义 / Callback function type definition
 
- Public Types inherited from LibXR::CallbackBlockHeader< Args... >
using InvokeFunType
 

Public Member Functions

 CallbackBlock (FunctionType fun, ArgType &&arg)
 构造回调块,绑定回调函数与参数 / Construct a callback block with bound function and argument
 
 CallbackBlock (const CallbackBlock &other)=delete
 禁用拷贝构造与拷贝赋值 / Copy construction and copy assignment are disabled
 
CallbackBlockoperator= (const CallbackBlock &other)=delete
 

Static Public Member Functions

static void InvokeThunk (void *cb_block, bool in_isr, Args... args)
 

Protected Member Functions

void Invoke (bool in_isr, Args... args)
 

Protected Attributes

FunctionType fun_
 绑定的回调函数 / Bound callback function
 
ArgType arg_
 绑定的参数 / Bound argument
 

Additional Inherited Members

- Data Fields inherited from LibXR::CallbackBlockHeader< Args... >
InvokeFunType run_fun_
 

Detailed Description

template<typename ArgType, typename... Args>
class LibXR::CallbackBlock< ArgType, Args >

回调函数封装块,提供参数绑定与擦除调用入口 / Callback block with bound argument and erased invoke entry

Template Parameters
ArgType绑定的第一个参数类型 / Type of the first bound argument
Args额外的参数类型列表 / Additional argument types

Definition at line 29 of file libxr_cb.hpp.

Member Typedef Documentation

◆ FunctionType

template<typename ArgType , typename... Args>
using LibXR::CallbackBlock< ArgType, Args >::FunctionType = void (*)(bool, ArgType, Args...)

回调函数类型定义 / Callback function type definition

Definition at line 35 of file libxr_cb.hpp.

Constructor & Destructor Documentation

◆ CallbackBlock()

template<typename ArgType , typename... Args>
LibXR::CallbackBlock< ArgType, Args >::CallbackBlock ( FunctionType fun,
ArgType && arg )
inline

构造回调块,绑定回调函数与参数 / Construct a callback block with bound function and argument

工厂层已经把 fun 收窄到了当前块真实需要的函数指针类型,因此这里不再保留 额外的模板参数做二次推导。 The factory has already narrowed fun to the exact function-pointer type required by this block, so there is no need to keep another template parameter here.

Parameters
fun需要调用的回调函数 / Callback function to be invoked
arg绑定的参数值 / Bound argument value

Definition at line 49 of file libxr_cb.hpp.

50 : CallbackBlockHeader<Args...>{&InvokeThunk}, fun_(fun), arg_(std::move(arg))
51 {
52 }
FunctionType fun_
绑定的回调函数 / Bound callback function
Definition libxr_cb.hpp:76
ArgType arg_
绑定的参数 / Bound argument
Definition libxr_cb.hpp:77

Member Function Documentation

◆ Invoke()

template<typename ArgType , typename... Args>
void LibXR::CallbackBlock< ArgType, Args >::Invoke ( bool in_isr,
Args... args )
inlineprotected

Definition at line 67 of file libxr_cb.hpp.

68 {
69 if (!fun_)
70 {
71 return;
72 }
73 fun_(in_isr, arg_, std::forward<Args>(args)...);
74 }

◆ InvokeThunk()

template<typename ArgType , typename... Args>
static void LibXR::CallbackBlock< ArgType, Args >::InvokeThunk ( void * cb_block,
bool in_isr,
Args... args )
inlinestatic

Definition at line 60 of file libxr_cb.hpp.

61 {
62 auto* cb = static_cast<CallbackBlock<ArgType, Args...>*>(cb_block);
63 cb->Invoke(in_isr, std::forward<Args>(args)...);
64 }
CallbackBlock(FunctionType fun, ArgType &&arg)
构造回调块,绑定回调函数与参数 / Construct a callback block with bound function and argument
Definition libxr_cb.hpp:49

Field Documentation

◆ arg_

template<typename ArgType , typename... Args>
ArgType LibXR::CallbackBlock< ArgType, Args >::arg_
protected

绑定的参数 / Bound argument

Definition at line 77 of file libxr_cb.hpp.

◆ fun_

template<typename ArgType , typename... Args>
FunctionType LibXR::CallbackBlock< ArgType, Args >::fun_
protected

绑定的回调函数 / Bound callback function

Definition at line 76 of file libxr_cb.hpp.


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