Skip to content

Commit

Permalink
Use FASTRTPS_DEFAULT_PROFILES_FILE environment var to load profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
EduPonz committed Nov 25, 2019
1 parent 4675d06 commit 8c4c65a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 65 deletions.
35 changes: 15 additions & 20 deletions rmw_fastrtps_cpp/src/rmw_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,36 +89,31 @@ rmw_create_client(
}
}

// If FASTRTPS_DEFAULT_PROFILES_FILE defined, fill subscriber attributes with a subscriber
// profile 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.
// If the user defined an XML file via env "FASTRTPS_DEFAULT_PROFILES_FILE", 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.
std::string topic_name_fallback = "client";
eprosima::fastrtps::SubscriberAttributes subscriberParam;
eprosima::fastrtps::fixed_string<255> sub_topic_name = _create_topic_name(
qos_policies, ros_service_response_prefix, service_name, "Reply");
Domain::getDefaultSubscriberAttributes(subscriberParam);
if (std::getenv("FASTRTPS_DEFAULT_PROFILES_FILE") != nullptr) {
if (XMLProfileManager::fillSubscriberAttributes(sub_topic_name.to_string(),
subscriberParam, false) != XMLP_ret::XML_OK)
{
XMLProfileManager::fillSubscriberAttributes(topic_name_fallback, subscriberParam, false);
}
Domain::getDefaultSubscriberAttributes(subscriberParam); // Loads the XML file if not loaded
if (XMLProfileManager::fillSubscriberAttributes(sub_topic_name.to_string(),
subscriberParam, false) != XMLP_ret::XML_OK)
{
XMLProfileManager::fillSubscriberAttributes(topic_name_fallback, subscriberParam, false);
}

// If FASTRTPS_DEFAULT_PROFILES_FILE defined, fill publisher attributes with a publisher profile
// 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.
// If the user defined an XML file via env "FASTRTPS_DEFAULT_PROFILES_FILE", 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.
eprosima::fastrtps::fixed_string<255> pub_topic_name = _create_topic_name(
qos_policies, ros_service_requester_prefix, service_name, "Request");
eprosima::fastrtps::PublisherAttributes publisherParam;
Domain::getDefaultPublisherAttributes(publisherParam);
if (std::getenv("FASTRTPS_DEFAULT_PROFILES_FILE") != nullptr) {
if (XMLProfileManager::fillPublisherAttributes(pub_topic_name.to_string(),
publisherParam, false) != XMLP_ret::XML_OK)
{
XMLProfileManager::fillPublisherAttributes(topic_name_fallback, publisherParam, false);
}
if (XMLProfileManager::fillPublisherAttributes(pub_topic_name.to_string(),
publisherParam, false) != XMLP_ret::XML_OK)
{
XMLProfileManager::fillPublisherAttributes(topic_name_fallback, publisherParam, false);
}

CustomClientInfo * info = nullptr;
Expand Down
11 changes: 4 additions & 7 deletions rmw_fastrtps_cpp/src/rmw_publisher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,11 @@ rmw_create_publisher(
return nullptr;
}

// If the user exported FASTRTPS_DEFAULT_PROFILES_FILE, try to load publisher which profile name
// matches with topic_name. If such profile does not exist, or FASTRTPS_DEFAULT_PROFILES_FILE is
// not defined, then use the default attributes.
// 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);
if (std::getenv("FASTRTPS_DEFAULT_PROFILES_FILE") != nullptr) {
XMLProfileManager::fillPublisherAttributes(topic_name, publisherParam, false);
}
Domain::getDefaultPublisherAttributes(publisherParam); // Loads the XML file if not loaded
XMLProfileManager::fillPublisherAttributes(topic_name, publisherParam, false);

// TODO(karsten1987) Verify consequences for std::unique_ptr?
info = new (std::nothrow) CustomPublisherInfo();
Expand Down
36 changes: 17 additions & 19 deletions rmw_fastrtps_cpp/src/rmw_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,34 +101,32 @@ rmw_create_service(
}
}

// If FASTRTPS_DEFAULT_PROFILES_FILE defined, fill subscriber attributes with a subscriber
// profile 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.

// If the user defined an XML file via env "FASTRTPS_DEFAULT_PROFILES_FILE", 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.
std::string topic_name_fallback = "service";
eprosima::fastrtps::SubscriberAttributes subscriberParam;
eprosima::fastrtps::fixed_string<255> sub_topic_name = _create_topic_name(
qos_policies, ros_service_requester_prefix, service_name, "Request");
Domain::getDefaultSubscriberAttributes(subscriberParam);
if (std::getenv("FASTRTPS_DEFAULT_PROFILES_FILE") != nullptr) {
if (XMLProfileManager::fillSubscriberAttributes(sub_topic_name.to_string(),
subscriberParam, false) != XMLP_ret::XML_OK)
{
XMLProfileManager::fillSubscriberAttributes(topic_name_fallback, subscriberParam, false);
}
Domain::getDefaultSubscriberAttributes(subscriberParam); // Loads the XML file if not loaded
if (XMLProfileManager::fillSubscriberAttributes(sub_topic_name.to_string(),
subscriberParam, false) != XMLP_ret::XML_OK)
{
XMLProfileManager::fillSubscriberAttributes(topic_name_fallback, subscriberParam, false);
}
// If FASTRTPS_DEFAULT_PROFILES_FILE defined, fill publisher attributes with a publisher profile
// 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.

// If the user defined an XML file via env "FASTRTPS_DEFAULT_PROFILES_FILE", 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.
eprosima::fastrtps::fixed_string<255> pub_topic_name = _create_topic_name(
qos_policies, ros_service_response_prefix, service_name, "Reply");
eprosima::fastrtps::PublisherAttributes publisherParam;
Domain::getDefaultPublisherAttributes(publisherParam);
if (std::getenv("FASTRTPS_DEFAULT_PROFILES_FILE") != nullptr) {
if (XMLProfileManager::fillPublisherAttributes(pub_topic_name.to_string(),
publisherParam, false) != XMLP_ret::XML_OK)
{
XMLProfileManager::fillPublisherAttributes(topic_name_fallback, publisherParam, false);
}
if (XMLProfileManager::fillPublisherAttributes(pub_topic_name.to_string(),
publisherParam, false) != XMLP_ret::XML_OK)
{
XMLProfileManager::fillPublisherAttributes(topic_name_fallback, publisherParam, false);
}

CustomServiceInfo * info = nullptr;
Expand Down
15 changes: 4 additions & 11 deletions rmw_fastrtps_cpp/src/rmw_subscription.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,11 @@ rmw_create_subscription(
CustomSubscriberInfo * info = nullptr;
rmw_subscription_t * rmw_subscription = nullptr;

// // Load default XML profile.
// Domain::getDefaultSubscriberAttributes(subscriberParam);

// If the user exported FASTRTPS_DEFAULT_PROFILES_FILE, try to load subscriber which profile
// name matches with topic_name. If such profile does not exist, or
// FASTRTPS_DEFAULT_PROFILES_FILE is not defined, then use the default attributes.
// 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);
if (std::getenv("FASTRTPS_DEFAULT_PROFILES_FILE") != nullptr) {
XMLProfileManager::fillSubscriberAttributes(topic_name, subscriberParam, false);
}

Domain::getDefaultSubscriberAttributes(subscriberParam); // Loads the XML file if not loaded
XMLProfileManager::fillSubscriberAttributes(topic_name, subscriberParam, false);

info = new (std::nothrow) CustomSubscriberInfo();
if (!info) {
Expand Down
12 changes: 4 additions & 8 deletions rmw_fastrtps_shared_cpp/src/rmw_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,11 @@ __rmw_create_node(
return nullptr;
}


// If the user exported FASTRTPS_DEFAULT_PROFILES_FILE, try to load participant attributes using
// node name as profile_name. If such profile does not exist, or FASTRTPS_DEFAULT_PROFILES_FILE
// is not defined, then use the default attributes.
// If the user defined an XML file via env "FASTRTPS_DEFAULT_PROFILES_FILE", try to load participant attributes using
// node name as profile_name. If such profile does not exist, then use the default attributes.
ParticipantAttributes participantAttrs;
Domain::getDefaultParticipantAttributes(participantAttrs);
if (std::getenv("FASTRTPS_DEFAULT_PROFILES_FILE") != nullptr) {
XMLProfileManager::fillParticipantAttributes(name, participantAttrs, false);
}
Domain::getDefaultParticipantAttributes(participantAttrs); // Loads the XML file if not loaded
XMLProfileManager::fillParticipantAttributes(name, participantAttrs, false);

participantAttrs.rtps.builtin.domainId = static_cast<uint32_t>(domain_id);
// since the participant name is not part of the DDS spec
Expand Down

0 comments on commit 8c4c65a

Please sign in to comment.