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/publisher/Publisher.hpp>
17#include <fastdds/dds/publisher/DataWriter.hpp>
18#include <fastdds/dds/publisher/DataWriterListener.hpp>
19#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
20#include <fastdds/dds/core/status/PublicationMatchedStatus.hpp>
21#include <fastdds/dds/topic/qos/TopicQos.hpp>
22#include <fastrtps/attributes/ParticipantAttributes.h>
23#include <fastrtps/qos/QosPolicies.h>
30namespace efd = eprosima::fastdds::dds;
31using erc = eprosima::fastrtps::types::ReturnCode_t;
59 efd::DataWriter* writer,
60 const efd::PublicationMatchedStatus& info)
override {
61 _alive.store(info.current_count > 0, std::memory_order_relaxed);
86 bool Init(
const std::string& topic_name)
override {
87 return InitImpl(topic_name,
nullptr);
99 if (
_type ==
nullptr) {
100 log_error(
"FastDDSPublisherMiddleware: Invalid TypeSupport");
106 log_error(
"FastDDSPublisherMiddleware: Shared participant unavailable");
113 efd::PublisherQos pubqos = efd::PUBLISHER_QOS_DEFAULT;
116 log_error(
"FastDDSPublisherMiddleware: Failed to create Publisher");
125 if (
_participant->lookup_topicdescription(topic_name) !=
nullptr) {
128 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
132 log_error(
"FastDDSPublisherMiddleware: Failed to create Topic");
136 efd::DataWriterQos wqos = efd::DATAWRITER_QOS_DEFAULT;
137 wqos.endpoint().history_memory_policy =
138 eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
151 wqos.publish_mode().kind = efd::ASYNCHRONOUS_PUBLISH_MODE;
153 if (qos !=
nullptr) {
154 wqos.reliability().kind =
156 ? efd::RELIABLE_RELIABILITY_QOS
157 : efd::BEST_EFFORT_RELIABILITY_QOS;
158 wqos.durability().kind =
160 ? efd::TRANSIENT_LOCAL_DURABILITY_QOS
161 : efd::VOLATILE_DURABILITY_QOS;
162 wqos.history().kind =
164 ? efd::KEEP_LAST_HISTORY_QOS
165 : efd::KEEP_ALL_HISTORY_QOS;
173 auto ud = build_user_data_for<msg_type>();
175 wqos.user_data().data_vec(ud);
182 log_error(
"FastDDSPublisherMiddleware: Failed to create DataWriter");
192 eprosima::fastrtps::rtps::InstanceHandle_t instance_handle;
194 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
197 log_error(
"FastDDSPublisherMiddleware::Publish (",
203 return _alive.load(std::memory_order_relaxed);
FastDDS implementation of IPublisherMiddleware.
bool Publish(void *message_data) override
Serialize and write a message to the network.
std::atomic< bool > _alive
bool IsAlive() const override
FastDDSPublisherMiddleware(const FastDDSPublisherMiddleware &)=delete
~FastDDSPublisherMiddleware() override
std::string GetTopicName() const override
FastDDSPublisherMiddleware & operator=(const FastDDSPublisherMiddleware &)=delete
efd::Publisher * _publisher
bool InitImpl(const std::string &topic_name, const QosProfile *qos)
Shared Init body.
void on_publication_matched(efd::DataWriter *writer, const efd::PublicationMatchedStatus &info) override
bool Init(const std::string &topic_name, const QosProfile &qos) override
Initialize with an explicit per-topic QoS profile (see QosProfile.h).
efd::DomainParticipant * _participant
bool Init(const std::string &topic_name) override
Initialize the underlying middleware entities.
efd::DataWriter * _datawriter
typename T::msg_type msg_type
FastDDSPublisherMiddleware()=default
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.
Generic FastDDS TopicDataType that serializes carla::ros2::msg::* POD structs directly to CDR via Cdr...
Type-erased abstract interface for a publisher 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