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

Public Member Functions

template<typename Data , uint32_t Length>
 QueuedSubscriber (const char *name, LockFreeQueue< Data > &queue, Domain *domain=nullptr)
 构造函数,自动创建队列
 
template<typename Data >
 QueuedSubscriber (Topic topic, LockFreeQueue< Data > &queue)
 构造函数,使用 Topic 和无锁队列进行初始化 Constructor using a Topic and a lock-free queue
 

Detailed Description

Definition at line 414 of file message.hpp.

Constructor & Destructor Documentation

◆ QueuedSubscriber() [1/2]

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

构造函数,自动创建队列

Template Parameters
Data队列存储的数据类型 Data type stored in the queue
Length队列长度 Queue length
Parameters
name订阅的主题名称 Name of the subscribed topic
queue订阅的数据队列 Subscribed data queue
domain可选的域指针 Optional domain pointer (default: nullptr)
Note
包含动态内存分配。 Contains dynamic memory allocation.

Definition at line 430 of file message.hpp.

432 {
433 *this = QueuedSubscriber(WaitTopic(name, UINT32_MAX, domain), queue);
434 }
QueuedSubscriber(const char *name, LockFreeQueue< Data > &queue, Domain *domain=nullptr)
构造函数,自动创建队列
Definition message.hpp:430
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 message.cpp:368

◆ QueuedSubscriber() [2/2]

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 dynamic memory allocation.

Definition at line 447 of file message.hpp.

448 {
449 if (topic.block_->data_.check_length)
450 {
451 ASSERT(topic.block_->data_.max_length == sizeof(Data));
452 }
453 else
454 {
455 ASSERT(topic.block_->data_.max_length <= sizeof(Data));
456 }
457
458 auto block = new LockFreeList::Node<QueueBlock>;
459 block->data_.type = SuberType::QUEUE;
460 block->data_.queue = &queue;
461 block->data_.fun = [](RawData &data, void *arg, bool in_isr)
462 {
463 UNUSED(in_isr);
464 LockFreeQueue<Data> *queue = reinterpret_cast<LockFreeQueue<Data> *>(arg);
465 queue->Push(*reinterpret_cast<Data *>(data.addr_));
466 };
467
468 topic.block_->data_.subers.Add(*block);
469 }
@ QUEUE
队列订阅者。Queued subscriber.

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