20 template <
typename Function>
30 template <
typename Return,
typename... Args>
34 static constexpr size_t ARITY =
sizeof...(Args);
40 template <
size_t Index>
41 using Arg = std::tuple_element_t<Index, std::tuple<Args...>>;
53 static constexpr bool VALUE =
false;
63 template <
typename Data>
66 static constexpr bool VALUE =
true;
76 using RemoveCVRef = std::remove_cv_t<std::remove_reference_t<T>>;
102 template <
typename T>
112 template <
typename T>
115 !std::is_const_v<std::remove_reference_t<T>>;
145 template <
typename PayloadArg>
149 "LibXR::Topic::Callback does not accept MessageView<T>&; "
150 "use MessageView<T> or const MessageView<T>& instead.");
160 "LibXR::Topic::Callback payload must be Topic::MessageView<T>, "
161 "T, T&, or const T&.");
180 template <
typename Function,
typename BoundArg,
typename PayloadArg>
187 using Data =
typename View::DataType;
194 fun(in_isr, arg, *
reinterpret_cast<Data*
>(payload_addr));
205 template <
typename Function,
typename BoundArg,
typename PayloadArg>
235 block->fun_,
const_cast<BoundArg&
>(block->arg_), in_isr, timestamp,
251 template <
typename Function,
typename BoundArg,
typename PayloadArg>
283 using Data =
typename View::DataType;
285 in_isr, block->arg_, timestamp,
291 block->fun_(in_isr, block->arg_, timestamp,
292 *
reinterpret_cast<Data*
>(payload_addr));
308 template <
typename Function,
typename BoundArg,
size_t Arity>
311 static_assert(Arity == 3 || Arity == 4,
312 "LibXR::Topic::Callback function must be void(bool, Arg, Payload) "
313 "or void(bool, Arg, MicrosecondTimestamp, Payload).");
322 template <
typename Function,
typename BoundArg>
327 typename Traits::template Arg<2>;
338 static_assert(std::same_as<typename Traits::ReturnType, void>);
339 static_assert(std::same_as<typename Traits::template Arg<0>,
bool>);
340 static_assert(std::same_as<typename Traits::template Arg<1>, BoundArg>);
352 template <
typename Function,
typename BoundArg>
357 typename Traits::template Arg<2>;
359 typename Traits::template Arg<3>;
370 static_assert(std::same_as<typename Traits::ReturnType, void>);
371 static_assert(std::same_as<typename Traits::template Arg<0>,
bool>);
372 static_assert(std::same_as<typename Traits::template Arg<1>, BoundArg>);
394 UNUSED(payload_addr);
437 template <
typename BoundArg,
typename Callable>
440 using Function =
decltype(+std::declval<Callable>());
442 static_assert(Traits::ARITY == 3 || Traits::ARITY == 4,
443 "LibXR::Topic::Callback::Create expects a capture-free callable "
444 "with bool and bound-argument parameters.");
数据节点模板,继承自 BaseNode,用于存储具体数据类型。 Template data node that inherits from BaseNode to store specific data...
微秒时间戳 / Microsecond timestamp
Data data_
存储的数据 (Stored data).
每次发布时直接执行函数的订阅句柄 / Subscription handle that runs a function on each publish
static constexpr bool IS_MESSAGE_VIEW
是否为带时间戳的类型化消息视图参数 / Whether one callback payload argument is a timestamped typed message view
Callback & operator=(const Callback &other)=default
拷贝赋值回调句柄 / Copy-assign one callback handle
static constexpr bool IS_CALLBACK_PAYLOAD
是否是回调接口允许的 payload 参数写法 / Whether one payload argument form is accepted by this callback interface
void Run(bool in_isr, MicrosecondTimestamp timestamp, void *payload_addr) const
执行回调 / Run the callback
Callback(const Callback &other)=default
拷贝构造回调句柄 / Copy-construct one callback handle
Callback(BlockHeader *block)
用指定执行块构造回调句柄 / Construct one callback handle from the given execution block
static constexpr bool IS_MUTABLE_MESSAGE_VIEW_REF
是否错误地使用了可变 MessageView<T>& / Whether one payload argument is an invalid mutable MessageView<T>&
static Callback Create(Callable fun, BoundArg arg)
创建一个回调订阅句柄 / Create a callback subscription handle
static void EmptyRun(const BlockHeader *header, bool in_isr, MicrosecondTimestamp timestamp, void *payload_addr)
空回调块的执行函数 / Execution function of the empty callback block
static BlockHeader empty_block_
空回调句柄共用的静态空执行块。Shared static empty execution block used by empty callback handles.
Callback()=default
构造一个空回调句柄 / Construct one empty callback handle
TypeID::ID PayloadTypeID() const
读取这个回调句柄期望的 payload 类型标识 / Read the payload type ID expected by this callback handle
std::remove_cv_t< std::remove_reference_t< T > > RemoveCVRef
去掉引用和 cv 限定后的规范类型 / Canonical type after removing reference and cv qualifiers
static constexpr bool IS_TYPED_DATA
是否把 payload 直接当成一个对象接收 / Whether one callback payload argument receives the payload directly as one o...
static void InvokePayload(Function fun, BoundArg &arg, bool in_isr, MicrosecondTimestamp timestamp, void *payload_addr)
按回调声明的参数形式,把当前消息拼成实参再调函数 / Build the actual call arguments from the current message in the form decla...
BlockHeader * block_
当前回调句柄绑定的执行块。Execution block bound to the current callback handle.
static TypeID::ID PayloadTypeID()
取回调 payload 参数对应的精确类型标识 / Get the exact type ID expected by one callback payload argument
@ CALLBACK
回调执行型订阅者。Callback-executing subscriber.
TopicHandle block_
当前 topic 视图绑定的状态块。Runtime state block bound to the current topic view.
void RegisterCallback(Callback &cb)
注册一个回调订阅者 / Register one callback subscriber
static ID GetID()
获取类型的唯一标识符 / Get a unique identifier for type T
topic 可承载 payload 的类型约束 / Type constraint for payloads carried by one topic
constexpr size_t CACHE_LINE_SIZE
缓存行大小 / Cache line size
typename Traits::template Arg< 2 > PayloadArg
第三个参数,即负载参数类型。Third argument, namely the payload argument type.
static BlockHeader * Create(Function fun, BoundArg &&arg)
创建只转发负载的回调块 / Create one callback block that forwards only the payload
static BlockHeader * Create(Function fun, BoundArg &&arg)
创建同时转发时间戳和负载的回调块 / Create one callback block that forwards both timestamp and payload
typename Traits::template Arg< 3 > PayloadArg
第四个参数,即负载参数类型。Fourth argument, namely the payload argument type.
typename Traits::template Arg< 2 > TimestampArg
第三个参数,即时间戳参数类型。Third argument, namely the timestamp argument type.
看回调有几个参数,决定分配哪种回调块 / Choose which callback block to allocate from the callback parameter count
std::tuple_element_t< Index, std::tuple< Args... > > Arg
取出指定下标的参数类型 / Fetch the argument type at the given index
Return ReturnType
回调返回类型。Callback return type.
把一个无捕获回调函数拆成返回类型和参数类型 / Split one callback function without captures into its return type and paramet...
Data DataType
MessageView 对应的数据类型。Payload type behind the MessageView.
判断某个参数是否为 MessageView<T> / Tell whether one argument is MessageView<T>
static constexpr bool VALUE
默认不是 MessageView。Not a MessageView by default.
只转发负载的回调块 / Callback block that forwards only the payload
static void Run(const BlockHeader *header, bool in_isr, MicrosecondTimestamp timestamp, void *payload_addr)
根据块头指针取回具体块并执行回调 / Recover the concrete block from the block header pointer and run the callback
BoundArg arg_
绑定到回调中的参数副本。Stored copy of the bound argument.
Function fun_
目标回调函数。Target callback function.
PayloadOnlyBlock(Function fun, BoundArg &&arg)
构造一个只转发负载的具体回调块 / Construct one concrete callback block that forwards only the payload
同时转发时间戳和负载的回调块 / Callback block that forwards both timestamp and payload
BoundArg arg_
绑定到回调中的参数副本。Stored copy of the bound argument.
Function fun_
目标回调函数。Target callback function.
static void Run(const BlockHeader *header, bool in_isr, MicrosecondTimestamp timestamp, void *payload_addr)
根据块头指针取回具体块并执行带时间戳回调 / Recover the concrete block from the block header pointer and run the timestamp...
TimestampPayloadBlock(Function fun, BoundArg &&arg)
构造一个同时转发时间戳和负载的具体回调块 / Construct one concrete callback block that forwards both timestamp and payload
挂在 topic 订阅链表里的回调记录 / Callback record stored in the topic subscriber list
Callback cb
订阅的回调句柄。Subscribed callback handle.
CallbackBlock(Callback &callback)
构造一个回调订阅块 / Construct one callback subscriber block
带时间戳和 payload 指针的只读消息视图 / Read-only message view carrying a timestamp and a payload pointer
所有订阅块共用的公共头 / Common header shared by all subscriber blocks
SuberType type
订阅块的具体种类。Concrete kind of this subscriber block.