libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::Topic::QueuedSubscriber Class Reference

每次发布都往队列里塞一份数据的订阅者 / Subscriber that pushes one entry into a queue on each publish More...

#include <queue.hpp>

Collaboration diagram for LibXR::Topic::QueuedSubscriber:
[legend]

Public Member Functions

template<typename Data >
 QueuedSubscriber (const char *name, SPSCQueue< Data > &queue, Domain *domain=nullptr)
 通过主题名称构造队列订阅者 / Construct a queue subscriber by topic name
 
template<typename Data >
 QueuedSubscriber (const char *name, SPSCQueue< Message< Data > > &queue, Domain *domain=nullptr)
 通过主题名称构造带时间戳消息队列订阅者 / Construct a queue subscriber for timestamped messages by topic name
 
template<typename Data >
 QueuedSubscriber (Topic topic, SPSCQueue< Data > &queue)
 使用 Topic 和无锁队列构造订阅者 / Construct a subscriber from a Topic and a lock-free queue
 
template<typename Data >
 QueuedSubscriber (Topic topic, SPSCQueue< Message< Data > > &queue)
 使用 Topic 和带时间戳消息队列构造订阅者 / Construct a subscriber from a Topic and a timestamped message queue
 
 QueuedSubscriber (const QueuedSubscriber &other)=delete
 禁止拷贝队列订阅者 / Copy construction is disabled for queued subscribers
 
QueuedSubscriberoperator= (const QueuedSubscriber &other)=delete
 禁止拷贝赋值队列订阅者 / Copy assignment is disabled for queued subscribers
 
 QueuedSubscriber (QueuedSubscriber &&other) noexcept
 移动构造队列订阅者 / Move-construct one queued subscriber
 
QueuedSubscriberoperator= (QueuedSubscriber &&other) noexcept
 移动赋值队列订阅者 / Move-assign one queued subscriber
 

Private Attributes

LockFreeList::Node< QueueBlock > * block_
 订阅者数据块。Subscriber data block.
 

Detailed Description

每次发布都往队列里塞一份数据的订阅者 / Subscriber that pushes one entry into a queue on each publish

把每次发布推入队列的订阅者 / Subscriber that pushes each publish into a queue

Definition at line 24 of file queue.hpp.

Constructor & Destructor Documentation

◆ QueuedSubscriber() [1/6]

template<typename Data >
LibXR::Topic::QueuedSubscriber::QueuedSubscriber ( const char * name,
SPSCQueue< Data > & queue,
Domain * domain = nullptr )
inline

通过主题名称构造队列订阅者 / Construct a queue subscriber by topic name

Template Parameters
Data队列存储的数据类型 / Data type stored in the queue
Parameters
name订阅的主题名称 / Name of the subscribed topic
queue订阅的数据队列 / Subscribed data queue
domain可选的域指针,默认为 nullptr / Optional domain pointer, default nullptr
Note
包含初始化期动态内存分配,订阅者应长期存在 / Contains initialization-time dynamic allocation; subscribers are expected to be long-lived
队列订阅者只保存 queue 的指针;队列对象本身必须至少活到订阅者不再使用 为止 / Queued subscribers keep only a pointer to queue; the queue object itself must outlive the subscriber's use of it
每次发布都会直接调一次底层 SPSCQueueBase::PushBytes();如果 push 不进去, 这次发布就直接丢掉 / Each publish directly calls one underlying SPSCQueueBase::PushBytes(); if that push cannot fit, this publish is dropped immediately

Definition at line 46 of file queue.hpp.

47 : QueuedSubscriber(Topic(WaitTopic(name, UINT32_MAX, domain)), queue)
48 {
49 }
QueuedSubscriber(const char *name, SPSCQueue< Data > &queue, Domain *domain=nullptr)
通过主题名称构造队列订阅者 / Construct a queue subscriber by topic name
Definition queue.hpp:46
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
Topic()
构造一个空 topic 视图 / Construct one empty topic view
Definition topic.cpp:114

◆ QueuedSubscriber() [2/6]

template<typename Data >
LibXR::Topic::QueuedSubscriber::QueuedSubscriber ( const char * name,
SPSCQueue< Message< Data > > & queue,
Domain * domain = nullptr )
inline

通过主题名称构造带时间戳消息队列订阅者 / Construct a queue subscriber for timestamped messages by topic name

Template Parameters
Data队列消息的数据类型 / Data type stored in the queue message
Parameters
name订阅的主题名称 / Name of the subscribed topic
queue订阅的消息队列 / Subscribed message queue
domain可选的域指针,默认为 nullptr / Optional domain pointer, default nullptr
Note
队列订阅者只保存 queue 的指针;队列对象本身必须至少活到订阅者不再使用 为止 / Queued subscribers keep only a pointer to queue; the queue object itself must outlive the subscriber's use of it
每次发布都会直接调一次底层 SPSCQueueBase::PushBytes();如果 push 不进去, 这次发布就直接丢掉 / Each publish directly calls one underlying SPSCQueueBase::PushBytes(); if that push cannot fit, this publish is dropped immediately

Definition at line 69 of file queue.hpp.

71 : QueuedSubscriber(Topic(WaitTopic(name, UINT32_MAX, domain)), queue)
72 {
73 }

◆ QueuedSubscriber() [3/6]

template<typename Data >
LibXR::Topic::QueuedSubscriber::QueuedSubscriber ( Topic topic,
SPSCQueue< Data > & queue )
inline

使用 Topic 和无锁队列构造订阅者 / Construct a subscriber from a Topic and a lock-free queue

Template Parameters
Data队列存储的数据类型 / Data type stored in the queue
Parameters
topic订阅的主题 / Subscribed topic
queue订阅的数据队列 / Subscribed data queue
Note
包含初始化期动态内存分配,订阅者应长期存在 / Contains initialization-time dynamic allocation; subscribers are expected to be long-lived
队列订阅者只保存 queue 的指针;队列对象本身必须至少活到订阅者不再使用 为止 / Queued subscribers keep only a pointer to queue; the queue object itself must outlive the subscriber's use of it
每次发布都会直接调一次底层 SPSCQueueBase::PushBytes();如果 push 不进去, 这次发布就直接丢掉 / Each publish directly calls one underlying SPSCQueueBase::PushBytes(); if that push cannot fit, this publish is dropped immediately

Definition at line 93 of file queue.hpp.

94 {
96
97 block_ = new LockFreeList::Node<QueueBlock>;
98 block_->data_.type = SuberType::QUEUE;
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 }
LockFreeList::Node< QueueBlock > * block_
订阅者数据块。Subscriber data block.
Definition queue.hpp:186
@ 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

◆ QueuedSubscriber() [4/6]

template<typename Data >
LibXR::Topic::QueuedSubscriber::QueuedSubscriber ( Topic topic,
SPSCQueue< Message< Data > > & queue )
inline

使用 Topic 和带时间戳消息队列构造订阅者 / Construct a subscriber from a Topic and a timestamped message queue

Template Parameters
Data队列消息的数据类型 / Data type stored in the queue message
Parameters
topic订阅的主题 / Subscribed topic
queue订阅的消息队列 / Subscribed message queue
Note
队列订阅者只保存 queue 的指针;队列对象本身必须至少活到订阅者不再使用 为止 / Queued subscribers keep only a pointer to queue; the queue object itself must outlive the subscriber's use of it
每次发布都会直接调一次底层 SPSCQueueBase::PushBytes();如果 push 不进去, 这次发布就直接丢掉 / Each publish directly calls one underlying SPSCQueueBase::PushBytes(); if that push cannot fit, this publish is dropped immediately

Definition at line 122 of file queue.hpp.

123 {
125
126 block_ = new LockFreeList::Node<QueueBlock>;
127 block_->data_.type = SuberType::QUEUE;
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 }

◆ QueuedSubscriber() [5/6]

LibXR::Topic::QueuedSubscriber::QueuedSubscriber ( const QueuedSubscriber & other)
delete

禁止拷贝队列订阅者 / Copy construction is disabled for queued subscribers

Parameters
other待拷贝的队列订阅者 / Queued subscriber to copy from

◆ QueuedSubscriber() [6/6]

LibXR::Topic::QueuedSubscriber::QueuedSubscriber ( QueuedSubscriber && other)
inlinenoexcept

移动构造队列订阅者 / Move-construct one queued subscriber

Parameters
other被转移的队列订阅者 / Queued subscriber to move from
Note
这里只移动本地句柄指针;底层订阅块仍留在 topic 的订阅链表里,other 会被清成空句柄 / This moves only the local handle pointer; the underlying subscriber block stays registered in the topic list and other becomes empty

Definition at line 160 of file queue.hpp.

160 : block_(other.block_)
161 {
162 other.block_ = nullptr;
163 }

Member Function Documentation

◆ operator=() [1/2]

QueuedSubscriber & LibXR::Topic::QueuedSubscriber::operator= ( const QueuedSubscriber & other)
delete

禁止拷贝赋值队列订阅者 / Copy assignment is disabled for queued subscribers

Parameters
other待拷贝的队列订阅者 / Queued subscriber to copy from
Returns
当前队列订阅者 / Returns the current queued subscriber

◆ operator=() [2/2]

QueuedSubscriber & LibXR::Topic::QueuedSubscriber::operator= ( QueuedSubscriber && other)
inlinenoexcept

移动赋值队列订阅者 / Move-assign one queued subscriber

Parameters
other被转移的队列订阅者 / Queued subscriber to move from
Returns
当前队列订阅者 / Returns the current queued subscriber
Note
这里只改当前包装对象指向的订阅块,不会注销旧块;底层订阅块仍留在 topic 的订阅链表里,other 会被清成空句柄 / This only changes which subscriber block the current wrapper points to and does not unregister the old block; the underlying subscriber blocks stay in the topic list and other becomes empty

Definition at line 175 of file queue.hpp.

176 {
177 if (this != &other)
178 {
179 block_ = other.block_;
180 other.block_ = nullptr;
181 }
182 return *this;
183 }

Field Documentation

◆ block_

LockFreeList::Node<QueueBlock>* LibXR::Topic::QueuedSubscriber::block_
private
Initial value:
=
nullptr

订阅者数据块。Subscriber data block.

Definition at line 186 of file queue.hpp.


The documentation for this class was generated from the following file: