libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::Topic::ASyncSubscriber< Data > Class Template Reference

异步订阅者类,用于订阅异步数据 Asynchronous subscriber class for subscribing to asynchronous data More...

#include <message.hpp>

Collaboration diagram for LibXR::Topic::ASyncSubscriber< Data >:
[legend]

Public Member Functions

 ASyncSubscriber (const char *name, Domain *domain=nullptr)
 构造函数,通过名称和数据创建订阅者 Constructor to create a subscriber with a name and data
 
 ASyncSubscriber (Topic topic)
 构造函数,使用 Topic 进行初始化 Constructor using a Topic for initialization
 
bool Available ()
 检查数据是否可用 Checks if data is available
 
Data & GetData ()
 获取当前数据 Retrieves the current data
 
void StartWaiting ()
 开始等待数据更新 Starts waiting for data update
 

Data Fields

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

Detailed Description

template<typename Data>
class LibXR::Topic::ASyncSubscriber< Data >

异步订阅者类,用于订阅异步数据 Asynchronous subscriber class for subscribing to asynchronous data

Template Parameters
Data订阅的数据类型 Subscribed data type

Definition at line 302 of file message.hpp.

Constructor & Destructor Documentation

◆ ASyncSubscriber() [1/2]

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

构造函数,通过名称和数据创建订阅者 Constructor to create a subscriber with a name and data

Parameters
name订阅的主题名称 Name of the subscribed topic
domain可选的域指针 Optional domain pointer (default: nullptr)

Definition at line 311 of file message.hpp.

312 {
313 *this = ASyncSubscriber(WaitTopic(name, UINT32_MAX, domain));
314 }
ASyncSubscriber(const char *name, Domain *domain=nullptr)
构造函数,通过名称和数据创建订阅者 Constructor to create a subscriber with a name and data
Definition message.hpp:311
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.hpp:847

◆ ASyncSubscriber() [2/2]

template<typename Data >
LibXR::Topic::ASyncSubscriber< Data >::ASyncSubscriber ( Topic topic)
inline

构造函数,使用 Topic 进行初始化 Constructor using a Topic for initialization

Parameters
topic订阅的主题 Subscribed topic

Definition at line 321 of file message.hpp.

322 {
323 if (topic.block_->data_.check_length)
324 {
325 ASSERT(topic.block_->data_.max_length == sizeof(Data));
326 }
327 else
328 {
329 ASSERT(topic.block_->data_.max_length <= sizeof(Data));
330 }
331
332 block_ = new LockFreeList::Node<ASyncBlock>;
333 block_->data_.type = SuberType::ASYNC;
334 block_->data_.buff = *(new Data);
335 topic.block_->data_.subers.Add(*block_);
336 }
LockFreeList::Node< ASyncBlock > * block_
订阅者数据块。Subscriber data block.
Definition message.hpp:366
@ ASYNC
异步订阅者。Asynchronous subscriber.

Member Function Documentation

◆ Available()

template<typename Data >
bool LibXR::Topic::ASyncSubscriber< Data >::Available ( )
inline

检查数据是否可用 Checks if data is available

Returns
true 如果数据已准备好,则返回 true true if data is ready
false 如果数据不可用,则返回 false false if data is not available

Definition at line 346 of file message.hpp.

346{ return block_->data_.data_ready; }

◆ GetData()

template<typename Data >
Data & LibXR::Topic::ASyncSubscriber< Data >::GetData ( )
inline

获取当前数据 Retrieves the current data

Returns
Data& 返回数据引用 Reference to the data

Definition at line 354 of file message.hpp.

355 {
356 block_->data_.data_ready = false;
357 return *reinterpret_cast<Data *>(block_->data_.buff.addr_);
358 }

◆ StartWaiting()

template<typename Data >
void LibXR::Topic::ASyncSubscriber< Data >::StartWaiting ( )
inline

开始等待数据更新 Starts waiting for data update

Definition at line 364 of file message.hpp.

364{ block_->data_.waiting = true; }

Field Documentation

◆ block_

template<typename Data >
LockFreeList::Node<ASyncBlock>* LibXR::Topic::ASyncSubscriber< Data >::block_

订阅者数据块。Subscriber data block.

Definition at line 366 of file message.hpp.


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