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 |
using | Callback = LibXR::Callback<LibXR::RawData &> |
typedef LibXR::Topic::CallbackBlock | CallbackBlock |
Public Member Functions | |
void | RegisterCallback (Callback &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 | |
void | Publish (void *addr, uint32_t size) |
以原始地址和大小发布数据 Publishes data using raw address and size | |
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 | |
uint32_t | GetKey () const |
获取主题的键值 Gets the key value of the topic | |
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 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 27 of file message.hpp.
using LibXR::Topic::Callback = LibXR::Callback<LibXR::RawData &> |
Definition at line 441 of file message.hpp.
RBTree<uint32_t>::Node<Block>* LibXR::Topic::TopicHandle |
主题句柄,指向存储数据的红黑树节点。Handle pointing to a red-black tree node storing data.
Definition at line 134 of file message.hpp.
|
strong |
Topic::Topic | ( | ) |
默认构造函数,创建一个空的 Topic 实例 Default constructor, creates an empty Topic instance
Definition at line 61 of file message.cpp.
Topic::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
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 63 of file message.cpp.
Topic::Topic | ( | TopicHandle | topic | ) |
通过句柄构造主题 Constructs a topic from a topic handle
topic | 主题句柄 Topic handle |
Definition at line 108 of file message.cpp.
|
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 494 of file message.hpp.
|
inline |
转储数据到普通数据结构 Dumps data into a normal data structure
Data | 数据类型 Data type |
data | 存储数据的变量 Variable to store the data |
Definition at line 638 of file message.hpp.
|
inline |
转储数据到 PackedData Dumps data into PackedData format
Data | 数据类型 Data type |
data | 存储数据的 PackedData 结构 PackedData structure to store data |
Definition at line 619 of file message.hpp.
|
inline |
转储数据 Dump data
Mode | 数据大小检查模式 Size limit check mode |
data | 需要转储的数据 Data to be dumped |
pack | 是否打包数据 Pack data |
Definition at line 577 of file message.hpp.
void Topic::EnableCache | ( | ) |
启用主题的缓存功能 Enables caching for the topic
Definition at line 122 of file message.cpp.
|
static |
在指定域中查找主题 Finds a topic in the specified domain
name | 主题名称 Topic name |
domain | 主题所属的域(默认为 nullptr)Domain to search in (default: nullptr) |
Definition at line 110 of file message.cpp.
|
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 530 of file message.hpp.
uint32_t Topic::GetKey | ( | ) | const |
获取主题的键值 Gets the key value of the topic
Definition at line 236 of file message.cpp.
|
inline |
将 Topic 转换为 TopicHandle Converts Topic to TopicHandle
Definition at line 669 of file message.hpp.
打包数据
topic_name_crc32 | 话题名称的 CRC32 校验码 |
buffer | 等待写入的包 Packed data to be written |
source | 需要打包的数据 Data to be packed |
Definition at line 200 of file message.cpp.
|
inline |
发布数据 Publishes data
Data | 数据类型 Data type |
data | 需要发布的数据 Data to be published |
Definition at line 554 of file message.hpp.
void Topic::Publish | ( | void * | addr, |
uint32_t | size ) |
以原始地址和大小发布数据 Publishes data using raw address and size
addr | 数据的地址 Address of the data |
size | 数据大小 Size of the data |
Definition at line 133 of file message.cpp.
void LibXR::Topic::RegisterCallback | ( | Callback & | cb | ) |
注册回调函数 Registers a callback function
cb | 需要注册的回调函数 The callback function to register |
Definition at line 51 of file message.cpp.
|
static |
等待主题的创建并返回其句柄 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 217 of file message.cpp.
|
private |
主题句柄,指向当前主题的内存块 Topic handle pointing to the memory block of the current topic
Definition at line 737 of file message.hpp.
|
inlinestaticprivate |
默认的主题域,所有未指定域的主题都会归入此域 Default domain where all topics without a specified domain are assigned
Definition at line 749 of file message.hpp.
|
inlinestaticprivate |
主题域的红黑树结构,存储不同的主题 Red-Black Tree structure for storing different topics in the domain
Definition at line 743 of file message.hpp.