From 442f37ca41ac4b108c2cc139b05b16561b32585e Mon Sep 17 00:00:00 2001 From: JuanCarlos Date: Fri, 30 Nov 2018 10:42:07 +0100 Subject: [PATCH] Refs #3555 Apply the changes to the current master on ROS2 --- rmw_fastrtps_cpp/src/rmw_client.cpp | 18 +++++-- rmw_fastrtps_cpp/src/rmw_publisher.cpp | 10 ++-- rmw_fastrtps_cpp/src/rmw_service.cpp | 18 +++++-- rmw_fastrtps_cpp/src/rmw_subscription.cpp | 8 ++- rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp | 18 +++++-- .../src/rmw_publisher.cpp | 10 ++-- rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp | 18 +++++-- .../src/rmw_subscription.cpp | 8 ++- .../custom_participant_info.hpp | 1 + rmw_fastrtps_shared_cpp/src/rmw_node.cpp | 53 +++++++++++++++++-- 10 files changed, 128 insertions(+), 34 deletions(-) diff --git a/rmw_fastrtps_cpp/src/rmw_client.cpp b/rmw_fastrtps_cpp/src/rmw_client.cpp index 171a72cfb..874784c89 100644 --- a/rmw_fastrtps_cpp/src/rmw_client.cpp +++ b/rmw_fastrtps_cpp/src/rmw_client.cpp @@ -120,10 +120,14 @@ rmw_create_client( _register_type(participant, info->response_type_support_); } + 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 = response_type_name; - subscriberParam.historyMemoryPolicy = - eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; if (!qos_policies->avoid_ros_namespace_conventions) { subscriberParam.topic.topicName = std::string(ros_service_response_prefix) + service_name; } else { @@ -131,11 +135,15 @@ rmw_create_client( } subscriberParam.topic.topicName += "Reply"; + if (!impl->leave_middleware_default_qos) + { + publisherParam.qos.m_publishMode.kind = eprosima::fastrtps::ASYNCHRONOUS_PUBLISH_MODE; + publisherParam.historyMemoryPolicy = + eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + } + publisherParam.topic.topicKind = eprosima::fastrtps::rtps::NO_KEY; publisherParam.topic.topicDataType = request_type_name; - publisherParam.qos.m_publishMode.kind = eprosima::fastrtps::ASYNCHRONOUS_PUBLISH_MODE; - publisherParam.historyMemoryPolicy = - eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; if (!qos_policies->avoid_ros_namespace_conventions) { publisherParam.topic.topicName = std::string(ros_service_requester_prefix) + service_name; } else { diff --git a/rmw_fastrtps_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_cpp/src/rmw_publisher.cpp index 5907590fd..5e50cb2bb 100644 --- a/rmw_fastrtps_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_cpp/src/rmw_publisher.cpp @@ -113,9 +113,13 @@ rmw_create_publisher( _register_type(participant, info->type_support_); } - publisherParam.qos.m_publishMode.kind = eprosima::fastrtps::ASYNCHRONOUS_PUBLISH_MODE; - publisherParam.historyMemoryPolicy = - eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + if (!impl->leave_middleware_default_qos) + { + publisherParam.qos.m_publishMode.kind = eprosima::fastrtps::ASYNCHRONOUS_PUBLISH_MODE; + publisherParam.historyMemoryPolicy = + eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + } + publisherParam.topic.topicKind = eprosima::fastrtps::rtps::NO_KEY; publisherParam.topic.topicDataType = type_name; if (!qos_policies->avoid_ros_namespace_conventions) { diff --git a/rmw_fastrtps_cpp/src/rmw_service.cpp b/rmw_fastrtps_cpp/src/rmw_service.cpp index af81304e4..391949cb4 100644 --- a/rmw_fastrtps_cpp/src/rmw_service.cpp +++ b/rmw_fastrtps_cpp/src/rmw_service.cpp @@ -132,9 +132,13 @@ rmw_create_service( _register_type(participant, info->response_type_support_); } + 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.historyMemoryPolicy = - eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; subscriberParam.topic.topicDataType = request_type_name; if (!qos_policies->avoid_ros_namespace_conventions) { subscriberParam.topic.topicName = std::string(ros_service_requester_prefix) + service_name; @@ -143,11 +147,15 @@ rmw_create_service( } subscriberParam.topic.topicName += "Request"; + if (!impl->leave_middleware_default_qos) + { + publisherParam.qos.m_publishMode.kind = eprosima::fastrtps::ASYNCHRONOUS_PUBLISH_MODE; + publisherParam.historyMemoryPolicy = + eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + } + publisherParam.topic.topicKind = eprosima::fastrtps::rtps::NO_KEY; publisherParam.topic.topicDataType = response_type_name; - publisherParam.qos.m_publishMode.kind = eprosima::fastrtps::ASYNCHRONOUS_PUBLISH_MODE; - publisherParam.historyMemoryPolicy = - eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; if (!qos_policies->avoid_ros_namespace_conventions) { publisherParam.topic.topicName = std::string(ros_service_response_prefix) + service_name; } else { diff --git a/rmw_fastrtps_cpp/src/rmw_subscription.cpp b/rmw_fastrtps_cpp/src/rmw_subscription.cpp index 998b859f8..e4dc65699 100644 --- a/rmw_fastrtps_cpp/src/rmw_subscription.cpp +++ b/rmw_fastrtps_cpp/src/rmw_subscription.cpp @@ -116,8 +116,12 @@ rmw_create_subscription( _register_type(participant, info->type_support_); } - subscriberParam.historyMemoryPolicy = - eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + 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 = type_name; if (!qos_policies->avoid_ros_namespace_conventions) { diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp index da3c6cda0..9e0fc2538 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_client.cpp @@ -125,10 +125,14 @@ rmw_create_client( _register_type(participant, info->response_type_support_); } + 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 = response_type_name; - subscriberParam.historyMemoryPolicy = - eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; if (!qos_policies->avoid_ros_namespace_conventions) { subscriberParam.topic.topicName = std::string(ros_service_response_prefix) + service_name; } else { @@ -136,11 +140,15 @@ rmw_create_client( } subscriberParam.topic.topicName += "Reply"; + if (!impl->leave_middleware_default_qos) + { + publisherParam.qos.m_publishMode.kind = eprosima::fastrtps::ASYNCHRONOUS_PUBLISH_MODE; + publisherParam.historyMemoryPolicy = + eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + } + publisherParam.topic.topicKind = eprosima::fastrtps::rtps::NO_KEY; publisherParam.topic.topicDataType = request_type_name; - publisherParam.qos.m_publishMode.kind = eprosima::fastrtps::ASYNCHRONOUS_PUBLISH_MODE; - publisherParam.historyMemoryPolicy = - eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; if (!qos_policies->avoid_ros_namespace_conventions) { publisherParam.topic.topicName = std::string(ros_service_requester_prefix) + service_name; } else { diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp index ae44cfe03..9433ae7c9 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_publisher.cpp @@ -108,9 +108,13 @@ rmw_create_publisher( _register_type(participant, info->type_support_); } - publisherParam.qos.m_publishMode.kind = eprosima::fastrtps::ASYNCHRONOUS_PUBLISH_MODE; - publisherParam.historyMemoryPolicy = - eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + if (!impl->leave_middleware_default_qos) + { + publisherParam.qos.m_publishMode.kind = eprosima::fastrtps::ASYNCHRONOUS_PUBLISH_MODE; + publisherParam.historyMemoryPolicy = + eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + } + publisherParam.topic.topicKind = eprosima::fastrtps::rtps::NO_KEY; publisherParam.topic.topicDataType = type_name; if (!qos_policies->avoid_ros_namespace_conventions) { diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp index 2de1d7645..6c2353b64 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_service.cpp @@ -137,9 +137,13 @@ rmw_create_service( _register_type(participant, info->response_type_support_); } + 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.historyMemoryPolicy = - eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; subscriberParam.topic.topicDataType = request_type_name; if (!qos_policies->avoid_ros_namespace_conventions) { subscriberParam.topic.topicName = std::string(ros_service_requester_prefix) + service_name; @@ -148,11 +152,15 @@ rmw_create_service( } subscriberParam.topic.topicName += "Request"; + if (!impl->leave_middleware_default_qos) + { + publisherParam.qos.m_publishMode.kind = eprosima::fastrtps::ASYNCHRONOUS_PUBLISH_MODE; + publisherParam.historyMemoryPolicy = + eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + } + publisherParam.topic.topicKind = eprosima::fastrtps::rtps::NO_KEY; publisherParam.topic.topicDataType = response_type_name; - publisherParam.qos.m_publishMode.kind = eprosima::fastrtps::ASYNCHRONOUS_PUBLISH_MODE; - publisherParam.historyMemoryPolicy = - eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; if (!qos_policies->avoid_ros_namespace_conventions) { publisherParam.topic.topicName = std::string(ros_service_response_prefix) + service_name; } else { diff --git a/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp b/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp index a421424fe..e1aaa21ee 100644 --- a/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp +++ b/rmw_fastrtps_dynamic_cpp/src/rmw_subscription.cpp @@ -112,8 +112,12 @@ rmw_create_subscription( _register_type(participant, info->type_support_); } - subscriberParam.historyMemoryPolicy = - eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + 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 = type_name; if (!qos_policies->avoid_ros_namespace_conventions) { diff --git a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/custom_participant_info.hpp b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/custom_participant_info.hpp index 4e086435d..20588e57b 100644 --- a/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/custom_participant_info.hpp +++ b/rmw_fastrtps_shared_cpp/include/rmw_fastrtps_shared_cpp/custom_participant_info.hpp @@ -37,6 +37,7 @@ typedef struct CustomParticipantInfo ReaderInfo * secondarySubListener; WriterInfo * secondaryPubListener; rmw_guard_condition_t * graph_guard_condition; + bool leave_middleware_default_qos; } CustomParticipantInfo; class ParticipantListener : public eprosima::fastrtps::ParticipantListener diff --git a/rmw_fastrtps_shared_cpp/src/rmw_node.cpp b/rmw_fastrtps_shared_cpp/src/rmw_node.cpp index c106f5db6..74d9e2f41 100644 --- a/rmw_fastrtps_shared_cpp/src/rmw_node.cpp +++ b/rmw_fastrtps_shared_cpp/src/rmw_node.cpp @@ -104,6 +104,27 @@ create_node( try { node_impl = new CustomParticipantInfo(); + + node_impl->leave_middleware_default_qos = false; + const char * env_var = "RMW_FASTRTPS_LEAVE_MIDDLEWARE_DEFAULT_QOS"; + // Check if the configuration from XML has been enabled from + // the RMW_FASTRTPS_LEAVE_MIDDLEWARE_DEFAULT_QOS env variable. + char * config_env_val = nullptr; +#ifndef _WIN32 + config_env_val = getenv(env_var); + if (config_env_val != nullptr) + { + node_impl->leave_middleware_default_qos = strcmp(config_env_val, "1") == 0; + } +#else + size_t config_env_val_size; + _dupenv_s(&config_env_val, &config_env_val_size, env_var); + if (config_env_val != nullptr) + { + node_impl->leave_middleware_default_qos = strcmp(config_env_val, "1") == 0; + } + free(config_env_val); +#endif } catch (std::bad_alloc &) { RMW_SET_ERROR_MSG("failed to allocate node impl struct"); goto fail; @@ -246,11 +267,35 @@ __rmw_create_node( // since the participant name is not part of the DDS spec participantAttrs.rtps.setName(name); + bool leave_middleware_default_qos = false; + const char * env_var = "RMW_FASTRTPS_LEAVE_MIDDLEWARE_DEFAULT_QOS"; + // Check if the configuration from XML has been enabled from + // the RMW_FASTRTPS_LEAVE_MIDDLEWARE_DEFAULT_QOS env variable. + char * config_env_val = nullptr; +#ifndef _WIN32 + config_env_val = getenv(env_var); + if (config_env_val != nullptr) + { + leave_middleware_default_qos = strcmp(config_env_val, "1") == 0; + } +#else + size_t config_env_val_size; + _dupenv_s(&config_env_val, &config_env_val_size, env_var); + if (config_env_val != nullptr) + { + leave_middleware_default_qos = strcmp(config_env_val, "1") == 0; + } + free(config_env_val); +#endif + // allow reallocation to support discovery messages bigger than 5000 bytes - participantAttrs.rtps.builtin.readerHistoryMemoryPolicy = - eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; - participantAttrs.rtps.builtin.writerHistoryMemoryPolicy = - eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + if (!leave_middleware_default_qos) + { + participantAttrs.rtps.builtin.readerHistoryMemoryPolicy = + eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + participantAttrs.rtps.builtin.writerHistoryMemoryPolicy = + eprosima::fastrtps::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE; + } size_t length = strlen(name) + strlen("name=;") + strlen(namespace_) + strlen("namespace=;") + 1;