|
libxr
Embedded C++ framework for bare-metal, RTOS and Linux
|
发布订阅主题 / Publish-subscribe topic More...
#include <topic.hpp>
Classes | |
| struct | ASyncBlock |
| 异步订阅者自己挂的数据块 / Data block owned by one asynchronous subscriber More... | |
| class | ASyncSubscriber |
先 StartWaiting(),再自己来取数据的订阅者 / Subscriber that first calls StartWaiting() and later pulls the data itself More... | |
| struct | Block |
| topic 运行时状态块 / Runtime state block of one topic More... | |
| class | Callback |
| 每次发布时直接执行函数的订阅句柄 / Subscription handle that runs a function on each publish More... | |
| struct | CallbackBlock |
| 挂在 topic 订阅链表里的回调记录 / Callback record stored in the topic subscriber list More... | |
| class | Domain |
| topic 所属的命名域 / Naming domain that groups topics More... | |
| struct | Message |
| 带时间戳和 payload 副本的消息对象 / Message object carrying a timestamp and a payload copy More... | |
| struct | MessageView |
| 带时间戳和 payload 指针的只读消息视图 / Read-only message view carrying a timestamp and a payload pointer More... | |
| struct | QueueBlock |
| 队列订阅者自己挂的数据块 / Data block owned by one queued subscriber More... | |
| class | QueuedSubscriber |
| 每次发布都往队列里塞一份数据的订阅者 / Subscriber that pushes one entry into a queue on each publish More... | |
| struct | RawMessageView |
| 带时间戳和只读原始 payload 视图的消息 / Message carrying a timestamp and a read-only raw payload view More... | |
| class | Server |
| 将字节流解析成 packet 并发布到已注册 topic 的状态机 / State machine that parses byte streams into packets and publishes them into registered topics More... | |
| struct | SuberBlock |
| 所有订阅块共用的公共头 / Common header shared by all subscriber blocks More... | |
| struct | SyncBlock |
| 同步订阅者自己挂的数据块 / Data block owned by one synchronous subscriber More... | |
| class | SyncSubscriber |
调用 Wait() 收消息的订阅者 / Subscriber that receives messages by calling Wait() More... | |
Public Types | |
| enum class | ASyncSubscriberState : uint32_t { IDLE = 0 , WAITING = 1 , DATA_READY = UINT32_MAX } |
| 异步订阅者本地缓冲区的状态 / State of the async subscriber's local buffer More... | |
| enum class | SuberType : uint8_t { SYNC , ASYNC , QUEUE , CALLBACK } |
| topic 支持的订阅者种类 / Subscriber kinds supported by a topic More... | |
| typedef RBTree< uint32_t >::Node< Block > * | TopicHandle |
| 指向一个 topic 运行时状态块的句柄 / Handle pointing to one topic runtime state block | |
Public Member Functions | |
| void | RegisterCallback (Callback &cb) |
| 注册一个回调订阅者 / Register one callback subscriber | |
| Topic () | |
| 构造一个空 topic 视图 / Construct one empty topic view | |
| Topic (const char *name, TypeID::ID payload_type_id, size_t payload_size, size_t payload_alignment, Domain *domain=nullptr, bool multi_publisher=false) | |
| 用显式类型契约构造或查找一个 topic / Construct or look up one topic with an explicit runtime type contract | |
| Topic (TopicHandle topic) | |
| 从已有句柄构造一个 topic 视图 / Construct one topic view from an existing handle | |
| size_t | PayloadSize () const |
| 获取该 topic 固定 payload 字节数 / Get the fixed payload size of this topic | |
| size_t | PayloadAlignment () const |
| 获取该 topic payload 的对齐要求 / Get the payload alignment requirement of this topic | |
| template<typename Data > | |
| void | Publish (Data &data) |
| 在普通上下文里发布一条消息,并自动取当前时间戳 / Publish one message in normal context and stamp it with the current time | |
| template<typename Data > | |
| void | Publish (Data &data, MicrosecondTimestamp timestamp) |
| 在普通上下文里按指定时间戳发布一条消息 / Publish one message in normal context with an explicit timestamp | |
| template<typename Data > | |
| void | PublishFromCallback (Data &data, bool in_isr) |
| 在回调或 ISR 路径里发布一条消息,并自动取当前时间戳 / Publish one message from callback or ISR context and stamp it with the current time | |
| template<typename Data > | |
| void | PublishFromCallback (Data &data, MicrosecondTimestamp timestamp, bool in_isr) |
| 在回调或 ISR 路径里按指定时间戳发布一条消息 / Publish one message from callback or ISR context with an explicit timestamp | |
| void | PublishBytesFromServer (void *payload_addr, size_t payload_size, MicrosecondTimestamp timestamp) |
| 供 packet/server 路径按字节发布一条消息 / Publish one message from the packet/server path using bytes already arranged as the exact payload object | |
| void | PublishBytesFromServerCallback (void *payload_addr, size_t payload_size, MicrosecondTimestamp timestamp, bool in_isr) |
| 供回调/ISR 上下文里的 packet/server 路径按字节发布一条消息 / Publish one packet/server message from callback/ISR context using bytes already arranged as the exact payload object | |
| template<typename Data > | |
| ErrorCode | PackData (const Data &data, PackedData< Data > &packet) |
| 将一个精确类型消息打包成 packet / Pack one exact-typed message into one packet using the topic's runtime contract and current timestamp | |
| template<typename Data > | |
| ErrorCode | PackData (const Data &data, PackedData< Data > &packet, MicrosecondTimestamp timestamp) |
| 将一个精确类型消息按指定时间戳打包成 packet / Pack one exact-typed message into one packet with the given timestamp | |
| ErrorCode | PackRaw (ConstRawData data, RawData packet) |
| 将一段 raw payload 按当前 topic 元数据打包成 packet / Pack a raw payload byte view into one packet using the current topic metadata and current timestamp | |
| ErrorCode | PackRaw (ConstRawData data, RawData packet, MicrosecondTimestamp timestamp) |
| 将一段 raw payload 按当前 topic 元数据和指定时间戳打包成 packet / Pack a raw payload byte view into one packet using the current topic metadata and timestamp | |
| operator TopicHandle () | |
| 把 topic 视图转换为底层句柄 / Convert this topic view to the underlying handle | |
| uint32_t | GetKey () const |
| 读取 topic 键值 / Read the key value of this topic | |
Static Public Member Functions | |
| static void | Lock (TopicHandle topic) |
| 在普通上下文里锁住一个 topic 发布路径 / Lock one topic publish path in normal context | |
| static void | Unlock (TopicHandle topic) |
| 在普通上下文里释放一个 topic 发布路径 / Unlock one topic publish path in normal context | |
| static void | LockFromCallback (TopicHandle topic) |
| 在回调或 ISR 路径里锁住一个 topic 发布路径 / Lock one topic publish path from callback or ISR context | |
| static void | UnlockFromCallback (TopicHandle topic) |
| 在回调或 ISR 路径里释放一个 topic 发布路径 / Unlock one topic publish path from callback or ISR context | |
| static MicrosecondTimestamp | NowTimestamp () |
| 读取当前时间戳 / Read the current timestamp | |
| template<typename Data > | |
| static Topic | CreateTopic (const char *name, Domain *domain=nullptr, bool multi_publisher=false) |
| 用精确类型创建或查找一个 topic / Create or look up one topic using one exact payload type | |
| static TopicHandle | Find (const char *name, Domain *domain=nullptr) |
| 按名称查找一个已存在 topic / Find one existing topic by name | |
| template<typename Data > | |
| static TopicHandle | FindOrCreate (const char *name, Domain *domain=nullptr, bool multi_publisher=false) |
| 按精确类型查找或创建一个 topic / Find or create one topic with an exact payload type | |
| static TopicHandle | WaitTopic (const char *name, uint32_t timeout=UINT32_MAX, Domain *domain=nullptr) |
| 等待指定名称的 topic 出现 / Wait until a topic with the given name exists | |
发布订阅主题 / Publish-subscribe topic
一个 Topic 表示一种精确类型的消息通道:它在每次发布时同步通知挂在上面的同步、 异步、队列或回调订阅者,但自身不缓存最近一次消息。 One Topic represents one exact-typed message channel: it synchronously notifies the attached synchronous, asynchronous, queued, or callback subscribers on each publish, but does not cache the latest message itself.
| RBTree<uint32_t>::Node<Block>* LibXR::Topic::TopicHandle |
|
strong |
异步订阅者本地缓冲区的状态 / State of the async subscriber's local buffer
异步订阅者本地缓冲区状态 / State of one asynchronous subscriber local buffer
|
strong |
topic 支持的订阅者种类 / Subscriber kinds supported by a topic
| Topic::Topic | ( | ) |
| Topic::Topic | ( | const char * | name, |
| TypeID::ID | payload_type_id, | ||
| size_t | payload_size, | ||
| size_t | payload_alignment, | ||
| Domain * | domain = nullptr, | ||
| bool | multi_publisher = false ) |
用显式类型契约构造或查找一个 topic / Construct or look up one topic with an explicit runtime type contract
| name | topic 名称 / Topic name |
| payload_type_id | payload 类型标识 / Payload type identifier |
| payload_size | 该 topic 固定 payload 字节数 / Fixed payload size of this topic |
| payload_alignment | 该 topic payload 所需对齐,必须是非零 2 次幂 / Required payload alignment of this topic; must be a non-zero power of two |
| domain | 可选主题域 / Optional topic domain |
| multi_publisher | 是否允许多发布者串行化 / Whether to allow serialized multi-publisher use |
Definition at line 116 of file topic.cpp.
| Topic::Topic | ( | TopicHandle | topic | ) |
|
inlinestatic |
用精确类型创建或查找一个 topic / Create or look up one topic using one exact payload type
| Data | payload 类型 / Payload type |
| name | topic 名称 / Topic name |
| domain | 可选主题域 / Optional topic domain |
| multi_publisher | 是否允许多发布者串行化 / Whether to allow serialized multi-publisher use |
Definition at line 362 of file topic.hpp.
|
static |
按名称查找一个已存在 topic / Find one existing topic by name
| name | topic 名称 / Topic name |
| domain | 可选主题域 / Optional topic domain |
Definition at line 188 of file topic.cpp.
|
inlinestatic |
按精确类型查找或创建一个 topic / Find or create one topic with an exact payload type
| Data | payload 类型 / Payload type |
| name | topic 名称 / Topic name |
| domain | 可选主题域 / Optional topic domain |
| multi_publisher | 是否允许多发布者串行化 / Whether to allow serialized multi-publisher use |
Definition at line 399 of file topic.hpp.
| uint32_t Topic::GetKey | ( | ) | const |
|
static |
在普通上下文里锁住一个 topic 发布路径 / Lock one topic publish path in normal context
| topic | 目标 topic 句柄 / Target topic handle |
|
static |
在回调或 ISR 路径里锁住一个 topic 发布路径 / Lock one topic publish path from callback or ISR context
| topic | 目标 topic 句柄 / Target topic handle |
|
static |
读取当前时间戳 / Read the current timestamp
Definition at line 80 of file publish.cpp.
|
inline |
|
inline |
将一个精确类型消息打包成 packet / Pack one exact-typed message into one packet using the topic's runtime contract and current timestamp
| Data | 负载类型 / Payload type |
| data | 待打包 payload / Payload to pack |
| packet | 输出 packet 对象 / Output packed message object |
Definition at line 533 of file topic.hpp.
| ErrorCode LibXR::Topic::PackData | ( | const Data & | data, |
| PackedData< Data > & | packet, | ||
| MicrosecondTimestamp | timestamp ) |
将一个精确类型消息按指定时间戳打包成 packet / Pack one exact-typed message into one packet with the given timestamp
按当前 topic 的名字和类型契约把一条消息打包成 packet / Pack one message into one packet using the current topic name and type contract
| Data | 负载类型 / Payload type |
| data | 待打包 payload / Payload to pack |
| packet | 输出 packet 对象 / Output packed message object |
| timestamp | 指定时间戳 / Explicit timestamp |
| Data | payload 类型 / Payload type |
| data | 待打包 payload / Payload to pack |
| packet | 输出 packet / Output packed message |
| timestamp | 要写入包头的时间戳 / Timestamp to store into the packet header |
Definition at line 112 of file packet.hpp.
|
inline |
将一段 raw payload 按当前 topic 元数据打包成 packet / Pack a raw payload byte view into one packet using the current topic metadata and current timestamp
| data | 待打包 payload 字节 / Payload bytes to pack |
| packet | 输出 packet 缓冲区 / Output packet buffer |
Definition at line 559 of file topic.hpp.
|
inline |
将一段 raw payload 按当前 topic 元数据和指定时间戳打包成 packet / Pack a raw payload byte view into one packet using the current topic metadata and timestamp
| data | 待打包 payload 字节 / Payload bytes to pack |
| packet | 输出 packet 缓冲区 / Output packet buffer |
| timestamp | 指定时间戳 / Explicit timestamp |
Definition at line 573 of file topic.hpp.
|
inlinenodiscard |
|
inlinenodiscard |
|
inline |
在普通上下文里发布一条消息,并自动取当前时间戳 / Publish one message in normal context and stamp it with the current time
| Data | payload 类型 / Payload type |
| data | 待发布的 payload 对象 / Payload object to publish |
|
inline |
在普通上下文里按指定时间戳发布一条消息 / Publish one message in normal context with an explicit timestamp
| Data | payload 类型 / Payload type |
| data | 待发布的 payload 对象 / Payload object to publish |
| timestamp | 消息时间戳 / Message timestamp |
Definition at line 460 of file topic.hpp.
|
inline |
供 packet/server 路径按字节发布一条消息 / Publish one message from the packet/server path using bytes already arranged as the exact payload object
| payload_addr | 已满足对齐的 payload 起始地址 / Start address of the already-aligned payload object |
| payload_size | payload 字节数,必须等于 topic 固定大小 / Payload size, must equal the fixed topic size |
| timestamp | 这条消息的时间戳 / Timestamp of this message |
Definition at line 501 of file topic.hpp.
|
inline |
供回调/ISR 上下文里的 packet/server 路径按字节发布一条消息 / Publish one packet/server message from callback/ISR context using bytes already arranged as the exact payload object
| payload_addr | 已满足对齐的 payload 起始地址 / Start address of the already-aligned payload object |
| payload_size | payload 字节数,必须等于 topic 固定大小 / Payload size, must equal the fixed topic size |
| timestamp | 这条消息的时间戳 / Timestamp of this message |
| in_isr | 当前是否位于 ISR / Whether the current path is in ISR context |
Definition at line 518 of file topic.hpp.
|
inline |
在回调或 ISR 路径里发布一条消息,并自动取当前时间戳 / Publish one message from callback or ISR context and stamp it with the current time
| Data | payload 类型 / Payload type |
| data | 待发布的 payload 对象 / Payload object to publish |
| in_isr | 当前是否位于 ISR / Whether the current path is in ISR context |
|
inline |
在回调或 ISR 路径里按指定时间戳发布一条消息 / Publish one message from callback or ISR context with an explicit timestamp
| Data | payload 类型 / Payload type |
| data | 待发布的 payload 对象 / Payload object to publish |
| timestamp | 消息时间戳 / Message timestamp |
| in_isr | 当前是否位于 ISR / Whether the current path is in ISR context |
Definition at line 487 of file topic.hpp.
|
inline |
注册一个回调订阅者 / Register one callback subscriber
注册回调函数 / Register a callback function
Definition at line 620 of file callback.hpp.
|
static |
在普通上下文里释放一个 topic 发布路径 / Unlock one topic publish path in normal context
| topic | 目标 topic 句柄 / Target topic handle |
|
static |
在回调或 ISR 路径里释放一个 topic 发布路径 / Unlock one topic publish path from callback or ISR context
| topic | 目标 topic 句柄 / Target topic handle |
|
static |
等待指定名称的 topic 出现 / Wait until a topic with the given name exists
| name | topic 名称 / Topic name |
| timeout | 等待超时,默认永久等待 / Timeout in ticks, default wait forever |
| domain | 可选主题域 / Optional topic domain |
Definition at line 206 of file topic.cpp.