23 eprosima::fastdds::dds::DomainParticipant* participant,
25 : channel_name_(name),
29 subscriber_listener_(nullptr),
30 participant_(participant),
38 eprosima::fastdds::dds::SubscriberQos sub_qos;
42 subscriber_ = participant_->create_subscriber(sub_qos);
43 if (subscriber_ ==
nullptr) {
44 AINFO <<
"something went wrong while creating the fastdds subscriber...";
48 if (!EnsureCreateTopic(this->channel_name_)) {
49 AINFO <<
"something went wrong while creating the fastdds topic...";
53 eprosima::fastdds::dds::DataReaderQos reader_qos;
60 subscriber_->create_datareader(topic_, reader_qos, subscriber_listener_);
61 if (reader_ ==
nullptr) {
62 AINFO <<
"something went wrong while creating the fastdds datareader...";
66 ADEBUG <<
"dds reader: " << reader_ <<
", subscriber: " <<
this
67 <<
", reader guid: " << reader_->guid()
68 <<
", channel: " << this->channel_name_;
75 if (subscriber_ !=
nullptr && reader_ !=
nullptr) {
76 subscriber_->delete_datareader(reader_);
79 if (participant_ !=
nullptr && subscriber_ !=
nullptr) {
80 if (participant_->delete_subscriber(subscriber_) ==
81 eprosima::fastrtps::types::ReturnCode_t::RETCODE_OK) {
82 subscriber_ =
nullptr;
84 AERROR << channel_name_ <<
": Failed to delete the subscriber.";
87 if (participant_ !=
nullptr && topic_ !=
nullptr) {
88 participant_->delete_topic(topic_);
92 if (subscriber_listener_ !=
nullptr) {
93 delete subscriber_listener_;
97bool Subscriber::EnsureCreateTopic(
const std::string& channel_name) {
98 topic_ =
dynamic_cast<eprosima::fastdds::dds::Topic*
>(
99 participant_->lookup_topicdescription(channel_name));
100 if (topic_ ==
nullptr) {
101 eprosima::fastdds::dds::TopicQos topic_qos;
106 participant_->create_topic(channel_name,
"UnderlayMessage", topic_qos);
108 return (topic_ !=
nullptr);
static bool FillInTopicQos(const std::string &channel_name, const proto::QosProfile &qos, eprosima::fastdds::dds::TopicQos *topic_qos)
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)
Subscriber(const std::string &name, const proto::QosProfile &qos, eprosima::fastdds::dds::DomainParticipant *participant, const rtps::subsciber_callback &callback)
#define RETURN_VAL_IF(condition, val)
#define RETURN_IF(condition)
std::function< void(const std::shared_ptr< std::string > &msg_str, uint64_t channel_id, const MessageInfo &msg_info)> subsciber_callback