6#include "libxr_def.hpp"
18 {
return (a > b) - (a < b); });
34 if (topic->
data_.mutex)
36 topic->
data_.mutex->Lock();
52 if (topic->
data_.mutex)
54 topic->
data_.mutex->Unlock();
64 if (topic->
data_.mutex)
82 if (topic->
data_.mutex)
94 ASSERT(name !=
nullptr);
102 if (domain !=
nullptr)
109 [](
const uint32_t& a,
const uint32_t& b) {
return (a > b) - (a < b); });
116Topic::Topic(
const char* name, TypeID::ID payload_type_id,
size_t payload_size,
117 size_t payload_alignment,
Domain* domain,
bool multi_publisher)
119 ASSERT(name !=
nullptr);
120 ASSERT(payload_type_id !=
nullptr);
121 ASSERT(payload_size != 0);
122 ASSERT(payload_alignment != 0);
123 ASSERT((payload_alignment & (payload_alignment - 1)) == 0);
125 if (domain ==
nullptr)
136 ASSERT(topic->data_.payload_type_id == payload_type_id);
137 ASSERT(topic->data_.payload_size == payload_size);
138 ASSERT(topic->data_.payload_alignment == payload_alignment);
140 if (multi_publisher && !topic->data_.mutex)
152 block_->
data_.payload_alignment = payload_alignment;
174 ASSERT(name !=
nullptr);
176 if (domain ==
nullptr)
196 topic =
Find(name, domain);
197 if (topic ==
nullptr)
199 if (timeout != UINT32_MAX &&
206 }
while (topic ==
nullptr);
static uint32_t Calculate(const void *raw, size_t len)
计算数据的 CRC32 校验码 / Computes the CRC32 checksum for the given data
互斥锁类,提供线程同步机制 (Mutex class providing thread synchronization mechanisms).
Key key
节点键值 (Key associated with the node).
红黑树的泛型数据节点,继承自 BaseNode (Generic data node for Red-Black Tree, inheriting from BaseNode).
Data data_
存储的数据 (Stored data).
红黑树实现,支持泛型键和值,并提供线程安全操作 (Red-Black Tree implementation supporting generic keys and values with thread...
Node< Data > * Search(const Key &key)
搜索红黑树中的节点 (Search for a node in the Red-Black Tree).
void Insert(BaseNode &node, KeyType &&key)
在树中插入新节点 (Insert a new node into the tree).
static uint32_t GetTime()
获取当前系统时间(毫秒) Gets the current system time in milliseconds
static void Sleep(uint32_t milliseconds)
让线程进入休眠状态 Puts the thread to sleep
topic 所属的命名域 / Naming domain that groups topics
Domain(const char *name)
构造一个 topic 域 / Construct one topic domain
RBTree< uint32_t >::Node< RBTree< uint32_t > > * node_
static Domain * def_domain_
缺省 topic 域。Default topic domain.
static void Unlock(TopicHandle topic)
在普通上下文里释放一个 topic 发布路径 / Unlock one topic publish path in normal context
static Domain * EnsureDefaultDomain()
确保默认域已创建 / Ensure the default domain exists
static void Lock(TopicHandle topic)
在普通上下文里锁住一个 topic 发布路径 / Lock one topic publish path in normal context
static void UnlockFromCallback(TopicHandle topic)
在回调或 ISR 路径里释放一个 topic 发布路径 / Unlock one topic publish path from callback or ISR context
static void LockFromCallback(TopicHandle topic)
在回调或 ISR 路径里锁住一个 topic 发布路径 / Lock one topic publish path from callback or ISR context
static TopicHandle WaitTopic(const char *name, uint32_t timeout=UINT32_MAX, Domain *domain=nullptr)
等待指定名称的 topic 出现 / Wait until a topic with the given name exists
uint32_t GetKey() const
读取 topic 键值 / Read the key value of this topic
LockState
topic 发布路径的内部锁状态 / Internal lock state of the topic publish path
@ UNLOCKED
当前未持有发布锁。The publish path is currently unlocked.
static TopicHandle Find(const char *name, Domain *domain=nullptr)
按名称查找一个已存在 topic / Find one existing topic by name
static RBTree< uint32_t > * domain_
全局 topic 域注册表。Global registry of topic domains.
Topic()
构造一个空 topic 视图 / Construct one empty topic view
static void EnsureDomainRegistry()
确保全局域注册表已创建 / Ensure the global domain registry exists
topic 运行时状态块 / Runtime state block of one topic