26 eprosima::fastdds::dds::DomainParticipant* participant)
27 : channel_name_(channel_name),
30 participant_(participant),
38 eprosima::fastdds::dds::PublisherQos pub_qos;
42 publisher_ = participant_->create_publisher(pub_qos,
nullptr);
43 if (publisher_ ==
nullptr) {
44 AINFO <<
"something went wrong while creating the publisher...";
48 if (!EnsureCreateTopic(this->channel_name_)) {
49 AINFO <<
"something went wrong while creating the topic...";
53 eprosima::fastdds::dds::DataWriterQos writer_qos;
57 writer_ = publisher_->create_datawriter(topic_, writer_qos,
nullptr);
58 if (writer_ ==
nullptr) {
59 AINFO <<
"something went wrong while creating the datawriter...";
69 AINFO <<
"FastDDSPublisher::Write data size: " << msg.
data().size();
71 return writer_->write(
79 AINFO <<
"FastDDSPublisher::Write data size: " << msg.
data().size();
82 eprosima::fastrtps::rtps::WriteParams wparams;
85 reinterpret_cast<char*
>(&wparams.related_sample_identity().writer_guid());
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);
95 return writer_->write(
102 if (publisher_ !=
nullptr && writer_ !=
nullptr) {
103 publisher_->delete_datawriter(writer_);
106 if (participant_ !=
nullptr && publisher_ !=
nullptr) {
107 if (participant_->delete_publisher(publisher_) ==
108 eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK) {
109 publisher_ =
nullptr;
111 AERROR << channel_name_ <<
": Failed to delete the publisher.";
114 if (participant_ !=
nullptr && topic_ !=
nullptr) {
115 participant_->delete_topic(topic_);
120bool Publisher::EnsureCreateTopic(
const std::string& channel_name) {
121 topic_ =
dynamic_cast<eprosima::fastdds::dds::Topic*
>(
122 participant_->lookup_topicdescription(channel_name));
123 if (topic_ ==
nullptr) {
124 eprosima::fastdds::dds::TopicQos topic_qos;
129 participant_->create_topic(channel_name,
"UnderlayMessage", topic_qos);
131 return (topic_ !=
nullptr);
const char * data() const
const Identity & sender_id() const
const Identity & spare_id() const
bool Write(const UnderlayMessage &msg, bool is_topo_msg=false)
Publisher(const std::string &channel_name, const proto::QosProfile &qos, eprosima::fastdds::dds::DomainParticipant *participant)
static bool FillInTopicQos(const std::string &channel_name, const proto::QosProfile &qos, eprosima::fastdds::dds::TopicQos *topic_qos)
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)
This class represents the structure UnderlayMessage defined by the user in the IDL file.
void data(const std::string &_data)
This function copies the value in member data
#define RETURN_VAL_IF(condition, val)
#define RETURN_IF(condition)
constexpr uint8_t ID_SIZE