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 236 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 246 of file message.hpp.

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

◆ 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 257 of file message.hpp.

258 {
259 if (topic.block_->data_.check_length)
260 {
261 ASSERT(topic.block_->data_.max_length == sizeof(Data));
262 }
263 else
264 {
265 ASSERT(topic.block_->data_.max_length <= sizeof(Data));
266 }
267
268 block_ = new LockFreeList::Node<SyncBlock>;
269 block_->data_.type = SuberType::SYNC;
270 block_->data_.buff = RawData(data);
271 topic.block_->data_.subers.Add(*block_);
272 }
LockFreeList::Node< SyncBlock > * block_
订阅者数据块。Subscriber data block.
Definition message.hpp:285
@ 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 279 of file message.hpp.

280 {
281 // TODO: Reset sem
282 return block_->data_.sem.Wait(timeout);
283 }

Field Documentation

◆ block_

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

订阅者数据块。Subscriber data block.

Definition at line 285 of file message.hpp.


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