Apollo 10.0
自动驾驶开放平台
apollo::cyber::transport::Subscriber类 参考

#include <subscriber.h>

apollo::cyber::transport::Subscriber 的协作图:

Public 成员函数

 Subscriber (const std::string &name, const proto::QosProfile &qos, eprosima::fastdds::dds::DomainParticipant *participant, const rtps::subsciber_callback &callback)
 
virtual ~Subscriber ()
 
bool Init ()
 
void Shutdown ()
 

详细描述

在文件 subscriber.h45 行定义.

构造及析构函数说明

◆ Subscriber()

apollo::cyber::transport::Subscriber::Subscriber ( const std::string &  name,
const proto::QosProfile qos,
eprosima::fastdds::dds::DomainParticipant *  participant,
const rtps::subsciber_callback callback 
)

在文件 subscriber.cc22 行定义.

25 : channel_name_(name),
26 qos_(qos),
27 shutdown_(false),
28 callback_(callback),
29 subscriber_listener_(nullptr),
30 participant_(participant),
31 subscriber_(nullptr),
32 topic_(nullptr),
33 reader_(nullptr) {}

◆ ~Subscriber()

apollo::cyber::transport::Subscriber::~Subscriber ( )
virtual

在文件 subscriber.cc35 行定义.

35{}

成员函数说明

◆ Init()

bool apollo::cyber::transport::Subscriber::Init ( )

在文件 subscriber.cc37 行定义.

37 {
38 eprosima::fastdds::dds::SubscriberQos sub_qos;
40 !QosFiller::FillInSubQos(this->channel_name_, this->qos_, &sub_qos),
41 false);
42 subscriber_ = participant_->create_subscriber(sub_qos);
43 if (subscriber_ == nullptr) {
44 AINFO << "something went wrong while creating the fastdds subscriber...";
45 return false;
46 }
47
48 if (!EnsureCreateTopic(this->channel_name_)) {
49 AINFO << "something went wrong while creating the fastdds topic...";
50 return false;
51 }
52
53 eprosima::fastdds::dds::DataReaderQos reader_qos;
55 !QosFiller::FillInReaderQos(this->channel_name_, this->qos_, &reader_qos),
56 false);
57 subscriber_listener_ = new dispatcher::SubscriberListener(this->callback_);
58
59 reader_ =
60 subscriber_->create_datareader(topic_, reader_qos, subscriber_listener_);
61 if (reader_ == nullptr) {
62 AINFO << "something went wrong while creating the fastdds datareader...";
63 return false;
64 }
65
66 ADEBUG << "dds reader: " << reader_ << ", subscriber: " << this
67 << ", reader guid: " << reader_->guid()
68 << ", channel: " << this->channel_name_;
69 return true;
70}
static bool FillInSubQos(const std::string &channel_name, const proto::QosProfile &qos, eprosima::fastdds::dds::SubscriberQos *sub_qos)
static bool FillInReaderQos(const std::string &channel_name, const proto::QosProfile &qos, eprosima::fastdds::dds::DataReaderQos *reader_qos)
#define RETURN_VAL_IF(condition, val)
Definition log.h:114
#define ADEBUG
Definition log.h:41
#define AINFO
Definition log.h:42

◆ Shutdown()

void apollo::cyber::transport::Subscriber::Shutdown ( )

在文件 subscriber.cc72 行定义.

72 {
73 RETURN_IF(shutdown_.exchange(true));
74
75 if (subscriber_ != nullptr && reader_ != nullptr) {
76 subscriber_->delete_datareader(reader_);
77 reader_ = nullptr;
78 }
79 if (participant_ != nullptr && subscriber_ != nullptr) {
80 if (participant_->delete_subscriber(subscriber_) ==
81 eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK) {
82 subscriber_ = nullptr;
83 } else {
84 AERROR << channel_name_ << ": Failed to delete the subscriber.";
85 }
86 }
87 if (participant_ != nullptr && topic_ != nullptr) {
88 participant_->delete_topic(topic_);
89 topic_ = nullptr;
90 }
91
92 if (subscriber_listener_ != nullptr) {
93 delete subscriber_listener_;
94 }
95}
#define AERROR
Definition log.h:44
#define RETURN_IF(condition)
Definition log.h:106

该类的文档由以下文件生成: