libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
queue.hpp
1#pragma once
2
3#include "../topic.hpp"
4
5namespace LibXR
6{
18
25{
26 public:
45 template <typename Data>
46 QueuedSubscriber(const char* name, SPSCQueue<Data>& queue, Domain* domain = nullptr)
47 : QueuedSubscriber(Topic(WaitTopic(name, UINT32_MAX, domain)), queue)
48 {
49 }
50
68 template <typename Data>
69 QueuedSubscriber(const char* name, SPSCQueue<Message<Data>>& queue,
70 Domain* domain = nullptr)
71 : QueuedSubscriber(Topic(WaitTopic(name, UINT32_MAX, domain)), queue)
72 {
73 }
74
92 template <typename Data>
94 {
96
99 block_->data_.queue = &queue;
100 block_->data_.fun = [](MicrosecondTimestamp, void* payload_addr, QueueBlock& block)
101 { (void)block.queue->PushBytes(payload_addr); };
102
103 topic.block_->data_.subers.Add(*block_);
104 }
105
121 template <typename Data>
123 {
125
128 block_->data_.queue = &queue;
129 block_->data_.fun =
130 [](MicrosecondTimestamp timestamp, void* payload_addr, QueueBlock& block)
131 {
132 Message<Data> message{timestamp, *reinterpret_cast<Data*>(payload_addr)};
133 (void)block.queue->PushBytes(&message);
134 };
135
136 topic.block_->data_.subers.Add(*block_);
137 }
138
143 QueuedSubscriber(const QueuedSubscriber& other) = delete;
144
151
160 QueuedSubscriber(QueuedSubscriber&& other) noexcept : block_(other.block_)
161 {
162 other.block_ = nullptr;
163 }
164
176 {
177 if (this != &other)
178 {
179 block_ = other.block_;
180 other.block_ = nullptr;
181 }
182 return *this;
183 }
184
185 private:
187 nullptr;
188};
189} // namespace LibXR
数据节点模板,继承自 BaseNode,用于存储具体数据类型。 Template data node that inherits from BaseNode to store specific data...
Data data_
存储的数据。 The stored data.
微秒时间戳 / Microsecond timestamp
Data data_
存储的数据 (Stored data).
Definition rbt.hpp:98
单生产者单消费者字节队列内核 / Single-producer single-consumer byte-queue core
单生产者单消费者无锁队列。
topic 所属的命名域 / Naming domain that groups topics
Definition topic.hpp:207
每次发布都往队列里塞一份数据的订阅者 / Subscriber that pushes one entry into a queue on each publish
Definition queue.hpp:25
QueuedSubscriber(const char *name, SPSCQueue< Message< Data > > &queue, Domain *domain=nullptr)
通过主题名称构造带时间戳消息队列订阅者 / Construct a queue subscriber for timestamped messages by topic name
Definition queue.hpp:69
LockFreeList::Node< QueueBlock > * block_
订阅者数据块。Subscriber data block.
Definition queue.hpp:186
QueuedSubscriber(QueuedSubscriber &&other) noexcept
移动构造队列订阅者 / Move-construct one queued subscriber
Definition queue.hpp:160
QueuedSubscriber(Topic topic, SPSCQueue< Data > &queue)
使用 Topic 和无锁队列构造订阅者 / Construct a subscriber from a Topic and a lock-free queue
Definition queue.hpp:93
QueuedSubscriber(const QueuedSubscriber &other)=delete
禁止拷贝队列订阅者 / Copy construction is disabled for queued subscribers
QueuedSubscriber & operator=(QueuedSubscriber &&other) noexcept
移动赋值队列订阅者 / Move-assign one queued subscriber
Definition queue.hpp:175
QueuedSubscriber & operator=(const QueuedSubscriber &other)=delete
禁止拷贝赋值队列订阅者 / Copy assignment is disabled for queued subscribers
QueuedSubscriber(const char *name, SPSCQueue< Data > &queue, Domain *domain=nullptr)
通过主题名称构造队列订阅者 / Construct a queue subscriber by topic name
Definition queue.hpp:46
QueuedSubscriber(Topic topic, SPSCQueue< Message< Data > > &queue)
使用 Topic 和带时间戳消息队列构造订阅者 / Construct a subscriber from a Topic and a timestamped message queue
Definition queue.hpp:122
发布订阅主题 / Publish-subscribe topic
Definition topic.hpp:56
@ QUEUE
队列转发型订阅者。Queue-forwarding subscriber.
static void CheckSubscriberType(Topic topic)
断言订阅者看到的精确 payload 类型与 topic 契约一致 / Assert that the exact payload type seen by a subscriber matches t...
Definition topic.hpp:653
static TopicHandle WaitTopic(const char *name, uint32_t timeout=UINT32_MAX, Domain *domain=nullptr)
等待指定名称的 topic 出现 / Wait until a topic with the given name exists
Definition topic.cpp:190
TopicHandle block_
Definition topic.hpp:610
LibXR 命名空间
Definition ch32_can.hpp:14
带时间戳和 payload 副本的消息对象 / Message object carrying a timestamp and a payload copy
Definition topic.hpp:168
队列订阅者自己挂的数据块 / Data block owned by one queued subscriber
Definition queue.hpp:12
void(* fun)(MicrosecondTimestamp, void *, QueueBlock &)
Definition queue.hpp:14
SPSCQueueBase * queue
指向订阅队列基类。Pointer to the subscribed queue base.
Definition queue.hpp:13
所有订阅块共用的公共头 / Common header shared by all subscriber blocks
Definition topic.hpp:237