1#define _GLIBCXX_USE_CXX11_ABI 0
8#include <fastdds/dds/domain/DomainParticipant.hpp>
9#include <fastdds/dds/publisher/Publisher.hpp>
10#include <fastdds/dds/topic/Topic.hpp>
11#include <fastdds/dds/publisher/DataWriter.hpp>
12#include <fastdds/dds/topic/TypeSupport.hpp>
13#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
14#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
15#include <fastdds/dds/publisher/qos/PublisherQos.hpp>
16#include <fastdds/dds/topic/qos/TopicQos.hpp>
17#include <fastrtps/attributes/ParticipantAttributes.h>
18#include <fastrtps/qos/QosPolicies.h>
19#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
20#include <fastdds/dds/publisher/DataWriterListener.hpp>
27 efd = eprosima::fastdds::dds;
28 using erc = eprosima::fastrtps::types::ReturnCode_t;
44 if (
_impl->_type ==
nullptr) {
45 std::cerr <<
"Invalid TypeSupport" << std::endl;
50 efd::DomainParticipantQos pqos = efd::PARTICIPANT_QOS_DEFAULT;
52 auto factory = efd::DomainParticipantFactory::get_instance();
53 _impl->_participant = factory->create_participant(0, pqos);
54 if (
_impl->_participant ==
nullptr) {
55 std::cerr <<
"Failed to create DomainParticipant" << std::endl;
58 _impl->_type.register_type(
_impl->_participant);
62 efd::PublisherQos pubqos = efd::PUBLISHER_QOS_DEFAULT;
63 _impl->_publisher =
_impl->_participant->create_publisher(pubqos,
nullptr);
64 if (
_impl->_publisher ==
nullptr) {
65 std::cerr <<
"Failed to create Publisher" << std::endl;
71 efd::TopicQos tqos = efd::TOPIC_QOS_DEFAULT;
72 const std::string base {
"rt/carla/" };
73 std::string topic_name = base;
77 _impl->_topic =
_impl->_participant->create_topic(topic_name,
_impl->_type->getName(), tqos);
78 if (
_impl->_topic ==
nullptr) {
79 std::cerr <<
"Failed to create Topic" << std::endl;
85 efd::DataWriterQos wqos = efd::DATAWRITER_QOS_DEFAULT;
86 wqos.endpoint().history_memory_policy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
88 _impl->_datawriter =
_impl->_publisher->create_datawriter(
_impl->_topic, wqos, listener);
89 if (
_impl->_datawriter ==
nullptr) {
90 std::cerr <<
"Failed to create DataWriter" << std::endl;
101 eprosima::fastrtps::rtps::InstanceHandle_t instance_handle;
102 eprosima::fastrtps::types::ReturnCode_t rcode =
_impl->_datawriter->write(&
_impl->_string, instance_handle);
103 if (rcode == erc::ReturnCodeValue::RETCODE_OK) {
109 if (rcode == erc::ReturnCodeValue::RETCODE_ERROR) {
110 std::cerr <<
"RETCODE_ERROR" << std::endl;
113 if (rcode == erc::ReturnCodeValue::RETCODE_UNSUPPORTED) {
114 std::cerr <<
"RETCODE_UNSUPPORTED" << std::endl;
117 if (rcode == erc::ReturnCodeValue::RETCODE_BAD_PARAMETER) {
118 std::cerr <<
"RETCODE_BAD_PARAMETER" << std::endl;
121 if (rcode == erc::ReturnCodeValue::RETCODE_PRECONDITION_NOT_MET) {
122 std::cerr <<
"RETCODE_PRECONDITION_NOT_MET" << std::endl;
125 if (rcode == erc::ReturnCodeValue::RETCODE_OUT_OF_RESOURCES) {
126 std::cerr <<
"RETCODE_OUT_OF_RESOURCES" << std::endl;
129 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ENABLED) {
130 std::cerr <<
"RETCODE_NOT_ENABLED" << std::endl;
133 if (rcode == erc::ReturnCodeValue::RETCODE_IMMUTABLE_POLICY) {
134 std::cerr <<
"RETCODE_IMMUTABLE_POLICY" << std::endl;
137 if (rcode == erc::ReturnCodeValue::RETCODE_INCONSISTENT_POLICY) {
138 std::cerr <<
"RETCODE_INCONSISTENT_POLICY" << std::endl;
141 if (rcode == erc::ReturnCodeValue::RETCODE_ALREADY_DELETED) {
142 std::cerr <<
"RETCODE_ALREADY_DELETED" << std::endl;
145 if (rcode == erc::ReturnCodeValue::RETCODE_TIMEOUT) {
146 std::cerr <<
"RETCODE_TIMEOUT" << std::endl;
149 if (rcode == erc::ReturnCodeValue::RETCODE_NO_DATA) {
150 std::cerr <<
"RETCODE_NO_DATA" << std::endl;
153 if (rcode == erc::ReturnCodeValue::RETCODE_ILLEGAL_OPERATION) {
154 std::cerr <<
"RETCODE_ILLEGAL_OPERATION" << std::endl;
157 if (rcode == erc::ReturnCodeValue::RETCODE_NOT_ALLOWED_BY_SECURITY) {
158 std::cerr <<
"RETCODE_NOT_ALLOWED_BY_SECURITY" << std::endl;
161 std::cerr <<
"UNKNOWN" << std::endl;
168 _impl->_string.data(data);
184 if (
_impl->_datawriter)
185 _impl->_publisher->delete_datawriter(
_impl->_datawriter);
187 if (
_impl->_publisher)
188 _impl->_participant->delete_publisher(
_impl->_publisher);
191 _impl->_participant->delete_topic(
_impl->_topic);
193 if (
_impl->_participant)
194 efd::DomainParticipantFactory::get_instance()->delete_participant(
_impl->_participant);
221 _name = std::move(other._name);
222 _parent = std::move(other._parent);
223 _impl = std::move(other._impl);
230 _name = std::move(other._name);
231 _parent = std::move(other._parent);
232 _impl = std::move(other._impl);
CarlaMapSensorPublisher & operator=(const CarlaMapSensorPublisher &)
void SetData(const char *data)
CarlaMapSensorPublisher(const char *ros_name="", const char *parent="")
std::shared_ptr< CarlaMapSensorPublisherImpl > _impl
~CarlaMapSensorPublisher()
const std::string & parent() const
This class represents the TopicDataType of the type String defined by the user in the IDL file.
这个类表示用户在IDL文件中定义的结构体String。
eprosima::fastrtps::types::ReturnCode_t erc
@using erc
efd::Publisher * _publisher
efd::DomainParticipant * _participant
efd::DataWriter * _datawriter
std_msgs::msg::String _string