Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load profiles based on topic names in rmw_fastrtps_dynamic_cpp #497

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions rmw_fastrtps_dynamic_cpp/src/publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include <string>

#include "fastrtps/xmlparser/XMLProfileManager.h"

#include "rcutils/error_handling.h"

#include "rmw/allocators.h"
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down
40 changes: 36 additions & 4 deletions rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -181,15 +188,41 @@ 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;
}

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 =
Expand All @@ -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",
Expand Down
42 changes: 37 additions & 5 deletions rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand All @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions rmw_fastrtps_dynamic_cpp/src/subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
{
Expand Down Expand Up @@ -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) {
Expand Down