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

StartWaiting(),再自己来取数据的订阅者 / Subscriber that first calls StartWaiting() and later pulls the data itself More...

#include <async.hpp>

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

Public Member Functions

 ASyncSubscriber (const char *name, Domain *domain=nullptr)
 通过主题名称构造异步订阅者 / Construct an asynchronous subscriber by topic name
 
 ASyncSubscriber (Topic topic)
 通过 Topic 句柄构造异步订阅者 / Construct an asynchronous subscriber from a Topic handle
 
 ASyncSubscriber (const ASyncSubscriber &other)=delete
 禁止拷贝异步订阅者 / Copy construction is disabled for asynchronous subscribers
 
ASyncSubscriberoperator= (const ASyncSubscriber &other)=delete
 禁止拷贝赋值异步订阅者 / Copy assignment is disabled for asynchronous subscribers
 
 ASyncSubscriber (ASyncSubscriber &&other) noexcept
 移动构造异步订阅者 / Move-construct one asynchronous subscriber
 
ASyncSubscriberoperator= (ASyncSubscriber &&other) noexcept
 移动赋值异步订阅者 / Move-assign one asynchronous subscriber
 
bool Available ()
 检查数据是否可用 / Check whether data is available
 
Data & GetData ()
 获取当前数据 / Retrieve the current data
 
MicrosecondTimestamp GetTimestamp () const
 获取最近一次接收的消息时间戳 / Get the latest received message timestamp
 
void StartWaiting ()
 开始等待数据更新 / Start waiting for a data update
 

Data Fields

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

Detailed Description

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

StartWaiting(),再自己来取数据的订阅者 / Subscriber that first calls StartWaiting() and later pulls the data itself

先等待再主动取数据的异步订阅者 / Asynchronous subscriber that waits first and then pulls data explicitly

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

Definition at line 247 of file topic.hpp.

Constructor & Destructor Documentation

◆ ASyncSubscriber() [1/4]

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

通过主题名称构造异步订阅者 / Construct an asynchronous subscriber by topic name

Parameters
name订阅的主题名称 / Name of the subscribed topic
domain可选的域指针 / Optional domain pointer
Note
包含初始化期动态内存分配,订阅者应长期存在 / Contains initialization-time dynamic allocation; subscribers are expected to be long-lived

Definition at line 48 of file async.hpp.

49 : ASyncSubscriber(Topic(WaitTopic(name, UINT32_MAX, domain)))
50 {
51 }
ASyncSubscriber(const char *name, Domain *domain=nullptr)
通过主题名称构造异步订阅者 / Construct an asynchronous subscriber by topic name
Definition async.hpp:48
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
Topic()
构造一个空 topic 视图 / Construct one empty topic view
Definition topic.cpp:115

◆ ASyncSubscriber() [2/4]

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

通过 Topic 句柄构造异步订阅者 / Construct an asynchronous subscriber from a Topic handle

Parameters
topic订阅的主题 / Subscribed topic
Note
包含初始化期动态内存分配,订阅者应长期存在 / Contains initialization-time dynamic allocation; subscribers are expected to be long-lived

Definition at line 59 of file async.hpp.

60 {
62
63 block_ = new LockFreeList::Node<ASyncBlock>;
64 block_->data_.type = SuberType::ASYNC;
65 block_->data_.timestamp = MicrosecondTimestamp();
67 block_->data_.copy_payload = &Topic::CopyPayload<Data>;
68 topic.block_->data_.subers.Add(*block_);
69 }
LockFreeList::Node< ASyncBlock > * block_
订阅者数据块。Subscriber data block.
Definition async.hpp:171
@ ASYNC
异步本地缓冲型订阅者。Asynchronous local-buffer subscriber.
static void * AllocateSubscriberBuffer()
为订阅者分配一个长期存在的本地接收对象 / Allocate one long-lived local receive object for a subscriber
Definition topic.hpp:590
static void CopyPayload(void *dst, void *payload_addr)
按精确类型把一份 payload 拷到订阅者缓冲区 / Copy one payload into a subscriber buffer using the exact type
Definition topic.hpp:605
static void CheckSubscriberType(Topic topic)
断言订阅者看到的精确 payload 类型与 topic 契约一致 / Assert that the exact payload type seen by a subscriber matches t...
Definition topic.hpp:574

◆ ASyncSubscriber() [3/4]

template<typename Data >
LibXR::Topic::ASyncSubscriber< Data >::ASyncSubscriber ( const ASyncSubscriber< Data > & other)
delete

禁止拷贝异步订阅者 / Copy construction is disabled for asynchronous subscribers

Parameters
other待拷贝的异步订阅者 / Asynchronous subscriber to copy from

◆ ASyncSubscriber() [4/4]

template<typename Data >
LibXR::Topic::ASyncSubscriber< Data >::ASyncSubscriber ( ASyncSubscriber< Data > && other)
inlinenoexcept

移动构造异步订阅者 / Move-construct one asynchronous subscriber

Parameters
other被转移的异步订阅者 / Asynchronous 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 94 of file async.hpp.

94 : block_(other.block_)
95 {
96 other.block_ = nullptr;
97 }

Member Function Documentation

◆ Available()

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

检查数据是否可用 / Check whether data is available

Returns
数据已准备好返回 true,否则返回 false / Returns true if data is ready, otherwise false

Definition at line 123 of file async.hpp.

124 {
125 return block_->data_.state.load(std::memory_order_acquire) ==
127 }
@ DATA_READY
本地缓冲区已有一份待消费的新数据。One unread fresh sample is buffered locally.

◆ GetData()

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

获取当前数据 / Retrieve the current data

Returns
当前数据引用 / Returns a reference to the current data
Note
若当前缓冲区处于 DATA_READY,本次读取会把状态清回 IDLE;之后新的发布需要 重新调用 StartWaiting() 才会继续接收 / If the local buffer is currently DATA_READY, this read clears the state back to IDLE; later publishes are ignored again until StartWaiting() is called

Definition at line 139 of file async.hpp.

140 {
141 if (block_->data_.state.load(std::memory_order_acquire) ==
143 {
144 block_->data_.state.store(ASyncSubscriberState::IDLE, std::memory_order_release);
145 }
146 return *reinterpret_cast<Data*>(block_->data_.buff_addr);
147 }
@ IDLE
当前没有等待,也没有待消费的新数据。No wait is pending and no unread data is buffered.

◆ GetTimestamp()

template<typename Data >
MicrosecondTimestamp LibXR::Topic::ASyncSubscriber< Data >::GetTimestamp ( ) const
inline

获取最近一次接收的消息时间戳 / Get the latest received message timestamp

Returns
最近一次接收的消息时间戳 / Returns the latest received message timestamp

Definition at line 153 of file async.hpp.

153{ return block_->data_.timestamp; }

◆ operator=() [1/2]

template<typename Data >
ASyncSubscriber & LibXR::Topic::ASyncSubscriber< Data >::operator= ( ASyncSubscriber< Data > && other)
inlinenoexcept

移动赋值异步订阅者 / Move-assign one asynchronous subscriber

Parameters
other被转移的异步订阅者 / Asynchronous subscriber to move from
Returns
当前异步订阅者 / Returns the current asynchronous 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 109 of file async.hpp.

110 {
111 if (this != &other)
112 {
113 block_ = other.block_;
114 other.block_ = nullptr;
115 }
116 return *this;
117 }

◆ operator=() [2/2]

template<typename Data >
ASyncSubscriber & LibXR::Topic::ASyncSubscriber< Data >::operator= ( const ASyncSubscriber< Data > & other)
delete

禁止拷贝赋值异步订阅者 / Copy assignment is disabled for asynchronous subscribers

Parameters
other待拷贝的异步订阅者 / Asynchronous subscriber to copy from
Returns
当前异步订阅者 / Returns the current asynchronous subscriber

◆ StartWaiting()

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

开始等待数据更新 / Start waiting for a data update

Note
异步订阅者只接收 WAITING 状态下的下一次发布;IDLEDATA_READY 状态下的新发布会被忽略 / Async subscribers only capture the next publish while in WAITING state; new publishes in IDLE or DATA_READY state are ignored

Definition at line 161 of file async.hpp.

162 {
163 if (block_->data_.state.load(std::memory_order_acquire) ==
165 {
166 block_->data_.state.store(ASyncSubscriberState::WAITING,
167 std::memory_order_release);
168 }
169 }
@ WAITING
等待下一次发布填充本地缓冲区。Waiting for the next publish to fill the local buffer.

Field Documentation

◆ block_

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

订阅者数据块。Subscriber data block.

Definition at line 171 of file async.hpp.


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