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 >:

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

List::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 215 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 225 of file message.hpp.

226 {
227 *this = SyncSubscriber(WaitTopic(name, UINT32_MAX, domain), data);
228 }
SyncSubscriber(const char *name, Data &data, Domain *domain=nullptr)
通过主题名称构造同步订阅者。Constructs a synchronous subscriber by topic name.
Definition message.hpp:225
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:916
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值

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

237 {
238 if (topic.block_->data_.check_length)
239 {
240 ASSERT(topic.block_->data_.max_length == sizeof(Data));
241 }
242 else
243 {
244 ASSERT(topic.block_->data_.max_length <= sizeof(Data));
245 }
246
247 block_ = new List::Node<SyncBlock>;
248 block_->data_.type = SuberType::SYNC;
249 block_->data_.buff = RawData(data);
250 topic.block_->data_.subers.Add(*block_);
251 }
List::Node< SyncBlock > * block_
订阅者数据块。Subscriber data block.
Definition message.hpp:263
@ 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 258 of file message.hpp.

259 {
260 return block_->data_.sem.Wait(timeout);
261 }

Field Documentation

◆ block_

订阅者数据块。Subscriber data block.

Definition at line 263 of file message.hpp.


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