13#include <fastdds/dds/domain/DomainParticipant.hpp>
14#include <fastdds/dds/topic/Topic.hpp>
15#include <fastdds/dds/topic/TypeSupport.hpp>
16#include <fastdds/dds/subscriber/Subscriber.hpp>
17#include <fastdds/dds/subscriber/DataReader.hpp>
18#include <fastdds/dds/subscriber/DataReaderListener.hpp>
19#include <fastdds/dds/subscriber/SampleInfo.hpp>
20#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
21#include <fastdds/dds/subscriber/qos/SubscriberQos.hpp>
22#include <fastdds/dds/topic/qos/TopicQos.hpp>
23#include <fastrtps/attributes/ParticipantAttributes.h>
24#include <fastrtps/qos/QosPolicies.h>
31namespace efd = eprosima::fastdds::dds;
32using erc = eprosima::fastrtps::types::ReturnCode_t;
49 public eprosima::fastdds::dds::DataReaderListener {
58 efd::DataReader* reader,
59 const efd::SubscriptionMatchedStatus& info)
override {
60 _alive.store(info.current_count > 0, std::memory_order_relaxed);
66 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
69 log_error(
"FastDDSSubscriberMiddleware::on_data_available (",
95 const std::string& topic_name,
97 bool* new_message_flag)
override {
98 return InitImpl(topic_name, message_ptr, new_message_flag,
nullptr);
102 const std::string& topic_name,
104 bool* new_message_flag,
106 return InitImpl(topic_name, message_ptr, new_message_flag, &qos);
115 const std::string& topic_name,
117 bool* new_message_flag,
122 if (
_type ==
nullptr) {
123 log_error(
"FastDDSSubscriberMiddleware: Invalid TypeSupport");
129 log_error(
"FastDDSSubscriberMiddleware: Shared participant unavailable");
136 efd::SubscriberQos subqos = efd::SUBSCRIBER_QOS_DEFAULT;
139 log_error(
"FastDDSSubscriberMiddleware: Failed to create Subscriber");
146 if (
_participant->lookup_topicdescription(topic_name) !=
nullptr) {
149 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
153 log_error(
"FastDDSSubscriberMiddleware: Failed to create Topic");
157 efd::DataReaderQos rqos = efd::DATAREADER_QOS_DEFAULT;
159 if (qos !=
nullptr) {
160 rqos.reliability().kind =
162 ? efd::RELIABLE_RELIABILITY_QOS
163 : efd::BEST_EFFORT_RELIABILITY_QOS;
164 rqos.durability().kind =
166 ? efd::TRANSIENT_LOCAL_DURABILITY_QOS
167 : efd::VOLATILE_DURABILITY_QOS;
168 rqos.history().kind =
170 ? efd::KEEP_LAST_HISTORY_QOS
171 : efd::KEEP_ALL_HISTORY_QOS;
177 auto ud = build_user_data_for<msg_type>();
179 rqos.user_data().data_vec(ud);
182 efd::DataReaderListener* listener =
183 static_cast<efd::DataReaderListener*
>(
this);
186 log_error(
"FastDDSSubscriberMiddleware: Failed to create DataReader");
196 return _alive.load(std::memory_order_relaxed);
static void release_type(const std::string &type_name)
Release one use of type_name.
static eprosima::fastdds::dds::DomainParticipant * acquire()
Increment the refcount and return the shared DomainParticipant.
static void retain_type(const std::string &type_name)
Notify the singleton that one more endpoint is using type_name so that unregister_type() is deferred ...
static void release()
Decrement the refcount.
FastDDS implementation of ISubscriberMiddleware.
typename S::msg_type msg_type
efd::Subscriber * _subscriber
void on_subscription_matched(efd::DataReader *reader, const efd::SubscriptionMatchedStatus &info) override
efd::DomainParticipant * _participant
FastDDSSubscriberMiddleware()=default
FastDDSSubscriberMiddleware(const FastDDSSubscriberMiddleware &)=delete
bool Init(const std::string &topic_name, void *message_ptr, bool *new_message_flag) override
Initialize the underlying middleware entities.
FastDDSSubscriberMiddleware & operator=(const FastDDSSubscriberMiddleware &)=delete
efd::DataReader * _datareader
void on_data_available(efd::DataReader *reader) override
std::atomic< bool > _alive
bool Init(const std::string &topic_name, void *message_ptr, bool *new_message_flag, const QosProfile &qos) override
Initialize with an explicit per-topic QoS profile (see QosProfile.h).
~FastDDSSubscriberMiddleware() override
std::string GetTopicName() const override
bool InitImpl(const std::string &topic_name, void *message_ptr, bool *new_message_flag, const QosProfile *qos)
Shared Init body.
bool IsAlive() const override
Generic FastDDS TopicDataType that serializes carla::ros2::msg::* POD structs directly to CDR via Cdr...
Type-erased abstract interface for a subscriber middleware.
eprosima::fastrtps::types::ReturnCode_t erc
This file contains definitions of common data structures used in traffic manager.
static void log_error(Args &&... args)
Middleware-neutral QoS profile passed to IPublisherMiddleware::Init / ISubscriberMiddleware::Init whe...
std::int32_t history_depth