libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::Topic::QueuedSubscriber Class Reference
Collaboration diagram for LibXR::Topic::QueuedSubscriber:
[legend]

Public Member Functions

template<typename Data >
 QueuedSubscriber (const char *name, LockFreeQueue< Data > &queue, Domain *domain=nullptr)
 构造函数,自动创建队列
 
template<typename Data >
 QueuedSubscriber (const char *name, LockFreeQueue< Message< Data > > &queue, Domain *domain=nullptr)
 构造函数,使用 Topic 和无锁队列进行初始化 Constructor using a Topic and a lock-free queue
 
template<typename Data >
 QueuedSubscriber (Topic topic, LockFreeQueue< Data > &queue)
 构造函数,使用 Topic 和无锁队列进行初始化 Constructor using a Topic and a lock-free queue
 
template<typename Data >
 QueuedSubscriber (Topic topic, LockFreeQueue< Message< Data > > &queue)
 构造函数,使用 Topic 和带时间戳消息队列进行初始化 Constructor using a Topic and a timestamped message queue
 
 QueuedSubscriber (const QueuedSubscriber &)=delete
 
QueuedSubscriberoperator= (const QueuedSubscriber &)=delete
 
 QueuedSubscriber (QueuedSubscriber &&other) noexcept
 
QueuedSubscriberoperator= (QueuedSubscriber &&other) noexcept
 

Private Attributes

LockFreeList::Node< QueueBlock > * block_ = nullptr
 

Detailed Description

Definition at line 312 of file subscriber.hpp.

Constructor & Destructor Documentation

◆ QueuedSubscriber() [1/5]

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

构造函数,自动创建队列

Template Parameters
Data队列存储的数据类型 Data type stored in the queue
Parameters
name订阅的主题名称 Name of the subscribed topic
queue订阅的数据队列 Subscribed data queue
domain可选的域指针 Optional domain pointer (default: nullptr)
Note
包含初始化期动态内存分配,订阅者应长期存在。 Contains initialization-time dynamic allocation; subscribers are expected to be long-lived.

Definition at line 328 of file subscriber.hpp.

329 : QueuedSubscriber(Topic(WaitTopic(name, UINT32_MAX, domain)), queue)
330 {
331 }
QueuedSubscriber(const char *name, LockFreeQueue< Data > &queue, Domain *domain=nullptr)
构造函数,自动创建队列
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
Definition topic.cpp:223
Topic()
默认构造函数,创建一个空的 Topic 实例 Default constructor, creates an empty Topic instance
Definition topic.cpp:132

◆ QueuedSubscriber() [2/5]

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

构造函数,使用 Topic 和无锁队列进行初始化 Constructor using a Topic and a lock-free queue

Template Parameters
Data队列消息的数据类型 Data type stored in the queue message
Parameters
name订阅的主题名称 Name of the subscribed topic
queue订阅的消息队列 Subscribed message queue
domain可选的域指针 Optional domain pointer (default: nullptr)

Definition at line 342 of file subscriber.hpp.

344 : QueuedSubscriber(Topic(WaitTopic(name, UINT32_MAX, domain)), queue)
345 {
346 }

◆ QueuedSubscriber() [3/5]

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

构造函数,使用 Topic 和无锁队列进行初始化 Constructor using 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.

Definition at line 360 of file subscriber.hpp.

361 {
363
364 block_ = new LockFreeList::Node<QueueBlock>;
365 block_->data_.type = SuberType::QUEUE;
366 block_->data_.queue = &queue;
367 block_->data_.fun = [](MicrosecondTimestamp, RawData data, QueueBlock& block)
368 {
369 LockFreeQueue<Data>* queue = reinterpret_cast<LockFreeQueue<Data>*>(block.queue);
370 (void)queue->Push(*reinterpret_cast<Data*>(data.addr_));
371 };
372
373 topic.block_->data_.subers.Add(*block_);
374 }
@ QUEUE
队列订阅者。Queued subscriber.
static void CheckSubscriberDataSize(Topic topic)
校验订阅者数据类型和主题最大长度是否兼容。 Checks whether subscriber data type is compatible with topic max length.
Definition message.hpp:573

◆ QueuedSubscriber() [4/5]

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

构造函数,使用 Topic 和带时间戳消息队列进行初始化 Constructor using a Topic and a timestamped message queue

Definition at line 381 of file subscriber.hpp.

382 {
384
385 block_ = new LockFreeList::Node<QueueBlock>;
386 block_->data_.type = SuberType::QUEUE;
387 block_->data_.queue = &queue;
388 block_->data_.fun =
389 [](MicrosecondTimestamp timestamp, RawData data, QueueBlock& block)
390 {
391 LockFreeQueue<Message<Data>>* queue =
392 reinterpret_cast<LockFreeQueue<Message<Data>>*>(block.queue);
393 (void)queue->Push(Message<Data>{timestamp, *reinterpret_cast<Data*>(data.addr_)});
394 };
395
396 topic.block_->data_.subers.Add(*block_);
397 }

◆ QueuedSubscriber() [5/5]

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

Definition at line 402 of file subscriber.hpp.

402 : block_(other.block_)
403 {
404 other.block_ = nullptr;
405 }

Member Function Documentation

◆ operator=()

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

Definition at line 407 of file subscriber.hpp.

408 {
409 if (this != &other)
410 {
411 block_ = other.block_;
412 other.block_ = nullptr;
413 }
414 return *this;
415 }

Field Documentation

◆ block_

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

Definition at line 418 of file subscriber.hpp.


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