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

#include <publisher.h>

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

Public 成员函数

 Publisher (const std::string &channel_name, const proto::QosProfile &qos, eprosima::fastdds::dds::DomainParticipant *participant)
 
virtual ~Publisher ()
 
bool Init ()
 
bool Write (const UnderlayMessage &msg, bool is_topo_msg=false)
 
bool Write (const UnderlayMessage &msg, const MessageInfo &msg_info, bool is_topo_msg=false)
 
void Shutdown ()
 

详细描述

在文件 publisher.h42 行定义.

构造及析构函数说明

◆ Publisher()

apollo::cyber::transport::Publisher::Publisher ( const std::string &  channel_name,
const proto::QosProfile qos,
eprosima::fastdds::dds::DomainParticipant *  participant 
)

在文件 publisher.cc24 行定义.

27 : channel_name_(channel_name),
28 qos_(qos),
29 shutdown_(false),
30 participant_(participant),
31 publisher_(nullptr),
32 topic_(nullptr),
33 writer_(nullptr) {}

◆ ~Publisher()

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

在文件 publisher.cc35 行定义.

成员函数说明

◆ Init()

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

在文件 publisher.cc37 行定义.

37 {
38 eprosima::fastdds::dds::PublisherQos pub_qos;
40 !QosFiller::FillInPubQos(this->channel_name_, this->qos_, &pub_qos),
41 false);
42 publisher_ = participant_->create_publisher(pub_qos, nullptr);
43 if (publisher_ == nullptr) {
44 AINFO << "something went wrong while creating the publisher...";
45 return false;
46 }
47
48 if (!EnsureCreateTopic(this->channel_name_)) {
49 AINFO << "something went wrong while creating the topic...";
50 return false;
51 }
52
53 eprosima::fastdds::dds::DataWriterQos writer_qos;
55 !QosFiller::FillInWriterQos(this->channel_name_, this->qos_, &writer_qos),
56 false);
57 writer_ = publisher_->create_datawriter(topic_, writer_qos, nullptr);
58 if (writer_ == nullptr) {
59 AINFO << "something went wrong while creating the datawriter...";
60 return false;
61 }
62
63 return true;
64}
static bool FillInPubQos(const std::string &channel_name, const proto::QosProfile &qos, eprosima::fastdds::dds::PublisherQos *pub_qos)
static bool FillInWriterQos(const std::string &channel_name, const proto::QosProfile &qos, eprosima::fastdds::dds::DataWriterQos *writer_qos)
#define RETURN_VAL_IF(condition, val)
Definition log.h:114
#define AINFO
Definition log.h:42

◆ Shutdown()

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

在文件 publisher.cc99 行定义.

99 {
100 RETURN_IF(shutdown_.exchange(true));
101
102 if (publisher_ != nullptr && writer_ != nullptr) {
103 publisher_->delete_datawriter(writer_);
104 writer_ = nullptr;
105 }
106 if (participant_ != nullptr && publisher_ != nullptr) {
107 if (participant_->delete_publisher(publisher_) ==
108 eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK) {
109 publisher_ = nullptr;
110 } else {
111 AERROR << channel_name_ << ": Failed to delete the publisher.";
112 }
113 }
114 if (participant_ != nullptr && topic_ != nullptr) {
115 participant_->delete_topic(topic_);
116 topic_ = nullptr;
117 }
118}
#define AERROR
Definition log.h:44
#define RETURN_IF(condition)
Definition log.h:106

◆ Write() [1/2]

bool apollo::cyber::transport::Publisher::Write ( const UnderlayMessage msg,
bool  is_topo_msg = false 
)

在文件 publisher.cc66 行定义.

66 {
67 RETURN_VAL_IF(shutdown_.load(), false);
68 if (is_topo_msg) {
69 AINFO << "FastDDSPublisher::Write data size: " << msg.data().size();
70 }
71 return writer_->write(
72 reinterpret_cast<void*>(const_cast<UnderlayMessage*>(&msg)));
73}

◆ Write() [2/2]

bool apollo::cyber::transport::Publisher::Write ( const UnderlayMessage msg,
const MessageInfo msg_info,
bool  is_topo_msg = false 
)

在文件 publisher.cc75 行定义.

76 {
77 RETURN_VAL_IF(shutdown_.load(), false);
78 if (is_topo_msg) {
79 AINFO << "FastDDSPublisher::Write data size: " << msg.data().size();
80 }
81
82 eprosima::fastrtps::rtps::WriteParams wparams;
83
84 char* ptr =
85 reinterpret_cast<char*>(&wparams.related_sample_identity().writer_guid());
86
87 memcpy(ptr, msg_info.sender_id().data(), ID_SIZE);
88 memcpy(ptr + ID_SIZE, msg_info.spare_id().data(), ID_SIZE);
89
90 wparams.related_sample_identity().sequence_number().high =
91 (int32_t)((msg_info.seq_num() & 0xFFFFFFFF00000000) >> 32);
92 wparams.related_sample_identity().sequence_number().low =
93 (int32_t)(msg_info.seq_num() & 0xFFFFFFFF);
94
95 return writer_->write(
96 reinterpret_cast<void*>(const_cast<UnderlayMessage*>(&msg)), wparams);
97}
constexpr uint8_t ID_SIZE
Definition identity.h:28

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