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

同步订阅者类,允许同步方式接收数据。Synchronous subscriber class allowing data reception in a synchronous manner. More...

#include <message.hpp>

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

Public Member Functions

 SyncSubscriber (const char *name, Data &data, Domain *domain=nullptr)
 通过主题名称构造同步订阅者。Constructs a synchronous subscriber by topic name.
 
 SyncSubscriber (Topic topic, Data &data)
 通过 Topic 句柄构造同步订阅者。Constructs a synchronous subscriber using a Topic handle.
 
ErrorCode Wait (uint32_t timeout=UINT32_MAX)
 等待接收数据。Waits for data reception.
 

Data Fields

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

Detailed Description

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

同步订阅者类,允许同步方式接收数据。Synchronous subscriber class allowing data reception in a synchronous manner.

Template Parameters
Data订阅的数据类型。Type of data being subscribed to.

Definition at line 232 of file message.hpp.

Constructor & Destructor Documentation

◆ SyncSubscriber() [1/2]

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

通过主题名称构造同步订阅者。Constructs a synchronous subscriber by topic name.

Parameters
name主题名称。Topic name.
data存储接收数据的变量。Variable to store received data.
domain可选的主题域。Optional topic domain.

Definition at line 242 of file message.hpp.

243 {
244 *this = SyncSubscriber<Data>(WaitTopic(name, UINT32_MAX, domain), data);
245 }
SyncSubscriber(const char *name, Data &data, Domain *domain=nullptr)
通过主题名称构造同步订阅者。Constructs a synchronous subscriber by topic name.
Definition message.hpp:242
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

◆ SyncSubscriber() [2/2]

template<typename Data >
LibXR::Topic::SyncSubscriber< Data >::SyncSubscriber ( Topic topic,
Data & data )
inline

通过 Topic 句柄构造同步订阅者。Constructs a synchronous subscriber using a Topic handle.

Parameters
topic订阅的主题。Topic being subscribed to.
data存储接收数据的变量。Variable to store received data.

Definition at line 253 of file message.hpp.

254 {
255 if (topic.block_->data_.check_length)
256 {
257 ASSERT(topic.block_->data_.max_length == sizeof(Data));
258 }
259 else
260 {
261 ASSERT(topic.block_->data_.max_length <= sizeof(Data));
262 }
263
264 block_ = new LockFreeList::Node<SyncBlock>;
265 block_->data_.type = SuberType::SYNC;
266 block_->data_.buff = RawData(data);
267 topic.block_->data_.subers.Add(*block_);
268 }
LockFreeList::Node< SyncBlock > * block_
订阅者数据块。Subscriber data block.
Definition message.hpp:280
@ SYNC
同步订阅者。Synchronous subscriber.

Member Function Documentation

◆ Wait()

template<typename Data >
ErrorCode LibXR::Topic::SyncSubscriber< Data >::Wait ( uint32_t timeout = UINT32_MAX)
inline

等待接收数据。Waits for data reception.

Parameters
timeout超时时间(默认最大值)。Timeout period (default is maximum).
Returns
操作结果的错误码。Error code indicating the operation result.

Definition at line 275 of file message.hpp.

276 {
277 return block_->data_.sem.Wait(timeout);
278 }

Field Documentation

◆ block_

template<typename Data >
LockFreeList::Node<SyncBlock>* LibXR::Topic::SyncSubscriber< Data >::block_

订阅者数据块。Subscriber data block.

Definition at line 280 of file message.hpp.


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