libxr 1.0
Want to be the best embedded framework
|
主题(Topic)管理类 / Topic management class More...
#include <message.hpp>
Data Structures | |
struct | ASyncBlock |
异步订阅块,继承自 SuberBlock Asynchronous subscription block, inheriting from SuberBlock More... | |
class | ASyncSubscriber |
异步订阅者类,用于订阅异步数据 Asynchronous subscriber class for subscribing to asynchronous data More... | |
struct | Block |
存储主题(Topic)数据的结构体。Structure storing topic data. More... | |
struct | CallbackBlock |
回调订阅块,继承自 SuberBlock Callback subscription block, inheriting from SuberBlock More... | |
class | Domain |
主题域(Domain)管理器,用于组织多个主题。Domain manager for organizing multiple topics. More... | |
struct | QueueBlock |
队列订阅块,继承自 SuberBlock Queue subscription block, inheriting from SuberBlock More... | |
class | QueuedSubscriber |
构造函数,使用名称和无锁队列进行初始化 Constructor using a name and a lock-free queue More... | |
class | Server |
服务器类,负责解析数据并将其分发到相应的主题 Server class responsible for parsing data and distributing it to corresponding topics More... | |
struct | SuberBlock |
订阅者信息存储结构。Structure storing subscriber information. More... | |
struct | SyncBlock |
同步订阅者存储结构。Structure storing synchronous subscriber data. More... | |
class | SyncSubscriber |
同步订阅者类,允许同步方式接收数据。Synchronous subscriber class allowing data reception in a synchronous manner. More... | |
Public Types | |
enum class | SuberType : uint8_t { SYNC , ASYNC , QUEUE , CALLBACK } |
订阅者类型。Subscriber type. More... | |
typedef RBTree< uint32_t >::Node< Block > * | TopicHandle |
主题句柄,指向存储数据的红黑树节点。Handle pointing to a red-black tree node storing data. | |
typedef LibXR::Topic::ASyncBlock | ASyncBlock |
typedef LibXR::Topic::QueueBlock | QueueBlock |
typedef LibXR::Topic::CallbackBlock | CallbackBlock |
Public Member Functions | |
void | RegisterCallback (Callback< RawData & > &cb) |
注册回调函数 Registers a callback function | |
Topic () | |
默认构造函数,创建一个空的 Topic 实例 Default constructor, creates an empty Topic instance | |
Topic (const char *name, uint32_t max_length, Domain *domain=nullptr, bool cache=false, bool check_length=false) | |
构造函数,使用指定名称、最大长度、域及其他选项初始化主题 Constructor to initialize a topic with the specified name, maximum length, domain, and options | |
Topic (TopicHandle topic) | |
通过句柄构造主题 Constructs a topic from a topic handle | |
void | EnableCache () |
启用主题的缓存功能 Enables caching for the topic | |
template<typename Data > | |
void | Publish (Data &data) |
发布数据 Publishes data | |
template<typename Data > | |
void | PublishFromCallback (Data &data, bool in_isr) |
从回调函数发布数据 Publishes data from a callback function | |
void | Publish (void *addr, uint32_t size) |
以原始地址和大小发布数据 Publishes data using raw address and size | |
void | PublishFromCallback (void *addr, uint32_t size, bool in_isr) |
从回调函数发布数据 Publishes data from a callback function | |
template<SizeLimitMode Mode = SizeLimitMode::MORE> | |
ErrorCode | DumpData (RawData data, bool pack=false) |
转储数据 Dump data | |
template<typename Data > | |
ErrorCode | DumpData (PackedData< Data > &data) |
转储数据到 PackedData Dumps data into PackedData format | |
template<typename Data > | |
ErrorCode | DumpData (Data &data) |
转储数据到普通数据结构 Dumps data into a normal data structure | |
operator TopicHandle () | |
将 Topic 转换为 TopicHandle Converts Topic to TopicHandle | |
Static Public Member Functions | |
template<typename Data > | |
static Topic | CreateTopic (const char *name, Domain *domain=nullptr, bool cache=false, bool check_length=true) |
创建一个新的主题 Creates a new topic | |
static TopicHandle | Find (const char *name, Domain *domain=nullptr) |
在指定域中查找主题 Finds a topic in the specified domain | |
template<typename Data > | |
static TopicHandle | FindOrCreate (const char *name, Domain *domain=nullptr, bool cache=false, bool check_length=true) |
在指定域中查找或创建主题 Finds or creates a topic in the specified domain | |
static void | PackData (uint32_t topic_name_crc32, RawData buffer, RawData source) |
static TopicHandle | WaitTopic (const char *name, uint32_t timeout=UINT32_MAX, Domain *domain=nullptr) |
等待主题的创建并返回其句柄 Waits for a topic to be created and returns its handle | |
Private Attributes | |
TopicHandle | block_ = nullptr |
主题句柄,指向当前主题的内存块 Topic handle pointing to the memory block of the current topic | |
Static Private Attributes | |
static RBTree< uint32_t > * | domain_ = nullptr |
主题域的红黑树结构,存储不同的主题 Red-Black Tree structure for storing different topics in the domain | |
static SpinLock | domain_lock_ |
主题域访问的自旋锁,确保多线程安全 SpinLock for domain access to ensure thread safety | |
static Domain * | def_domain_ = nullptr |
默认的主题域,所有未指定域的主题都会归入此域 Default domain where all topics without a specified domain are assigned | |
主题(Topic)管理类 / Topic management class
该类提供了基于发布-订阅模式的主题管理,支持同步、异步、队列和回调订阅者,以及数据的缓存和校验机制。 This class provides topic management based on the publish-subscribe model, supporting synchronous, asynchronous, queue-based, and callback subscribers, as well as data caching and validation mechanisms.
Definition at line 28 of file message.hpp.
主题句柄,指向存储数据的红黑树节点。Handle pointing to a red-black tree node storing data.
Definition at line 125 of file message.hpp.
|
strong |
|
inline |
默认构造函数,创建一个空的 Topic 实例 Default constructor, creates an empty Topic instance
Definition at line 489 of file message.hpp.
|
inline |
构造函数,使用指定名称、最大长度、域及其他选项初始化主题 Constructor to initialize a topic with the specified name, maximum length, domain, and options
name | 主题名称 Topic name |
max_length | 数据的最大长度 Maximum length of data |
domain | 主题所属的域(默认为 nullptr)Domain to which the topic belongs (default: nullptr) |
cache | 是否启用缓存(默认为 false)Whether to enable caching (default: false) |
check_length | 是否检查数据长度(默认为 false)Whether to check data length (default: false) |
Definition at line 503 of file message.hpp.
|
inline |
通过句柄构造主题 Constructs a topic from a topic handle
topic | 主题句柄 Topic handle |
Definition at line 580 of file message.hpp.
|
inlinestatic |
创建一个新的主题 Creates a new topic
Data | 主题数据类型 Topic data type |
name | 主题名称 Topic name |
domain | 主题所属的域(默认为 nullptr)Domain to which the topic belongs (default: nullptr) |
cache | 是否启用缓存(默认为 false)Whether to enable caching (default: false) |
check_length | 是否检查数据长度(默认为 true)Whether to check data length (default: true) |
Definition at line 569 of file message.hpp.
转储数据到普通数据结构 Dumps data into a normal data structure
Data | 数据类型 Data type |
data | 存储数据的变量 Variable to store the data |
Definition at line 893 of file message.hpp.
|
inline |
转储数据到 PackedData Dumps data into PackedData format
Data | 数据类型 Data type |
data | 存储数据的 PackedData 结构 PackedData structure to store data |
Definition at line 874 of file message.hpp.
|
inline |
转储数据 Dump data
Mode | 数据大小检查模式 Size limit check mode |
data | 需要转储的数据 Data to be dumped |
pack | 是否打包数据 Pack data |
Definition at line 824 of file message.hpp.
|
inline |
启用主题的缓存功能 Enables caching for the topic
Definition at line 630 of file message.hpp.
在指定域中查找主题 Finds a topic in the specified domain
name | 主题名称 Topic name |
domain | 主题所属的域(默认为 nullptr)Domain to search in (default: nullptr) |
Definition at line 590 of file message.hpp.
|
inlinestatic |
在指定域中查找或创建主题 Finds or creates a topic in the specified domain
Data | 数据类型 Data type |
name | 话题名称 Topic name |
domain | 可选的域指针 Optional domain pointer (default: nullptr) |
cache | 可选的缓存标志位 Optional cache flag (default: false) |
check_length | 可选的数据长度检查标志位 Optional data length check flag (default: true) |
Definition at line 615 of file message.hpp.
|
inline |
将 Topic 转换为 TopicHandle Converts Topic to TopicHandle
Definition at line 941 of file message.hpp.
|
inlinestatic |
Definition at line 850 of file message.hpp.
发布数据 Publishes data
Data | 数据类型 Data type |
data | 需要发布的数据 Data to be published |
Definition at line 648 of file message.hpp.
以原始地址和大小发布数据 Publishes data using raw address and size
addr | 数据的地址 Address of the data |
size | 数据大小 Size of the data |
Definition at line 672 of file message.hpp.
从回调函数发布数据 Publishes data from a callback function
Data | 数据类型 Data type |
data | 需要发布的数据 Data to be published |
in_isr | 是否在中断服务程序(ISR)中发布 Whether publishing inside an ISR |
Definition at line 661 of file message.hpp.
从回调函数发布数据 Publishes data from a callback function
addr | 数据的地址 Address of the data |
size | 数据大小 Size of the data |
in_isr | 是否在中断服务程序(ISR)中发布 Whether publishing inside an ISR |
Definition at line 746 of file message.hpp.
注册回调函数 Registers a callback function
cb | 需要注册的回调函数 The callback function to register |
Definition at line 476 of file message.hpp.
|
inlinestatic |
等待主题的创建并返回其句柄 Waits for a topic to be created and returns its handle
name | 主题名称 The name of the topic |
timeout | 等待的超时时间(默认 UINT32_MAX)Timeout duration to wait (default: UINT32_MAX) |
domain | 主题所属的域(默认为 nullptr)The domain in which to search for the topic (default: nullptr) |
Definition at line 916 of file message.hpp.
|
private |
主题句柄,指向当前主题的内存块 Topic handle pointing to the memory block of the current topic
Definition at line 1113 of file message.hpp.
默认的主题域,所有未指定域的主题都会归入此域 Default domain where all topics without a specified domain are assigned
Definition at line 1131 of file message.hpp.
主题域的红黑树结构,存储不同的主题 Red-Black Tree structure for storing different topics in the domain
Definition at line 1119 of file message.hpp.
|
inlinestaticprivate |
主题域访问的自旋锁,确保多线程安全 SpinLock for domain access to ensure thread safety
Definition at line 1125 of file message.hpp.