diff --git a/rmw_fastrtps_dynamic_cpp/src/publisher.cpp b/rmw_fastrtps_dynamic_cpp/src/publisher.cpp index 74327cad6..f6cfde1a1 100644 --- a/rmw_fastrtps_dynamic_cpp/src/publisher.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/publisher.cpp @@ -15,6 +15,8 @@ #include +#include "fastrtps/xmlparser/XMLProfileManager.h" + #include "rcutils/error_handling.h" #include "rmw/allocators.h" @@ -42,6 +44,7 @@ using Domain = eprosima::fastrtps::Domain; using Participant = eprosima::fastrtps::Participant; using TopicDataType = eprosima::fastrtps::TopicDataType; using TypeSupportProxy = rmw_fastrtps_dynamic_cpp::TypeSupportProxy; +using XMLProfileManager = eprosima::fastrtps::xmlparser::XMLProfileManager; rmw_publisher_t * rmw_fastrtps_dynamic_cpp::create_publisher( @@ -105,12 +108,15 @@ rmw_fastrtps_dynamic_cpp::create_publisher( return nullptr; } - CustomPublisherInfo * info = nullptr; - rmw_publisher_t * rmw_publisher = nullptr; + // If the user defined an XML file via env "FASTRTPS_DEFAULT_PROFILES_FILE", try to load + // publisher which profile name matches with topic_name. If such profile does not exist, + // then use the default attributes. eprosima::fastrtps::PublisherAttributes publisherParam; + Domain::getDefaultPublisherAttributes(publisherParam); // Loads the XML file if not loaded + XMLProfileManager::fillPublisherAttributes(topic_name, publisherParam, false); - // Load default XML profile. - Domain::getDefaultPublisherAttributes(publisherParam); + CustomPublisherInfo * info = nullptr; + rmw_publisher_t * rmw_publisher = nullptr; info = new (std::nothrow) CustomPublisherInfo(); if (!info) { diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp index ed9572504..ebc4412a9 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp @@ -40,11 +40,15 @@ #include "type_support_common.hpp" #include "type_support_registry.hpp" +#include "fastrtps/xmlparser/XMLProfileManager.h" + using BaseTypeSupport = rmw_fastrtps_dynamic_cpp::BaseTypeSupport; using Domain = eprosima::fastrtps::Domain; using Participant = eprosima::fastrtps::Participant; using TopicDataType = eprosima::fastrtps::TopicDataType; using TypeSupportProxy = rmw_fastrtps_dynamic_cpp::TypeSupportProxy; +using XMLProfileManager = eprosima::fastrtps::xmlparser::XMLProfileManager; +using XMLP_ret = eprosima::fastrtps::xmlparser::XMLP_ret; extern "C" { @@ -118,6 +122,9 @@ rmw_create_client( eprosima::fastrtps::SubscriberAttributes subscriberParam; eprosima::fastrtps::PublisherAttributes publisherParam; rmw_client_t * rmw_client = nullptr; + eprosima::fastrtps::fixed_string<255> sub_topic_name; + eprosima::fastrtps::fixed_string<255> pub_topic_name; + std::string topic_name_fallback; info = new CustomClientInfo(); info->participant_ = participant; @@ -181,6 +188,20 @@ rmw_create_client( _register_type(participant, info->response_type_support_); } + // If FASTRTPS_DEFAULT_PROFILES_FILE defined, fill subscriber attributes with a subscriber profile + // located based of topic name defined by _create_topic_name(). If no profile is found, a search + // with profile_name "client" is attempted. Else, use the default attributes. + topic_name_fallback = "client"; + sub_topic_name = _create_topic_name( + qos_policies, ros_service_response_prefix, service_name, "Reply"); + Domain::getDefaultSubscriberAttributes(subscriberParam); + + if (XMLProfileManager::fillSubscriberAttributes( + sub_topic_name.to_string(), subscriberParam, false) != XMLP_ret::XML_OK) + { + XMLProfileManager::fillSubscriberAttributes(topic_name_fallback, subscriberParam, false); + } + if (!participant_info->leave_middleware_default_qos) { subscriberParam.historyMemoryPolicy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; @@ -188,8 +209,20 @@ rmw_create_client( subscriberParam.topic.topicKind = eprosima::fastrtps::rtps::NO_KEY; subscriberParam.topic.topicDataType = response_type_name; - subscriberParam.topic.topicName = _create_topic_name( - qos_policies, ros_service_response_prefix, service_name, "Reply"); + subscriberParam.topic.topicName = sub_topic_name; + + // If FASTRTPS_DEFAULT_PROFILES_FILE defined, fill publisher attributes with a publisher profile + // located based of topic name defined by _create_topic_name(). If no profile is found, a search + // with profile_name "client" is attempted. Else, use the default attributes. + pub_topic_name = _create_topic_name( + qos_policies, ros_service_requester_prefix, service_name, "Request"); + Domain::getDefaultPublisherAttributes(publisherParam); + + if (XMLProfileManager::fillPublisherAttributes( + pub_topic_name.to_string(), publisherParam, false) != XMLP_ret::XML_OK) + { + XMLProfileManager::fillPublisherAttributes(topic_name_fallback, publisherParam, false); + } if (!participant_info->leave_middleware_default_qos) { publisherParam.historyMemoryPolicy = @@ -203,8 +236,7 @@ rmw_create_client( publisherParam.topic.topicKind = eprosima::fastrtps::rtps::NO_KEY; publisherParam.topic.topicDataType = request_type_name; - publisherParam.topic.topicName = _create_topic_name( - qos_policies, ros_service_requester_prefix, service_name, "Request"); + publisherParam.topic.topicName = pub_topic_name; RCUTILS_LOG_DEBUG_NAMED( "rmw_fastrtps_dynamic_cpp", diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp index ff948533b..85ecddbc0 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp @@ -52,11 +52,15 @@ #include "type_support_common.hpp" #include "type_support_registry.hpp" +#include "fastrtps/xmlparser/XMLProfileManager.h" + using BaseTypeSupport = rmw_fastrtps_dynamic_cpp::BaseTypeSupport; using Domain = eprosima::fastrtps::Domain; using Participant = eprosima::fastrtps::Participant; using TopicDataType = eprosima::fastrtps::TopicDataType; using TypeSupportProxy = rmw_fastrtps_dynamic_cpp::TypeSupportProxy; +using XMLProfileManager = eprosima::fastrtps::xmlparser::XMLProfileManager; +using XMLP_ret = eprosima::fastrtps::xmlparser::XMLP_ret; extern "C" { @@ -130,6 +134,10 @@ rmw_create_service( eprosima::fastrtps::SubscriberAttributes subscriberParam; eprosima::fastrtps::PublisherAttributes publisherParam; rmw_service_t * rmw_service = nullptr; + eprosima::fastrtps::fixed_string<255> sub_topic_name; + eprosima::fastrtps::fixed_string<255> pub_topic_name; + std::string topic_name_fallback; + info = new CustomServiceInfo(); info->participant_ = participant; @@ -191,15 +199,40 @@ rmw_create_service( _register_type(participant, info->response_type_support_); } + // If FASTRTPS_DEFAULT_PROFILES_FILE defined, fill subscriber attributes with a subscriber profile + // located based of topic name defined by _create_topic_name(). If no profile is found, a search + // with profile_name "service" is attempted. Else, use the default attributes. + topic_name_fallback = "service"; + sub_topic_name = _create_topic_name( + qos_policies, ros_service_requester_prefix, service_name, "Request"); + Domain::getDefaultSubscriberAttributes(subscriberParam); + + if (XMLProfileManager::fillSubscriberAttributes( + sub_topic_name.to_string(), subscriberParam, false) != XMLP_ret::XML_OK) + { + XMLProfileManager::fillSubscriberAttributes(topic_name_fallback, subscriberParam, false); + } + if (!impl->leave_middleware_default_qos) { subscriberParam.historyMemoryPolicy = eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; } - subscriberParam.topic.topicKind = eprosima::fastrtps::rtps::NO_KEY; subscriberParam.topic.topicDataType = request_type_name; - subscriberParam.topic.topicName = _create_topic_name( - qos_policies, ros_service_requester_prefix, service_name, "Request"); + subscriberParam.topic.topicName = sub_topic_name; + + // If FASTRTPS_DEFAULT_PROFILES_FILE defined, fill publisher attributes with a publisher profile + // located based of topic name defined by _create_topic_name(). If no profile is found, a search + // with profile_name "service" is attempted. Else, use the default attributes. + pub_topic_name = _create_topic_name( + qos_policies, ros_service_response_prefix, service_name, "Reply"); + Domain::getDefaultPublisherAttributes(publisherParam); + + if (XMLProfileManager::fillPublisherAttributes( + pub_topic_name.to_string(), publisherParam, false) != XMLP_ret::XML_OK) + { + XMLProfileManager::fillPublisherAttributes(topic_name_fallback, publisherParam, false); + } if (!impl->leave_middleware_default_qos) { publisherParam.historyMemoryPolicy = @@ -213,8 +246,7 @@ rmw_create_service( publisherParam.topic.topicKind = eprosima::fastrtps::rtps::NO_KEY; publisherParam.topic.topicDataType = response_type_name; - publisherParam.topic.topicName = _create_topic_name( - qos_policies, ros_service_response_prefix, service_name, "Reply"); + publisherParam.topic.topicName = pub_topic_name; RCUTILS_LOG_DEBUG_NAMED( "rmw_fastrtps_dynamic_cpp", diff --git a/rmw_fastrtps_dynamic_cpp/src/subscription.cpp b/rmw_fastrtps_dynamic_cpp/src/subscription.cpp index 1a716294f..156fc6ece 100644 --- a/rmw_fastrtps_dynamic_cpp/src/subscription.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/subscription.cpp @@ -33,6 +33,7 @@ #include "fastrtps/participant/Participant.h" #include "fastrtps/subscriber/Subscriber.h" +#include "fastrtps/xmlparser/XMLProfileManager.h" #include "rmw_fastrtps_dynamic_cpp/identifier.hpp" #include "rmw_fastrtps_dynamic_cpp/subscription.hpp" @@ -45,7 +46,7 @@ using Domain = eprosima::fastrtps::Domain; using Participant = eprosima::fastrtps::Participant; using TopicDataType = eprosima::fastrtps::TopicDataType; using TypeSupportProxy = rmw_fastrtps_dynamic_cpp::TypeSupportProxy; - +using XMLProfileManager = eprosima::fastrtps::xmlparser::XMLProfileManager; namespace rmw_fastrtps_dynamic_cpp { @@ -111,9 +112,12 @@ create_subscription( return nullptr; } - // Load default XML profile. + // If the user defined an XML file via env "FASTRTPS_DEFAULT_PROFILES_FILE", try to load + // subscriber which profile name matches with topic_name. If such profile does not exist, then use + // the default attributes. eprosima::fastrtps::SubscriberAttributes subscriberParam; - Domain::getDefaultSubscriberAttributes(subscriberParam); + Domain::getDefaultSubscriberAttributes(subscriberParam); // Loads the XML file if not loaded + XMLProfileManager::fillSubscriberAttributes(topic_name, subscriberParam, false); CustomSubscriberInfo * info = new (std::nothrow) CustomSubscriberInfo(); if (!info) {