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{
12{
13 void* queue;
14 void (*fun)(MicrosecondTimestamp, void*,
15 QueueBlock&);
16};
17
24{
25 public:
42 template <typename Data>
43 QueuedSubscriber(const char* name, LockFreeQueue<Data>& queue, Domain* domain = nullptr)
44 : QueuedSubscriber(Topic(WaitTopic(name, UINT32_MAX, domain)), queue)
45 {
46 }
47
63 template <typename Data>
64 QueuedSubscriber(const char* name, LockFreeQueue<Message<Data>>& queue,
65 Domain* domain = nullptr)
66 : QueuedSubscriber(Topic(WaitTopic(name, UINT32_MAX, domain)), queue)
67 {
68 }
69
85 template <typename Data>
87 {
89
92 block_->data_.queue = &queue;
93 block_->data_.fun = [](MicrosecondTimestamp, void* payload_addr, QueueBlock& block)
94 {
95 LockFreeQueue<Data>* queue = reinterpret_cast<LockFreeQueue<Data>*>(block.queue);
96 (void)queue->Push(*reinterpret_cast<Data*>(payload_addr));
97 };
98
99 topic.block_->data_.subers.Add(*block_);
100 }
101
116 template <typename Data>
118 {
120
123 block_->data_.queue = &queue;
124 block_->data_.fun =
125 [](MicrosecondTimestamp timestamp, void* payload_addr, QueueBlock& block)
126 {
128 reinterpret_cast<LockFreeQueue<Message<Data>>*>(block.queue);
129 (void)queue->Push(
130 Message<Data>{timestamp, *reinterpret_cast<Data*>(payload_addr)});
131 };
132
133 topic.block_->data_.subers.Add(*block_);
134 }
135
140 QueuedSubscriber(const QueuedSubscriber& other) = delete;
141
148
157 QueuedSubscriber(QueuedSubscriber&& other) noexcept : block_(other.block_)
158 {
159 other.block_ = nullptr;
160 }
161
173 {
174 if (this != &other)
175 {
176 block_ = other.block_;
177 other.block_ = nullptr;
178 }
179 return *this;
180 }
181
182 private:
184};
185} // namespace LibXR
数据节点模板,继承自 BaseNode,用于存储具体数据类型。 Template data node that inherits from BaseNode to store specific data...
Data data_
存储的数据。 The stored data.
无锁队列实现 / Lock-free queue implementation
ErrorCode Push(ElementData &&item)
向队列中推入数据 / Pushes data into the queue
微秒时间戳 / Microsecond timestamp
Data data_
存储的数据 (Stored data).
Definition rbt.hpp:98
topic 所属的命名域 / Naming domain that groups topics
Definition topic.hpp:179
每次发布都往队列里塞一份数据的订阅者 / Subscriber that pushes one entry into a queue on each publish
Definition queue.hpp:24
QueuedSubscriber(Topic topic, LockFreeQueue< Data > &queue)
使用 Topic 和无锁队列构造订阅者 / Construct a subscriber from a Topic and a lock-free queue
Definition queue.hpp:86
QueuedSubscriber(const char *name, LockFreeQueue< Data > &queue, Domain *domain=nullptr)
通过主题名称构造队列订阅者 / Construct a queue subscriber by topic name
Definition queue.hpp:43
LockFreeList::Node< QueueBlock > * block_
订阅者数据块。Subscriber data block.
Definition queue.hpp:183
QueuedSubscriber(QueuedSubscriber &&other) noexcept
移动构造队列订阅者 / Move-construct one queued subscriber
Definition queue.hpp:157
QueuedSubscriber(Topic topic, LockFreeQueue< Message< Data > > &queue)
使用 Topic 和带时间戳消息队列构造订阅者 / Construct a subscriber from a Topic and a timestamped message queue
Definition queue.hpp:117
QueuedSubscriber(const char *name, LockFreeQueue< Message< Data > > &queue, Domain *domain=nullptr)
通过主题名称构造带时间戳消息队列订阅者 / Construct a queue subscriber for timestamped messages by topic name
Definition queue.hpp:64
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:172
QueuedSubscriber & operator=(const QueuedSubscriber &other)=delete
禁止拷贝赋值队列订阅者 / Copy assignment is disabled for queued subscribers
发布订阅主题 / Publish-subscribe topic
Definition topic.hpp:57
@ 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:574
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:191
TopicHandle block_
当前 topic 视图绑定的状态块。Runtime state block bound to the current topic view.
Definition topic.hpp:533
LibXR 命名空间
Definition ch32_can.hpp:14
带时间戳和 payload 副本的消息对象 / Message object carrying a timestamp and a payload copy
Definition topic.hpp:140
队列订阅者自己挂的数据块 / Data block owned by one queued subscriber
Definition queue.hpp:12
void * queue
指向订阅队列实例的擦除指针。Erased pointer to the subscribed queue instance.
Definition queue.hpp:13
void(* fun)(MicrosecondTimestamp, void *, QueueBlock &)
把一条发布转发进具体队列类型的适配函数。Adapter that forwards one publish into the concrete queue type.
Definition queue.hpp:14
所有订阅块共用的公共头 / Common header shared by all subscriber blocks
Definition topic.hpp:207