From 717009a9ffa6baeff98f925e8cbd45eb9bfc992a Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Fri, 27 Nov 2020 16:43:52 +0800 Subject: [PATCH 01/14] To support a feature of content filtered topic Signed-off-by: Chen Lihui --- rmw/include/rmw/rmw.h | 71 ++++++++++++++++++++++++++++++++++ rmw/include/rmw/types.h | 7 ++++ rmw/src/subscription_options.c | 2 + 3 files changed, 80 insertions(+) diff --git a/rmw/include/rmw/rmw.h b/rmw/include/rmw/rmw.h index c98011e5..01852a14 100644 --- a/rmw/include/rmw/rmw.h +++ b/rmw/include/rmw/rmw.h @@ -1117,6 +1117,77 @@ rmw_subscription_get_actual_qos( const rmw_subscription_t * subscription, rmw_qos_profile_t * qos); +/// Set the filter expression and expression parameters for the subscription. +/** + * This function will set a filter expression and an array of expression parameters + * for the given subscription, but not to update the original rmw_subscription_options_t + * of subscription. + * + *
+ * Attribute | Adherence + * ------------------ | ------------- + * Allocates Memory | No + * Thread-Safe | No + * Uses Atomics | Maybe [1] + * Lock-Free | Maybe [1] + * [1] implementation defined, check the implementation documentation + * + * \param[in] subscription subscription the subscription object to inspect. + * \param[in] filter_expression An filter expression to set. + * \param[in] expression_parameters Array of expression parameters to set, + * it can be NULL if there is no placeholder in filter_expression. + * \return `RMW_RET_OK` if the query was successful, or + * \return `RMW_RET_INVALID_ARGUMENT` if `subscription` is NULL, or + * \return `RMW_RET_INVALID_ARGUMENT` if `filter_expression` is NULL, or + * \return `RMW_RET_INVALID_ARGUMENT` if `expression_parameters` is NULL, or + * \return `RMW_RET_INCORRECT_RMW_IMPLEMENTATION` if the `node` implementation + * identifier does not match this implementation, or + * \return `RMW_RET_ERROR` if an unspecified error occurs. + */ +RMW_PUBLIC +RMW_WARN_UNUSED +rmw_ret_t +rmw_subscription_set_cft_expression_parameters( + const rmw_subscription_t * subscription, + const char * filter_expression, + const rcutils_string_array_t * expression_parameters); + +/// Retrieve the filter expression of the subscription. +/** + * This function will return an filter expression by the given subscription. + * + *
+ * Attribute | Adherence + * ------------------ | ------------- + * Allocates Memory | Yes + * Thread-Safe | No + * Uses Atomics | Maybe [1] + * Lock-Free | Maybe [1] + * [1] implementation defined, check the implementation documentation + * + * \param[in] subscription subscription the subscription object to inspect. + * \param[out] filter_expression an filter expression, populated on success. + * It is up to the caller to deallocate the filter expression later on, + * using rcutils_get_default_allocator().deallocate(). + * \param[out] expression_parameters Array of expression parameters, populated on success. + * It is up to the caller to finalize this array later on, using rcutils_string_array_fini(). + * \return `RMW_RET_OK` if the query was successful, or + * \return `RMW_RET_INVALID_ARGUMENT` if `subscription` is NULL, or + * \return `RMW_RET_INVALID_ARGUMENT` if `filter_expression` is NULL or + * \return `RMW_RET_INVALID_ARGUMENT` if `expression_parameters` is NULL, or + * \return `RMW_RET_INCORRECT_RMW_IMPLEMENTATION` if the `node` implementation + * identifier does not match this implementation, or + * \return `RMW_RET_BAD_ALLOC` if memory allocation fails, or + * \return `RMW_RET_ERROR` if an unspecified error occurs. + */ +RMW_PUBLIC +RMW_WARN_UNUSED +rmw_ret_t +rmw_subscription_get_cft_expression_parameters( + const rmw_subscription_t * subscription, + char ** filter_expression, + rcutils_string_array_t * expression_parameters); + /// Take an incoming ROS message. /** * Take a ROS message already received by the given subscription, removing it from internal queues. diff --git a/rmw/include/rmw/types.h b/rmw/include/rmw/types.h index 0ba286f7..94f3c97f 100644 --- a/rmw/include/rmw/types.h +++ b/rmw/include/rmw/types.h @@ -177,6 +177,10 @@ typedef struct RMW_PUBLIC_TYPE rmw_subscription_options_s * Default value is RMW_UNIQUE_NETWORK_FLOW_ENDPOINTS_NOT_REQUIRED. */ rmw_unique_network_flow_endpoints_requirement_t require_unique_network_flow_endpoints; + + /// Used to create a content filtered topic during subscription creation. + char * filter_expression; + rcutils_string_array_t * expression_parameters; } rmw_subscription_options_t; typedef struct RMW_PUBLIC_TYPE rmw_subscription_s @@ -203,6 +207,9 @@ typedef struct RMW_PUBLIC_TYPE rmw_subscription_s /// Indicates whether this subscription can loan messages bool can_loan_messages; + + /// Indicates whether this subscription can set content filtered expression + bool is_cft_supported; } rmw_subscription_t; /// A handle to an rmw service diff --git a/rmw/src/subscription_options.c b/rmw/src/subscription_options.c index a968ccda..baf050a5 100644 --- a/rmw/src/subscription_options.c +++ b/rmw/src/subscription_options.c @@ -26,6 +26,8 @@ rmw_get_default_subscription_options(void) .rmw_specific_subscription_payload = NULL, .ignore_local_publications = false, .require_unique_network_flow_endpoints = RMW_UNIQUE_NETWORK_FLOW_ENDPOINTS_NOT_REQUIRED, + .filter_expression = NULL, + .expression_parameters = NULL, }; return subscription_options; } From c9cecb8b387b1fd1ea54cfaaff71cc6ecfa3465c Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Thu, 3 Dec 2020 15:57:16 +0800 Subject: [PATCH 02/14] Update function description Signed-off-by: Chen Lihui --- rmw/include/rmw/rmw.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rmw/include/rmw/rmw.h b/rmw/include/rmw/rmw.h index 01852a14..23bdb82a 100644 --- a/rmw/include/rmw/rmw.h +++ b/rmw/include/rmw/rmw.h @@ -1132,7 +1132,7 @@ rmw_subscription_get_actual_qos( * Lock-Free | Maybe [1] * [1] implementation defined, check the implementation documentation * - * \param[in] subscription subscription the subscription object to inspect. + * \param[in] subscription the subscription object to inspect. * \param[in] filter_expression An filter expression to set. * \param[in] expression_parameters Array of expression parameters to set, * it can be NULL if there is no placeholder in filter_expression. @@ -1165,7 +1165,7 @@ rmw_subscription_set_cft_expression_parameters( * Lock-Free | Maybe [1] * [1] implementation defined, check the implementation documentation * - * \param[in] subscription subscription the subscription object to inspect. + * \param[in] subscription the subscription object to inspect. * \param[out] filter_expression an filter expression, populated on success. * It is up to the caller to deallocate the filter expression later on, * using rcutils_get_default_allocator().deallocate(). From 59217b0b85815b54c6ea568a2f0d5122ad76708b Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Tue, 2 Feb 2021 13:28:25 +0800 Subject: [PATCH 03/14] Update based on review Signed-off-by: Chen Lihui --- rmw/include/rmw/rmw.h | 2 ++ rmw/include/rmw/types.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/rmw/include/rmw/rmw.h b/rmw/include/rmw/rmw.h index 23bdb82a..7493c00e 100644 --- a/rmw/include/rmw/rmw.h +++ b/rmw/include/rmw/rmw.h @@ -1142,6 +1142,7 @@ rmw_subscription_get_actual_qos( * \return `RMW_RET_INVALID_ARGUMENT` if `expression_parameters` is NULL, or * \return `RMW_RET_INCORRECT_RMW_IMPLEMENTATION` if the `node` implementation * identifier does not match this implementation, or + * \return `RMW_RET_UNSUPPORTED` if the implementation does not support content filter topic, or * \return `RMW_RET_ERROR` if an unspecified error occurs. */ RMW_PUBLIC @@ -1178,6 +1179,7 @@ rmw_subscription_set_cft_expression_parameters( * \return `RMW_RET_INCORRECT_RMW_IMPLEMENTATION` if the `node` implementation * identifier does not match this implementation, or * \return `RMW_RET_BAD_ALLOC` if memory allocation fails, or + * \return `RMW_RET_UNSUPPORTED` if the implementation does not support content filter topic, or * \return `RMW_RET_ERROR` if an unspecified error occurs. */ RMW_PUBLIC diff --git a/rmw/include/rmw/types.h b/rmw/include/rmw/types.h index 94f3c97f..42a22c1d 100644 --- a/rmw/include/rmw/types.h +++ b/rmw/include/rmw/types.h @@ -208,7 +208,7 @@ typedef struct RMW_PUBLIC_TYPE rmw_subscription_s /// Indicates whether this subscription can loan messages bool can_loan_messages; - /// Indicates whether this subscription can set content filtered expression + /// Indicates whether this subscription can support content filtered topic bool is_cft_supported; } rmw_subscription_t; From 4020fdf508d8f602f7aa2d7b2c48ac403c25bf09 Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Fri, 5 Feb 2021 13:06:42 +0800 Subject: [PATCH 04/14] update test for subscription option Signed-off-by: Chen Lihui --- rmw/test/test_subscription_options.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rmw/test/test_subscription_options.cpp b/rmw/test/test_subscription_options.cpp index 78990c12..d7999688 100644 --- a/rmw/test/test_subscription_options.cpp +++ b/rmw/test/test_subscription_options.cpp @@ -24,4 +24,6 @@ TEST(rmw_subscription_options, get_default_subscription_options) EXPECT_EQ( options.require_unique_network_flow_endpoints, RMW_UNIQUE_NETWORK_FLOW_ENDPOINTS_NOT_REQUIRED); + EXPECT_EQ(options.filter_expression, nullptr); + EXPECT_EQ(options.expression_parameters, nullptr); } From 542e05e536ef7b8841924dc414b73c464db2f3f8 Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Fri, 12 Mar 2021 12:52:44 +0800 Subject: [PATCH 05/14] to support reset content filtered topic with empty string. remove constness for rmw_subscription because is_cft_supported might be updated Signed-off-by: Chen Lihui --- rmw/include/rmw/rmw.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rmw/include/rmw/rmw.h b/rmw/include/rmw/rmw.h index 7493c00e..b0c4ec2e 100644 --- a/rmw/include/rmw/rmw.h +++ b/rmw/include/rmw/rmw.h @@ -1133,9 +1133,15 @@ rmw_subscription_get_actual_qos( * [1] implementation defined, check the implementation documentation * * \param[in] subscription the subscription object to inspect. - * \param[in] filter_expression An filter expression to set. - * \param[in] expression_parameters Array of expression parameters to set, - * it can be NULL if there is no placeholder in filter_expression. + * \param[in] filter_expression A filter_expression is a string that specifies the criteria + * to select the data samples of interest. It is similar to the WHERE part of an SQL clause. + * Using an empty("") string can reset/clean content filtered topic for the subscription. + * \param[in] expression_parameters An expression_parameters is an array of strings that + * give values to the ‘parameters’ (i.e., "%n" tokens begin from 0) in the filter_expression. + * The number of supplied parameters must fit with the requested values in the filter_expression. + * It can be NULL if there is no "%n" tokens placeholder in filter_expression. + * The maximun size allowance depends on concrete DDS vendor. + * (i.e., it cannot be greater than 100 on RTI_Connext.) * \return `RMW_RET_OK` if the query was successful, or * \return `RMW_RET_INVALID_ARGUMENT` if `subscription` is NULL, or * \return `RMW_RET_INVALID_ARGUMENT` if `filter_expression` is NULL, or @@ -1149,7 +1155,7 @@ RMW_PUBLIC RMW_WARN_UNUSED rmw_ret_t rmw_subscription_set_cft_expression_parameters( - const rmw_subscription_t * subscription, + rmw_subscription_t * subscription, const char * filter_expression, const rcutils_string_array_t * expression_parameters); From 6bb8e3c709547850649477da3f1931ac01c11eca Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Tue, 12 Oct 2021 09:54:01 +0800 Subject: [PATCH 06/14] Update the argument type of interface declaration Signed-off-by: Chen Lihui --- rmw/CMakeLists.txt | 1 + rmw/include/rmw/rmw.h | 60 ++--- ...scription_content_filtered_topic_options.h | 130 ++++++++++ rmw/include/rmw/types.h | 8 +- ...scription_content_filtered_topic_options.c | 181 +++++++++++++ rmw/src/subscription_options.c | 3 +- rmw/test/CMakeLists.txt | 9 + ...ription_content_filtered_topic_options.cpp | 237 ++++++++++++++++++ rmw/test/test_subscription_options.cpp | 3 +- 9 files changed, 587 insertions(+), 45 deletions(-) create mode 100644 rmw/include/rmw/subscription_content_filtered_topic_options.h create mode 100644 rmw/src/subscription_content_filtered_topic_options.c create mode 100644 rmw/test/test_subscription_content_filtered_topic_options.cpp diff --git a/rmw/CMakeLists.txt b/rmw/CMakeLists.txt index 261b8f4e..2b67fe9d 100644 --- a/rmw/CMakeLists.txt +++ b/rmw/CMakeLists.txt @@ -37,6 +37,7 @@ set(rmw_sources "src/qos_string_conversions.c" "src/sanity_checks.c" "src/security_options.c" + "src/subscription_content_filtered_topic_options.c" "src/subscription_options.c" "src/time.c" "src/topic_endpoint_info_array.c" diff --git a/rmw/include/rmw/rmw.h b/rmw/include/rmw/rmw.h index b0c4ec2e..051bdfbc 100644 --- a/rmw/include/rmw/rmw.h +++ b/rmw/include/rmw/rmw.h @@ -91,6 +91,7 @@ extern "C" #include #include +#include "rcutils/allocator.h" #include "rcutils/macros.h" #include "rcutils/types.h" @@ -1117,11 +1118,10 @@ rmw_subscription_get_actual_qos( const rmw_subscription_t * subscription, rmw_qos_profile_t * qos); -/// Set the filter expression and expression parameters for the subscription. +/// Set the content filtered topic options for the subscription. /** * This function will set a filter expression and an array of expression parameters - * for the given subscription, but not to update the original rmw_subscription_options_t - * of subscription. + * for the given subscription. * *
* Attribute | Adherence @@ -1132,23 +1132,15 @@ rmw_subscription_get_actual_qos( * Lock-Free | Maybe [1] * [1] implementation defined, check the implementation documentation * - * \param[in] subscription the subscription object to inspect. - * \param[in] filter_expression A filter_expression is a string that specifies the criteria - * to select the data samples of interest. It is similar to the WHERE part of an SQL clause. - * Using an empty("") string can reset/clean content filtered topic for the subscription. - * \param[in] expression_parameters An expression_parameters is an array of strings that - * give values to the ‘parameters’ (i.e., "%n" tokens begin from 0) in the filter_expression. - * The number of supplied parameters must fit with the requested values in the filter_expression. - * It can be NULL if there is no "%n" tokens placeholder in filter_expression. - * The maximun size allowance depends on concrete DDS vendor. - * (i.e., it cannot be greater than 100 on RTI_Connext.) - * \return `RMW_RET_OK` if the query was successful, or - * \return `RMW_RET_INVALID_ARGUMENT` if `subscription` is NULL, or - * \return `RMW_RET_INVALID_ARGUMENT` if `filter_expression` is NULL, or - * \return `RMW_RET_INVALID_ARGUMENT` if `expression_parameters` is NULL, or - * \return `RMW_RET_INCORRECT_RMW_IMPLEMENTATION` if the `node` implementation + * \param[in] subscription The subscription to set content filtered topic options. + * \param[in] options The content filtered topic options. + * Use `options.filter_expression` with an empty("") string to + * reset/clean content filtered topic for the subscription. + * \return `RMW_RET_OK` if successful, or + * \return `RMW_RET_INVALID_ARGUMENT` if an argument is null, or + * \return `RMW_RET_INCORRECT_RMW_IMPLEMENTATION` if the `subscription` implementation * identifier does not match this implementation, or - * \return `RMW_RET_UNSUPPORTED` if the implementation does not support content filter topic, or + * \return `RMW_RET_UNSUPPORTED` if the implementation does not support content filtered topic, or * \return `RMW_RET_ERROR` if an unspecified error occurs. */ RMW_PUBLIC @@ -1156,12 +1148,11 @@ RMW_WARN_UNUSED rmw_ret_t rmw_subscription_set_cft_expression_parameters( rmw_subscription_t * subscription, - const char * filter_expression, - const rcutils_string_array_t * expression_parameters); + const rmw_subscription_content_filtered_topic_options_t * options); -/// Retrieve the filter expression of the subscription. +/// Retrieve the content filtered topic options of the subscription. /** - * This function will return an filter expression by the given subscription. + * This function will return a content filtered topic options by the given subscription. * *
* Attribute | Adherence @@ -1172,20 +1163,15 @@ rmw_subscription_set_cft_expression_parameters( * Lock-Free | Maybe [1] * [1] implementation defined, check the implementation documentation * - * \param[in] subscription the subscription object to inspect. - * \param[out] filter_expression an filter expression, populated on success. - * It is up to the caller to deallocate the filter expression later on, - * using rcutils_get_default_allocator().deallocate(). - * \param[out] expression_parameters Array of expression parameters, populated on success. - * It is up to the caller to finalize this array later on, using rcutils_string_array_fini(). - * \return `RMW_RET_OK` if the query was successful, or - * \return `RMW_RET_INVALID_ARGUMENT` if `subscription` is NULL, or - * \return `RMW_RET_INVALID_ARGUMENT` if `filter_expression` is NULL or - * \return `RMW_RET_INVALID_ARGUMENT` if `expression_parameters` is NULL, or - * \return `RMW_RET_INCORRECT_RMW_IMPLEMENTATION` if the `node` implementation + * \param[in] subscription The subscription object to inspect. + * \param[in] allocator Allocator to be used when populating the content filtered topic options. + * \param[out] options The content filtered topic options. + * \return `RMW_RET_OK` if successful, or + * \return `RMW_RET_INVALID_ARGUMENT` if an argument is null, or + * \return `RMW_RET_INCORRECT_RMW_IMPLEMENTATION` if the `subscription` implementation * identifier does not match this implementation, or * \return `RMW_RET_BAD_ALLOC` if memory allocation fails, or - * \return `RMW_RET_UNSUPPORTED` if the implementation does not support content filter topic, or + * \return `RMW_RET_UNSUPPORTED` if the implementation does not support content filtered topic, or * \return `RMW_RET_ERROR` if an unspecified error occurs. */ RMW_PUBLIC @@ -1193,8 +1179,8 @@ RMW_WARN_UNUSED rmw_ret_t rmw_subscription_get_cft_expression_parameters( const rmw_subscription_t * subscription, - char ** filter_expression, - rcutils_string_array_t * expression_parameters); + rcutils_allocator_t * allocator, + rmw_subscription_content_filtered_topic_options_t * options); /// Take an incoming ROS message. /** diff --git a/rmw/include/rmw/subscription_content_filtered_topic_options.h b/rmw/include/rmw/subscription_content_filtered_topic_options.h new file mode 100644 index 00000000..1528b926 --- /dev/null +++ b/rmw/include/rmw/subscription_content_filtered_topic_options.h @@ -0,0 +1,130 @@ +// Copyright 2021 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef RMW__SUBSCRIPTION_CONTENT_FILTERED_TOPIC_OPTIONS_H_ +#define RMW__SUBSCRIPTION_CONTENT_FILTERED_TOPIC_OPTIONS_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "rcutils/allocator.h" +#include "rcutils/types.h" +#include "rmw/macros.h" +#include "rmw/ret_types.h" +#include "rmw/visibility_control.h" + +typedef struct RMW_PUBLIC_TYPE rmw_subscription_content_filtered_topic_options_s +{ + /** + * specify the criteria to select the data samples of interest. + * + * It is similar to the WHERE part of an SQL clause. + */ + char * filter_expression; + /** + * give values to the tokens placeholder ‘parameters’ (i.e., "%n" tokens begin from 0) in the + * filter_expression. The number of supplied parameters must fit with the requested values. + * + * It can be NULL if there is no "%n" tokens placeholder in filter_expression. + * The maximun size allowance depends on concrete DDS vendor. + * (i.e., it cannot be greater than 100 on RTI_Connext.) + */ + rcutils_string_array_t * expression_parameters; +} rmw_subscription_content_filtered_topic_options_t; + + +/// Get zero initialized content filtered topic options. +RMW_PUBLIC +rmw_subscription_content_filtered_topic_options_t +rmw_get_zero_initialized_content_filtered_topic_options(); + + +/// Initialize the given content filtered topic options. +/** + * \param[in] filter_expression The filter expression. + * \param[in] expression_parameters_argc The expression parameters argc. + * \param[in] expression_parameter_argv The expression parameters argv. + * \param[in] allocator The allocator used when copying data to the content filtered topic options. + * \param[out] options The content filtered topic options to be set. + * \returns RMW_RET_INVALID_ARGUMENT, or + * \returns RMW_RET_BAD_ALLOC, or + * \returns RMW_RET_OK + */ +RMW_PUBLIC +rmw_ret_t +rmw_subscription_content_filtered_topic_options_init( + const char * filter_expression, + size_t expression_parameters_argc, + const char * expression_parameter_argv[], + const rcutils_allocator_t * allocator, + rmw_subscription_content_filtered_topic_options_t * options); + +/// Set the given content filtered topic options. +/** + * \param[in] filter_expression The filter expression. + * \param[in] expression_parameters_argc The expression parameters argc. + * \param[in] expression_parameter_argv The expression parameters argv. + * \param[in] allocator The allocator used when copying data to the content filtered topic options. + * \param[out] options The content filtered topic options to be set. + * \returns RMW_RET_INVALID_ARGUMENT, or + * \returns RMW_RET_BAD_ALLOC, or + * \returns RMW_RET_OK + */ +RMW_PUBLIC +rmw_ret_t +rmw_subscription_content_filtered_topic_options_set( + const char * filter_expression, + size_t expression_parameters_argc, + const char * expression_parameter_argv[], + const rcutils_allocator_t * allocator, + rmw_subscription_content_filtered_topic_options_t * options); + +/// Copy the given content filtered topic options. +/** + * \param[in] src content filtered topic options to be copied. + * \param[in] allocator allocator used when copying data to the new content filtered topic options. + * \param[out] dst content filtered topic options to be set. + * \returns RMW_RET_INVALID_ARGUMENT, or + * \returns RMW_RET_BAD_ALLOC, or + * \returns RMW_RET_OK + */ +RMW_PUBLIC +rmw_ret_t +rmw_subscription_content_filtered_topic_options_copy( + const rmw_subscription_content_filtered_topic_options_t * src, + const rcutils_allocator_t * allocator, + rmw_subscription_content_filtered_topic_options_t * dst); + + +/// Finalize the content filtered topic options. +/** + * \param[in] options content filtered topic options to be finalized. + * \param[in] allocator allocator used to deallocate the content filtered topic options. + * \returns RMW_RET_INVALID_ARGUMENT, or + * \returns RMW_RET_ERROR, or + * \returns RMW_RET_OK + */ +RMW_PUBLIC +rmw_ret_t +rmw_subscription_content_filtered_topic_options_fini( + rmw_subscription_content_filtered_topic_options_t * options, + const rcutils_allocator_t * allocator); + +#ifdef __cplusplus +} +#endif + +#endif // RMW__SUBSCRIPTION_CONTENT_FILTERED_TOPIC_OPTIONS_H_ diff --git a/rmw/include/rmw/types.h b/rmw/include/rmw/types.h index 42a22c1d..b56a6598 100644 --- a/rmw/include/rmw/types.h +++ b/rmw/include/rmw/types.h @@ -33,6 +33,7 @@ extern "C" #include "rmw/ret_types.h" #include "rmw/security_options.h" #include "rmw/serialized_message.h" +#include "rmw/subscription_content_filtered_topic_options.h" #include "rmw/time.h" #include "rmw/visibility_control.h" @@ -179,8 +180,7 @@ typedef struct RMW_PUBLIC_TYPE rmw_subscription_options_s rmw_unique_network_flow_endpoints_requirement_t require_unique_network_flow_endpoints; /// Used to create a content filtered topic during subscription creation. - char * filter_expression; - rcutils_string_array_t * expression_parameters; + rmw_subscription_content_filtered_topic_options_t * content_filtered_topic_options; } rmw_subscription_options_t; typedef struct RMW_PUBLIC_TYPE rmw_subscription_s @@ -208,8 +208,8 @@ typedef struct RMW_PUBLIC_TYPE rmw_subscription_s /// Indicates whether this subscription can loan messages bool can_loan_messages; - /// Indicates whether this subscription can support content filtered topic - bool is_cft_supported; + /// Indicates whether content filtered topic of this subscription is enabled + bool is_cft_enabled; } rmw_subscription_t; /// A handle to an rmw service diff --git a/rmw/src/subscription_content_filtered_topic_options.c b/rmw/src/subscription_content_filtered_topic_options.c new file mode 100644 index 00000000..d3872aac --- /dev/null +++ b/rmw/src/subscription_content_filtered_topic_options.c @@ -0,0 +1,181 @@ +// Copyright 2021 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include "rcutils/strdup.h" + +#include "rmw/error_handling.h" +#include "rmw/subscription_content_filtered_topic_options.h" + +rmw_subscription_content_filtered_topic_options_t +rmw_get_zero_initialized_content_filtered_topic_options() +{ + static rmw_subscription_content_filtered_topic_options_t zero_initialized_options = { + .filter_expression = NULL, + .expression_parameters = NULL, + }; + + return zero_initialized_options; +} + +rmw_ret_t +rmw_subscription_content_filtered_topic_options_init( + const char * filter_expression, + size_t expression_parameters_argc, + const char * expression_parameter_argv[], + const rcutils_allocator_t * allocator, + rmw_subscription_content_filtered_topic_options_t * options) +{ + RMW_CHECK_ARGUMENT_FOR_NULL(filter_expression, RMW_RET_INVALID_ARGUMENT); + if (expression_parameters_argc > 0) { + RMW_CHECK_ARGUMENT_FOR_NULL(expression_parameter_argv, RMW_RET_INVALID_ARGUMENT); + } + RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); + RMW_CHECK_ARGUMENT_FOR_NULL(options, RMW_RET_INVALID_ARGUMENT); + + rmw_ret_t ret = RMW_RET_OK; + rcutils_ret_t rcutils_ret; + char * new_filter_expression = NULL; + rcutils_string_array_t * new_expression_parameters = NULL; + size_t i; + + new_filter_expression = rcutils_strdup(filter_expression, *allocator); + if (!new_filter_expression) { + RMW_SET_ERROR_MSG("failed to copy filter expression"); + ret = RMW_RET_BAD_ALLOC; + goto failed; + } + + if (expression_parameters_argc > 0) { + new_expression_parameters = + allocator->allocate(sizeof(rcutils_string_array_t), allocator->state); + if (!new_expression_parameters) { + RMW_SET_ERROR_MSG("failed to allocate expression parameters"); + ret = RMW_RET_BAD_ALLOC; + goto failed; + } + *new_expression_parameters = rcutils_get_zero_initialized_string_array(); + rcutils_ret_t rcutils_ret = rcutils_string_array_init( + new_expression_parameters, expression_parameters_argc, allocator); + if (RCUTILS_RET_OK != rcutils_ret) { + RMW_SET_ERROR_MSG("failed to init string array for expression parameters"); + ret = RMW_RET_BAD_ALLOC; + goto failed; + } + } + for (i = 0; i < expression_parameters_argc; i++) { + new_expression_parameters->data[i] = + rcutils_strdup(expression_parameter_argv[i], *allocator); + if (!new_expression_parameters->data[i]) { + RMW_SET_ERROR_MSG("failed to copy expression parameter"); + ret = RMW_RET_BAD_ALLOC; + goto clear_expression_parameters; + } + } + + options->filter_expression = new_filter_expression; + options->expression_parameters = new_expression_parameters; + + return RMW_RET_OK; + +clear_expression_parameters: + rcutils_ret = rcutils_string_array_fini(new_expression_parameters); + if (RCUTILS_RET_OK != rcutils_ret) { + RCUTILS_SAFE_FWRITE_TO_STDERR("Failed to fini string array.\n"); + } + +failed: + allocator->deallocate(new_expression_parameters, allocator->state); + allocator->deallocate(new_filter_expression, allocator->state); + + return ret; +} + +rmw_ret_t +rmw_subscription_content_filtered_topic_options_set( + const char * filter_expression, + size_t expression_parameters_argc, + const char * expression_parameter_argv[], + const rcutils_allocator_t * allocator, + rmw_subscription_content_filtered_topic_options_t * options) +{ + rmw_ret_t ret = rmw_subscription_content_filtered_topic_options_fini(options, allocator); + if (ret != RMW_RET_OK) { + return ret; + } + + return rmw_subscription_content_filtered_topic_options_init( + filter_expression, + expression_parameters_argc, + expression_parameter_argv, + allocator, + options + ); +} + +rmw_ret_t +rmw_subscription_content_filtered_topic_options_copy( + const rmw_subscription_content_filtered_topic_options_t * src, + const rcutils_allocator_t * allocator, + rmw_subscription_content_filtered_topic_options_t * dst) +{ + RMW_CHECK_ARGUMENT_FOR_NULL(src, RMW_RET_INVALID_ARGUMENT); + RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); + RMW_CHECK_ARGUMENT_FOR_NULL(dst, RMW_RET_INVALID_ARGUMENT); + size_t expression_parameters_size = 0; + char ** expression_parameters_data = NULL; + if (src->expression_parameters) { + expression_parameters_size = src->expression_parameters->size; + expression_parameters_data = src->expression_parameters->data; + } + rmw_ret_t ret = rmw_subscription_content_filtered_topic_options_fini(dst, allocator); + if (ret != RMW_RET_OK) { + return ret; + } + + return rmw_subscription_content_filtered_topic_options_init( + src->filter_expression, + expression_parameters_size, + (const char **)expression_parameters_data, + allocator, + dst + ); +} + +rmw_ret_t +rmw_subscription_content_filtered_topic_options_fini( + rmw_subscription_content_filtered_topic_options_t * options, + const rcutils_allocator_t * allocator) +{ + RMW_CHECK_ARGUMENT_FOR_NULL(options, RMW_RET_INVALID_ARGUMENT); + RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); + + if (options->filter_expression) { + allocator->deallocate(options->filter_expression, allocator->state); + options->filter_expression = NULL; + } + + if (options->expression_parameters) { + rcutils_ret_t ret = rcutils_string_array_fini(options->expression_parameters); + if (RCUTILS_RET_OK != ret) { + RCUTILS_SAFE_FWRITE_TO_STDERR("Failed to fini string array.\n"); + return RMW_RET_ERROR; + } + allocator->deallocate(options->expression_parameters, allocator->state); + options->expression_parameters = NULL; + } + + return RMW_RET_OK; +} diff --git a/rmw/src/subscription_options.c b/rmw/src/subscription_options.c index baf050a5..f25213f5 100644 --- a/rmw/src/subscription_options.c +++ b/rmw/src/subscription_options.c @@ -26,8 +26,7 @@ rmw_get_default_subscription_options(void) .rmw_specific_subscription_payload = NULL, .ignore_local_publications = false, .require_unique_network_flow_endpoints = RMW_UNIQUE_NETWORK_FLOW_ENDPOINTS_NOT_REQUIRED, - .filter_expression = NULL, - .expression_parameters = NULL, + .content_filtered_topic_options = NULL, }; return subscription_options; } diff --git a/rmw/test/CMakeLists.txt b/rmw/test/CMakeLists.txt index 2ff4486e..0542ea33 100644 --- a/rmw/test/CMakeLists.txt +++ b/rmw/test/CMakeLists.txt @@ -211,3 +211,12 @@ if(TARGET test_network_flow_endpoint_array) target_link_libraries(test_network_flow_endpoint_array ${PROJECT_NAME} osrf_testing_tools_cpp::memory_tools) endif() + +ament_add_gmock(test_subscription_content_filtered_topic_options + test_subscription_content_filtered_topic_options.cpp + # Append the directory of librmw so it is found at test time. + APPEND_LIBRARY_DIRS "$" +) +if(TARGET test_subscription_content_filtered_topic_options) + target_link_libraries(test_subscription_content_filtered_topic_options ${PROJECT_NAME}) +endif() diff --git a/rmw/test/test_subscription_content_filtered_topic_options.cpp b/rmw/test/test_subscription_content_filtered_topic_options.cpp new file mode 100644 index 00000000..d91f6610 --- /dev/null +++ b/rmw/test/test_subscription_content_filtered_topic_options.cpp @@ -0,0 +1,237 @@ +// Copyright 2021 Open Source Robotics Foundation, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "gmock/gmock.h" + +#include "rcutils/strdup.h" + +#include "./time_bomb_allocator_testing_utils.h" +#include "rmw/error_handling.h" +#include "rmw/subscription_content_filtered_topic_options.h" + +TEST(rmw_subscription_content_filtered_topic_options, get_zero_init) +{ + rmw_subscription_content_filtered_topic_options_t options = + rmw_get_zero_initialized_content_filtered_topic_options(); + EXPECT_EQ(options.filter_expression, nullptr); + EXPECT_EQ(options.expression_parameters, nullptr); +} + +TEST(rmw_subscription_content_filtered_topic_options, options_init) +{ + rmw_subscription_content_filtered_topic_options_t options = + rmw_get_zero_initialized_content_filtered_topic_options(); + EXPECT_EQ(options.filter_expression, nullptr); + EXPECT_EQ(options.expression_parameters, nullptr); + + rcutils_allocator_t allocator = rcutils_get_default_allocator(); + EXPECT_EQ( + RMW_RET_INVALID_ARGUMENT, + rmw_subscription_content_filtered_topic_options_init( + nullptr, 0, nullptr, &allocator, &options)); + rmw_reset_error(); + + EXPECT_EQ( + RMW_RET_INVALID_ARGUMENT, + rmw_subscription_content_filtered_topic_options_init( + "filter='p'", 1, nullptr, &allocator, &options)); + rmw_reset_error(); + + EXPECT_EQ( + RMW_RET_INVALID_ARGUMENT, + rmw_subscription_content_filtered_topic_options_init( + "filter='p'", 0, nullptr, &allocator, nullptr)); + rmw_reset_error(); + + { + EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( + "filter='p'", 0, nullptr, &allocator, &options)); + EXPECT_STREQ(options.filter_expression, "filter='p'"); + + EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_fini(&options, &allocator)); + } + + { + const char * filter_expression = "(filter1=%0 OR filter1=%1) AND filter2=%2"; + const char * expression_parameters[] = { + "p1", "p2", "q1", + }; + size_t expression_parameters_count = sizeof(expression_parameters) / sizeof(char*); + EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( + filter_expression, expression_parameters_count, expression_parameters, &allocator, &options)); + + EXPECT_STREQ(options.filter_expression, filter_expression); + ASSERT_NE(nullptr, options.expression_parameters); + ASSERT_EQ(expression_parameters_count, options.expression_parameters->size); + for (size_t i = 0; i < expression_parameters_count; ++i) { + EXPECT_STREQ(options.expression_parameters->data[i], expression_parameters[i]); + } + + EXPECT_EQ( + RMW_RET_OK, rmw_subscription_content_filtered_topic_options_fini(&options, &allocator)); + } +} + +TEST(rmw_subscription_content_filtered_topic_options, options_set) +{ + rmw_subscription_content_filtered_topic_options_t options = + rmw_get_zero_initialized_content_filtered_topic_options(); + EXPECT_EQ(options.filter_expression, nullptr); + EXPECT_EQ(options.expression_parameters, nullptr); + + rcutils_allocator_t allocator = rcutils_get_default_allocator(); + + EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( + "filter='p'", 0, nullptr, &allocator, &options)); + EXPECT_STREQ(options.filter_expression, "filter='p'"); + + EXPECT_EQ( + RMW_RET_INVALID_ARGUMENT, + rmw_subscription_content_filtered_topic_options_set( + nullptr, 0, nullptr, &allocator, &options)); + rmw_reset_error(); + + EXPECT_EQ( + RMW_RET_INVALID_ARGUMENT, + rmw_subscription_content_filtered_topic_options_set( + "filter='p'", 1, nullptr, &allocator, &options)); + rmw_reset_error(); + + EXPECT_EQ( + RMW_RET_INVALID_ARGUMENT, + rmw_subscription_content_filtered_topic_options_set( + "filter='p'", 0, nullptr, &allocator, nullptr)); + rmw_reset_error(); + + { + EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_set( + "filter='p1'", 0, nullptr, &allocator, &options)); + EXPECT_STREQ(options.filter_expression, "filter='p1'"); + } + + { + const char * filter_expression = "(filter1=%0 OR filter1=%1) AND filter2=%2"; + const char * expression_parameters[] = { + "p1", "p2", "q1", + }; + size_t expression_parameters_count = sizeof(expression_parameters) / sizeof(char*); + EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_set( + filter_expression, expression_parameters_count, expression_parameters, &allocator, &options)); + + EXPECT_STREQ(options.filter_expression, filter_expression); + ASSERT_NE(nullptr, options.expression_parameters); + ASSERT_EQ(expression_parameters_count, options.expression_parameters->size); + for (size_t i = 0; i < expression_parameters_count; ++i) { + EXPECT_STREQ(options.expression_parameters->data[i], expression_parameters[i]); + } + + EXPECT_EQ( + RMW_RET_OK, rmw_subscription_content_filtered_topic_options_fini(&options, &allocator)); + } + + EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_fini(&options, &allocator)); +} + +TEST(rmw_subscription_content_filtered_topic_options, options_copy) { + rmw_subscription_content_filtered_topic_options_t source = + rmw_get_zero_initialized_content_filtered_topic_options(); + rcutils_allocator_t allocator = rcutils_get_default_allocator(); + + const char * filter_expression = "(filter1=%0 OR filter1=%1) AND filter2=%2"; + const char * expression_parameters[] = { + "p1", "p2", "q1", + }; + size_t expression_parameters_count = sizeof(expression_parameters) / sizeof(char*); + + EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( + filter_expression, expression_parameters_count, expression_parameters, &allocator, &source)); + + rmw_subscription_content_filtered_topic_options_t destination = + rmw_get_zero_initialized_content_filtered_topic_options(); + EXPECT_EQ( + RMW_RET_INVALID_ARGUMENT, + rmw_subscription_content_filtered_topic_options_copy(nullptr, &allocator, &destination)); + rcutils_reset_error(); + + EXPECT_EQ( + RMW_RET_INVALID_ARGUMENT, + rmw_subscription_content_filtered_topic_options_copy(&source, nullptr, &destination)); + rcutils_reset_error(); + + EXPECT_EQ( + RMW_RET_INVALID_ARGUMENT, + rmw_subscription_content_filtered_topic_options_copy(&source, &allocator, nullptr)); + rcutils_reset_error(); + + rcutils_allocator_t failing_allocator = get_time_bomb_allocator(); + constexpr int expected_num_malloc_calls = 5; + for (int i = 0; i < expected_num_malloc_calls; ++i) { + set_time_bomb_allocator_malloc_count(failing_allocator, i); + EXPECT_EQ( + RMW_RET_BAD_ALLOC, + rmw_subscription_content_filtered_topic_options_copy( + &source, &failing_allocator, &destination)); + rcutils_reset_error(); + } + + EXPECT_EQ( + RMW_RET_OK, + rmw_subscription_content_filtered_topic_options_copy(&source, &allocator, &destination)); + + EXPECT_STREQ(source.filter_expression, destination.filter_expression); + int res = 0; + EXPECT_EQ(RCUTILS_RET_OK, + rcutils_string_array_cmp( + source.expression_parameters, destination.expression_parameters, &res)); + EXPECT_EQ(res, 0); + + { + // second copy operation + rmw_subscription_content_filtered_topic_options_t source2 = + rmw_get_zero_initialized_content_filtered_topic_options(); + const char * filter_expression = "filter='p1'"; + EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( + filter_expression, 0, nullptr, &allocator, &source2)); + EXPECT_STREQ(source2.filter_expression, filter_expression); + EXPECT_EQ( + RMW_RET_OK, + rmw_subscription_content_filtered_topic_options_copy(&source2, &allocator, &destination)); + EXPECT_STREQ(source2.filter_expression, destination.filter_expression); + EXPECT_EQ(nullptr, destination.expression_parameters); + EXPECT_EQ( + RMW_RET_OK, rmw_subscription_content_filtered_topic_options_fini(&source2, &allocator)); + } + + EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_fini(&source, &allocator)); + EXPECT_EQ( + RMW_RET_OK, + rmw_subscription_content_filtered_topic_options_fini(&destination, &allocator)); +} + +TEST(rmw_subscription_content_filtered_topic_options, content_filtered_topic_options_fini) { + rcutils_allocator_t allocator = rcutils_get_default_allocator(); + EXPECT_EQ( + RMW_RET_INVALID_ARGUMENT, + rmw_subscription_content_filtered_topic_options_fini(nullptr, &allocator)); + rcutils_reset_error(); + + rmw_subscription_content_filtered_topic_options_t options = + rmw_get_zero_initialized_content_filtered_topic_options(); + EXPECT_EQ( + RMW_RET_INVALID_ARGUMENT, + rmw_subscription_content_filtered_topic_options_fini(&options, nullptr)); + rcutils_reset_error(); + + EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_fini(&options, &allocator)); +} diff --git a/rmw/test/test_subscription_options.cpp b/rmw/test/test_subscription_options.cpp index d7999688..37750e10 100644 --- a/rmw/test/test_subscription_options.cpp +++ b/rmw/test/test_subscription_options.cpp @@ -24,6 +24,5 @@ TEST(rmw_subscription_options, get_default_subscription_options) EXPECT_EQ( options.require_unique_network_flow_endpoints, RMW_UNIQUE_NETWORK_FLOW_ENDPOINTS_NOT_REQUIRED); - EXPECT_EQ(options.filter_expression, nullptr); - EXPECT_EQ(options.expression_parameters, nullptr); + EXPECT_EQ(options.content_filtered_topic_options, nullptr); } From dbfd2d4c26182732c66e8c6f44bc0d7d9a343696 Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Mon, 25 Oct 2021 09:56:03 +0800 Subject: [PATCH 07/14] nit Signed-off-by: Chen Lihui --- ...ubscription_content_filtered_topic_options.h | 1 + ...ubscription_content_filtered_topic_options.c | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/rmw/include/rmw/subscription_content_filtered_topic_options.h b/rmw/include/rmw/subscription_content_filtered_topic_options.h index 1528b926..bfa032f3 100644 --- a/rmw/include/rmw/subscription_content_filtered_topic_options.h +++ b/rmw/include/rmw/subscription_content_filtered_topic_options.h @@ -22,6 +22,7 @@ extern "C" #include "rcutils/allocator.h" #include "rcutils/types.h" + #include "rmw/macros.h" #include "rmw/ret_types.h" #include "rmw/visibility_control.h" diff --git a/rmw/src/subscription_content_filtered_topic_options.c b/rmw/src/subscription_content_filtered_topic_options.c index d3872aac..fb8383a1 100644 --- a/rmw/src/subscription_content_filtered_topic_options.c +++ b/rmw/src/subscription_content_filtered_topic_options.c @@ -74,14 +74,15 @@ rmw_subscription_content_filtered_topic_options_init( ret = RMW_RET_BAD_ALLOC; goto failed; } - } - for (i = 0; i < expression_parameters_argc; i++) { - new_expression_parameters->data[i] = - rcutils_strdup(expression_parameter_argv[i], *allocator); - if (!new_expression_parameters->data[i]) { - RMW_SET_ERROR_MSG("failed to copy expression parameter"); - ret = RMW_RET_BAD_ALLOC; - goto clear_expression_parameters; + + for (i = 0; i < expression_parameters_argc; i++) { + new_expression_parameters->data[i] = + rcutils_strdup(expression_parameter_argv[i], *allocator); + if (!new_expression_parameters->data[i]) { + RMW_SET_ERROR_MSG("failed to copy expression parameter"); + ret = RMW_RET_BAD_ALLOC; + goto clear_expression_parameters; + } } } From f2922c602b440d27a0c371c4ac03a677e67c1f72 Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Mon, 25 Oct 2021 10:05:26 +0800 Subject: [PATCH 08/14] unscrutify fixed Signed-off-by: Chen Lihui --- ...ription_content_filtered_topic_options.cpp | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/rmw/test/test_subscription_content_filtered_topic_options.cpp b/rmw/test/test_subscription_content_filtered_topic_options.cpp index d91f6610..81b76f05 100644 --- a/rmw/test/test_subscription_content_filtered_topic_options.cpp +++ b/rmw/test/test_subscription_content_filtered_topic_options.cpp @@ -55,11 +55,14 @@ TEST(rmw_subscription_content_filtered_topic_options, options_init) rmw_reset_error(); { - EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( - "filter='p'", 0, nullptr, &allocator, &options)); + EXPECT_EQ( + RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( + "filter='p'", 0, nullptr, &allocator, &options)); EXPECT_STREQ(options.filter_expression, "filter='p'"); - EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_fini(&options, &allocator)); + EXPECT_EQ( + RMW_RET_OK, + rmw_subscription_content_filtered_topic_options_fini(&options, &allocator)); } { @@ -67,9 +70,11 @@ TEST(rmw_subscription_content_filtered_topic_options, options_init) const char * expression_parameters[] = { "p1", "p2", "q1", }; - size_t expression_parameters_count = sizeof(expression_parameters) / sizeof(char*); - EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( - filter_expression, expression_parameters_count, expression_parameters, &allocator, &options)); + size_t expression_parameters_count = sizeof(expression_parameters) / sizeof(char *); + EXPECT_EQ( + RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( + filter_expression, expression_parameters_count, expression_parameters, &allocator, + &options)); EXPECT_STREQ(options.filter_expression, filter_expression); ASSERT_NE(nullptr, options.expression_parameters); @@ -92,8 +97,9 @@ TEST(rmw_subscription_content_filtered_topic_options, options_set) rcutils_allocator_t allocator = rcutils_get_default_allocator(); - EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( - "filter='p'", 0, nullptr, &allocator, &options)); + EXPECT_EQ( + RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( + "filter='p'", 0, nullptr, &allocator, &options)); EXPECT_STREQ(options.filter_expression, "filter='p'"); EXPECT_EQ( @@ -115,8 +121,9 @@ TEST(rmw_subscription_content_filtered_topic_options, options_set) rmw_reset_error(); { - EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_set( - "filter='p1'", 0, nullptr, &allocator, &options)); + EXPECT_EQ( + RMW_RET_OK, rmw_subscription_content_filtered_topic_options_set( + "filter='p1'", 0, nullptr, &allocator, &options)); EXPECT_STREQ(options.filter_expression, "filter='p1'"); } @@ -125,9 +132,11 @@ TEST(rmw_subscription_content_filtered_topic_options, options_set) const char * expression_parameters[] = { "p1", "p2", "q1", }; - size_t expression_parameters_count = sizeof(expression_parameters) / sizeof(char*); - EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_set( - filter_expression, expression_parameters_count, expression_parameters, &allocator, &options)); + size_t expression_parameters_count = sizeof(expression_parameters) / sizeof(char *); + EXPECT_EQ( + RMW_RET_OK, rmw_subscription_content_filtered_topic_options_set( + filter_expression, expression_parameters_count, expression_parameters, &allocator, + &options)); EXPECT_STREQ(options.filter_expression, filter_expression); ASSERT_NE(nullptr, options.expression_parameters); @@ -152,10 +161,11 @@ TEST(rmw_subscription_content_filtered_topic_options, options_copy) { const char * expression_parameters[] = { "p1", "p2", "q1", }; - size_t expression_parameters_count = sizeof(expression_parameters) / sizeof(char*); + size_t expression_parameters_count = sizeof(expression_parameters) / sizeof(char *); - EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( - filter_expression, expression_parameters_count, expression_parameters, &allocator, &source)); + EXPECT_EQ( + RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( + filter_expression, expression_parameters_count, expression_parameters, &allocator, &source)); rmw_subscription_content_filtered_topic_options_t destination = rmw_get_zero_initialized_content_filtered_topic_options(); @@ -191,7 +201,8 @@ TEST(rmw_subscription_content_filtered_topic_options, options_copy) { EXPECT_STREQ(source.filter_expression, destination.filter_expression); int res = 0; - EXPECT_EQ(RCUTILS_RET_OK, + EXPECT_EQ( + RCUTILS_RET_OK, rcutils_string_array_cmp( source.expression_parameters, destination.expression_parameters, &res)); EXPECT_EQ(res, 0); @@ -201,8 +212,9 @@ TEST(rmw_subscription_content_filtered_topic_options, options_copy) { rmw_subscription_content_filtered_topic_options_t source2 = rmw_get_zero_initialized_content_filtered_topic_options(); const char * filter_expression = "filter='p1'"; - EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( - filter_expression, 0, nullptr, &allocator, &source2)); + EXPECT_EQ( + RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( + filter_expression, 0, nullptr, &allocator, &source2)); EXPECT_STREQ(source2.filter_expression, filter_expression); EXPECT_EQ( RMW_RET_OK, From 0711a9a453ac8499a0741fcee1bbd5504acb4468 Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Tue, 26 Oct 2021 14:05:34 +0800 Subject: [PATCH 09/14] rename interfaces and structure Signed-off-by: Chen Lihui --- rmw/CMakeLists.txt | 2 +- rmw/include/rmw/rmw.h | 22 ++-- ... => subscription_content_filter_options.h} | 60 +++++----- rmw/include/rmw/types.h | 6 +- ... => subscription_content_filter_options.c} | 34 +++--- rmw/src/subscription_options.c | 2 +- rmw/test/CMakeLists.txt | 8 +- ...t_subscription_content_filter_options.cpp} | 104 +++++++++--------- rmw/test/test_subscription_options.cpp | 2 +- 9 files changed, 120 insertions(+), 120 deletions(-) rename rmw/include/rmw/{subscription_content_filtered_topic_options.h => subscription_content_filter_options.h} (64%) rename rmw/src/{subscription_content_filtered_topic_options.c => subscription_content_filter_options.c} (82%) rename rmw/test/{test_subscription_content_filtered_topic_options.cpp => test_subscription_content_filter_options.cpp} (61%) diff --git a/rmw/CMakeLists.txt b/rmw/CMakeLists.txt index 2b67fe9d..089d5cdf 100644 --- a/rmw/CMakeLists.txt +++ b/rmw/CMakeLists.txt @@ -37,7 +37,7 @@ set(rmw_sources "src/qos_string_conversions.c" "src/sanity_checks.c" "src/security_options.c" - "src/subscription_content_filtered_topic_options.c" + "src/subscription_content_filter_options.c" "src/subscription_options.c" "src/time.c" "src/topic_endpoint_info_array.c" diff --git a/rmw/include/rmw/rmw.h b/rmw/include/rmw/rmw.h index 051bdfbc..f25c7b07 100644 --- a/rmw/include/rmw/rmw.h +++ b/rmw/include/rmw/rmw.h @@ -1118,7 +1118,7 @@ rmw_subscription_get_actual_qos( const rmw_subscription_t * subscription, rmw_qos_profile_t * qos); -/// Set the content filtered topic options for the subscription. +/// Set the content filter options for the subscription. /** * This function will set a filter expression and an array of expression parameters * for the given subscription. @@ -1132,8 +1132,8 @@ rmw_subscription_get_actual_qos( * Lock-Free | Maybe [1] * [1] implementation defined, check the implementation documentation * - * \param[in] subscription The subscription to set content filtered topic options. - * \param[in] options The content filtered topic options. + * \param[in] subscription The subscription to set content filter options. + * \param[in] options The content filter options. * Use `options.filter_expression` with an empty("") string to * reset/clean content filtered topic for the subscription. * \return `RMW_RET_OK` if successful, or @@ -1146,13 +1146,13 @@ rmw_subscription_get_actual_qos( RMW_PUBLIC RMW_WARN_UNUSED rmw_ret_t -rmw_subscription_set_cft_expression_parameters( +rmw_subscription_set_content_filter( rmw_subscription_t * subscription, - const rmw_subscription_content_filtered_topic_options_t * options); + const rmw_subscription_content_filter_options_t * options); -/// Retrieve the content filtered topic options of the subscription. +/// Retrieve the content filter options of the subscription. /** - * This function will return a content filtered topic options by the given subscription. + * This function will return a content filter options by the given subscription. * *
* Attribute | Adherence @@ -1164,8 +1164,8 @@ rmw_subscription_set_cft_expression_parameters( * [1] implementation defined, check the implementation documentation * * \param[in] subscription The subscription object to inspect. - * \param[in] allocator Allocator to be used when populating the content filtered topic options. - * \param[out] options The content filtered topic options. + * \param[in] allocator Allocator to be used when populating the content filter options. + * \param[out] options The content filter options. * \return `RMW_RET_OK` if successful, or * \return `RMW_RET_INVALID_ARGUMENT` if an argument is null, or * \return `RMW_RET_INCORRECT_RMW_IMPLEMENTATION` if the `subscription` implementation @@ -1177,10 +1177,10 @@ rmw_subscription_set_cft_expression_parameters( RMW_PUBLIC RMW_WARN_UNUSED rmw_ret_t -rmw_subscription_get_cft_expression_parameters( +rmw_subscription_get_content_filter( const rmw_subscription_t * subscription, rcutils_allocator_t * allocator, - rmw_subscription_content_filtered_topic_options_t * options); + rmw_subscription_content_filter_options_t * options); /// Take an incoming ROS message. /** diff --git a/rmw/include/rmw/subscription_content_filtered_topic_options.h b/rmw/include/rmw/subscription_content_filter_options.h similarity index 64% rename from rmw/include/rmw/subscription_content_filtered_topic_options.h rename to rmw/include/rmw/subscription_content_filter_options.h index bfa032f3..f6aa545b 100644 --- a/rmw/include/rmw/subscription_content_filtered_topic_options.h +++ b/rmw/include/rmw/subscription_content_filter_options.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef RMW__SUBSCRIPTION_CONTENT_FILTERED_TOPIC_OPTIONS_H_ -#define RMW__SUBSCRIPTION_CONTENT_FILTERED_TOPIC_OPTIONS_H_ +#ifndef RMW__SUBSCRIPTION_CONTENT_FILTER_OPTIONS_H_ +#define RMW__SUBSCRIPTION_CONTENT_FILTER_OPTIONS_H_ #ifdef __cplusplus extern "C" @@ -27,7 +27,7 @@ extern "C" #include "rmw/ret_types.h" #include "rmw/visibility_control.h" -typedef struct RMW_PUBLIC_TYPE rmw_subscription_content_filtered_topic_options_s +typedef struct RMW_PUBLIC_TYPE rmw_subscription_content_filter_options_s { /** * specify the criteria to select the data samples of interest. @@ -44,88 +44,88 @@ typedef struct RMW_PUBLIC_TYPE rmw_subscription_content_filtered_topic_options_s * (i.e., it cannot be greater than 100 on RTI_Connext.) */ rcutils_string_array_t * expression_parameters; -} rmw_subscription_content_filtered_topic_options_t; +} rmw_subscription_content_filter_options_t; -/// Get zero initialized content filtered topic options. +/// Get zero initialized content filter options. RMW_PUBLIC -rmw_subscription_content_filtered_topic_options_t -rmw_get_zero_initialized_content_filtered_topic_options(); +rmw_subscription_content_filter_options_t +rmw_get_zero_initialized_content_filter_options(); -/// Initialize the given content filtered topic options. +/// Initialize the given content filter options. /** * \param[in] filter_expression The filter expression. * \param[in] expression_parameters_argc The expression parameters argc. * \param[in] expression_parameter_argv The expression parameters argv. - * \param[in] allocator The allocator used when copying data to the content filtered topic options. - * \param[out] options The content filtered topic options to be set. + * \param[in] allocator The allocator used when copying data to the content filter options. + * \param[out] options The content filter options to be set. * \returns RMW_RET_INVALID_ARGUMENT, or * \returns RMW_RET_BAD_ALLOC, or * \returns RMW_RET_OK */ RMW_PUBLIC rmw_ret_t -rmw_subscription_content_filtered_topic_options_init( +rmw_subscription_content_filter_options_init( const char * filter_expression, size_t expression_parameters_argc, const char * expression_parameter_argv[], const rcutils_allocator_t * allocator, - rmw_subscription_content_filtered_topic_options_t * options); + rmw_subscription_content_filter_options_t * options); -/// Set the given content filtered topic options. +/// Set the given content filter options. /** * \param[in] filter_expression The filter expression. * \param[in] expression_parameters_argc The expression parameters argc. * \param[in] expression_parameter_argv The expression parameters argv. - * \param[in] allocator The allocator used when copying data to the content filtered topic options. - * \param[out] options The content filtered topic options to be set. + * \param[in] allocator The allocator used when copying data to the content filter options. + * \param[out] options The content filter options to be set. * \returns RMW_RET_INVALID_ARGUMENT, or * \returns RMW_RET_BAD_ALLOC, or * \returns RMW_RET_OK */ RMW_PUBLIC rmw_ret_t -rmw_subscription_content_filtered_topic_options_set( +rmw_subscription_content_filter_options_set( const char * filter_expression, size_t expression_parameters_argc, const char * expression_parameter_argv[], const rcutils_allocator_t * allocator, - rmw_subscription_content_filtered_topic_options_t * options); + rmw_subscription_content_filter_options_t * options); -/// Copy the given content filtered topic options. +/// Copy the given content filter options. /** - * \param[in] src content filtered topic options to be copied. - * \param[in] allocator allocator used when copying data to the new content filtered topic options. - * \param[out] dst content filtered topic options to be set. + * \param[in] src content filter options to be copied. + * \param[in] allocator allocator used when copying data to the new content filter options. + * \param[out] dst content filter options to be set. * \returns RMW_RET_INVALID_ARGUMENT, or * \returns RMW_RET_BAD_ALLOC, or * \returns RMW_RET_OK */ RMW_PUBLIC rmw_ret_t -rmw_subscription_content_filtered_topic_options_copy( - const rmw_subscription_content_filtered_topic_options_t * src, +rmw_subscription_content_filter_options_copy( + const rmw_subscription_content_filter_options_t * src, const rcutils_allocator_t * allocator, - rmw_subscription_content_filtered_topic_options_t * dst); + rmw_subscription_content_filter_options_t * dst); -/// Finalize the content filtered topic options. +/// Finalize the content filter options. /** - * \param[in] options content filtered topic options to be finalized. - * \param[in] allocator allocator used to deallocate the content filtered topic options. + * \param[in] options content filter options to be finalized. + * \param[in] allocator allocator used to deallocate the content filter options. * \returns RMW_RET_INVALID_ARGUMENT, or * \returns RMW_RET_ERROR, or * \returns RMW_RET_OK */ RMW_PUBLIC rmw_ret_t -rmw_subscription_content_filtered_topic_options_fini( - rmw_subscription_content_filtered_topic_options_t * options, +rmw_subscription_content_filter_options_fini( + rmw_subscription_content_filter_options_t * options, const rcutils_allocator_t * allocator); #ifdef __cplusplus } #endif -#endif // RMW__SUBSCRIPTION_CONTENT_FILTERED_TOPIC_OPTIONS_H_ +#endif // RMW__SUBSCRIPTION_CONTENT_FILTER_OPTIONS_H_ diff --git a/rmw/include/rmw/types.h b/rmw/include/rmw/types.h index b56a6598..17d0ea89 100644 --- a/rmw/include/rmw/types.h +++ b/rmw/include/rmw/types.h @@ -33,7 +33,7 @@ extern "C" #include "rmw/ret_types.h" #include "rmw/security_options.h" #include "rmw/serialized_message.h" -#include "rmw/subscription_content_filtered_topic_options.h" +#include "rmw/subscription_content_filter_options.h" #include "rmw/time.h" #include "rmw/visibility_control.h" @@ -179,8 +179,8 @@ typedef struct RMW_PUBLIC_TYPE rmw_subscription_options_s */ rmw_unique_network_flow_endpoints_requirement_t require_unique_network_flow_endpoints; - /// Used to create a content filtered topic during subscription creation. - rmw_subscription_content_filtered_topic_options_t * content_filtered_topic_options; + /// Used to create a content filter options during subscription creation. + rmw_subscription_content_filter_options_t * content_filter_options; } rmw_subscription_options_t; typedef struct RMW_PUBLIC_TYPE rmw_subscription_s diff --git a/rmw/src/subscription_content_filtered_topic_options.c b/rmw/src/subscription_content_filter_options.c similarity index 82% rename from rmw/src/subscription_content_filtered_topic_options.c rename to rmw/src/subscription_content_filter_options.c index fb8383a1..f78bacfa 100644 --- a/rmw/src/subscription_content_filtered_topic_options.c +++ b/rmw/src/subscription_content_filter_options.c @@ -17,12 +17,12 @@ #include "rcutils/strdup.h" #include "rmw/error_handling.h" -#include "rmw/subscription_content_filtered_topic_options.h" +#include "rmw/subscription_content_filter_options.h" -rmw_subscription_content_filtered_topic_options_t -rmw_get_zero_initialized_content_filtered_topic_options() +rmw_subscription_content_filter_options_t +rmw_get_zero_initialized_content_filter_options() { - static rmw_subscription_content_filtered_topic_options_t zero_initialized_options = { + static rmw_subscription_content_filter_options_t zero_initialized_options = { .filter_expression = NULL, .expression_parameters = NULL, }; @@ -31,12 +31,12 @@ rmw_get_zero_initialized_content_filtered_topic_options() } rmw_ret_t -rmw_subscription_content_filtered_topic_options_init( +rmw_subscription_content_filter_options_init( const char * filter_expression, size_t expression_parameters_argc, const char * expression_parameter_argv[], const rcutils_allocator_t * allocator, - rmw_subscription_content_filtered_topic_options_t * options) + rmw_subscription_content_filter_options_t * options) { RMW_CHECK_ARGUMENT_FOR_NULL(filter_expression, RMW_RET_INVALID_ARGUMENT); if (expression_parameters_argc > 0) { @@ -105,19 +105,19 @@ rmw_subscription_content_filtered_topic_options_init( } rmw_ret_t -rmw_subscription_content_filtered_topic_options_set( +rmw_subscription_content_filter_options_set( const char * filter_expression, size_t expression_parameters_argc, const char * expression_parameter_argv[], const rcutils_allocator_t * allocator, - rmw_subscription_content_filtered_topic_options_t * options) + rmw_subscription_content_filter_options_t * options) { - rmw_ret_t ret = rmw_subscription_content_filtered_topic_options_fini(options, allocator); + rmw_ret_t ret = rmw_subscription_content_filter_options_fini(options, allocator); if (ret != RMW_RET_OK) { return ret; } - return rmw_subscription_content_filtered_topic_options_init( + return rmw_subscription_content_filter_options_init( filter_expression, expression_parameters_argc, expression_parameter_argv, @@ -127,10 +127,10 @@ rmw_subscription_content_filtered_topic_options_set( } rmw_ret_t -rmw_subscription_content_filtered_topic_options_copy( - const rmw_subscription_content_filtered_topic_options_t * src, +rmw_subscription_content_filter_options_copy( + const rmw_subscription_content_filter_options_t * src, const rcutils_allocator_t * allocator, - rmw_subscription_content_filtered_topic_options_t * dst) + rmw_subscription_content_filter_options_t * dst) { RMW_CHECK_ARGUMENT_FOR_NULL(src, RMW_RET_INVALID_ARGUMENT); RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); @@ -141,12 +141,12 @@ rmw_subscription_content_filtered_topic_options_copy( expression_parameters_size = src->expression_parameters->size; expression_parameters_data = src->expression_parameters->data; } - rmw_ret_t ret = rmw_subscription_content_filtered_topic_options_fini(dst, allocator); + rmw_ret_t ret = rmw_subscription_content_filter_options_fini(dst, allocator); if (ret != RMW_RET_OK) { return ret; } - return rmw_subscription_content_filtered_topic_options_init( + return rmw_subscription_content_filter_options_init( src->filter_expression, expression_parameters_size, (const char **)expression_parameters_data, @@ -156,8 +156,8 @@ rmw_subscription_content_filtered_topic_options_copy( } rmw_ret_t -rmw_subscription_content_filtered_topic_options_fini( - rmw_subscription_content_filtered_topic_options_t * options, +rmw_subscription_content_filter_options_fini( + rmw_subscription_content_filter_options_t * options, const rcutils_allocator_t * allocator) { RMW_CHECK_ARGUMENT_FOR_NULL(options, RMW_RET_INVALID_ARGUMENT); diff --git a/rmw/src/subscription_options.c b/rmw/src/subscription_options.c index f25213f5..e9efda3f 100644 --- a/rmw/src/subscription_options.c +++ b/rmw/src/subscription_options.c @@ -26,7 +26,7 @@ rmw_get_default_subscription_options(void) .rmw_specific_subscription_payload = NULL, .ignore_local_publications = false, .require_unique_network_flow_endpoints = RMW_UNIQUE_NETWORK_FLOW_ENDPOINTS_NOT_REQUIRED, - .content_filtered_topic_options = NULL, + .content_filter_options = NULL, }; return subscription_options; } diff --git a/rmw/test/CMakeLists.txt b/rmw/test/CMakeLists.txt index 0542ea33..e7733c95 100644 --- a/rmw/test/CMakeLists.txt +++ b/rmw/test/CMakeLists.txt @@ -212,11 +212,11 @@ if(TARGET test_network_flow_endpoint_array) osrf_testing_tools_cpp::memory_tools) endif() -ament_add_gmock(test_subscription_content_filtered_topic_options - test_subscription_content_filtered_topic_options.cpp +ament_add_gmock(test_subscription_content_filter_options + test_subscription_content_filter_options.cpp # Append the directory of librmw so it is found at test time. APPEND_LIBRARY_DIRS "$" ) -if(TARGET test_subscription_content_filtered_topic_options) - target_link_libraries(test_subscription_content_filtered_topic_options ${PROJECT_NAME}) +if(TARGET test_subscription_content_filter_options) + target_link_libraries(test_subscription_content_filter_options ${PROJECT_NAME}) endif() diff --git a/rmw/test/test_subscription_content_filtered_topic_options.cpp b/rmw/test/test_subscription_content_filter_options.cpp similarity index 61% rename from rmw/test/test_subscription_content_filtered_topic_options.cpp rename to rmw/test/test_subscription_content_filter_options.cpp index 81b76f05..d0f6d3c8 100644 --- a/rmw/test/test_subscription_content_filtered_topic_options.cpp +++ b/rmw/test/test_subscription_content_filter_options.cpp @@ -18,61 +18,61 @@ #include "./time_bomb_allocator_testing_utils.h" #include "rmw/error_handling.h" -#include "rmw/subscription_content_filtered_topic_options.h" +#include "rmw/subscription_content_filter_options.h" -TEST(rmw_subscription_content_filtered_topic_options, get_zero_init) +TEST(rmw_subscription_content_filter_options, get_zero_init) { - rmw_subscription_content_filtered_topic_options_t options = - rmw_get_zero_initialized_content_filtered_topic_options(); + rmw_subscription_content_filter_options_t options = + rmw_get_zero_initialized_content_filter_options(); EXPECT_EQ(options.filter_expression, nullptr); EXPECT_EQ(options.expression_parameters, nullptr); } -TEST(rmw_subscription_content_filtered_topic_options, options_init) +TEST(rmw_subscription_content_filter_options, options_init) { - rmw_subscription_content_filtered_topic_options_t options = - rmw_get_zero_initialized_content_filtered_topic_options(); + rmw_subscription_content_filter_options_t options = + rmw_get_zero_initialized_content_filter_options(); EXPECT_EQ(options.filter_expression, nullptr); EXPECT_EQ(options.expression_parameters, nullptr); rcutils_allocator_t allocator = rcutils_get_default_allocator(); EXPECT_EQ( RMW_RET_INVALID_ARGUMENT, - rmw_subscription_content_filtered_topic_options_init( + rmw_subscription_content_filter_options_init( nullptr, 0, nullptr, &allocator, &options)); rmw_reset_error(); EXPECT_EQ( RMW_RET_INVALID_ARGUMENT, - rmw_subscription_content_filtered_topic_options_init( + rmw_subscription_content_filter_options_init( "filter='p'", 1, nullptr, &allocator, &options)); rmw_reset_error(); EXPECT_EQ( RMW_RET_INVALID_ARGUMENT, - rmw_subscription_content_filtered_topic_options_init( + rmw_subscription_content_filter_options_init( "filter='p'", 0, nullptr, &allocator, nullptr)); rmw_reset_error(); { EXPECT_EQ( - RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( + RMW_RET_OK, rmw_subscription_content_filter_options_init( "filter='p'", 0, nullptr, &allocator, &options)); EXPECT_STREQ(options.filter_expression, "filter='p'"); EXPECT_EQ( RMW_RET_OK, - rmw_subscription_content_filtered_topic_options_fini(&options, &allocator)); + rmw_subscription_content_filter_options_fini(&options, &allocator)); } { const char * filter_expression = "(filter1=%0 OR filter1=%1) AND filter2=%2"; const char * expression_parameters[] = { - "p1", "p2", "q1", + "1", "2", "3", }; size_t expression_parameters_count = sizeof(expression_parameters) / sizeof(char *); EXPECT_EQ( - RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( + RMW_RET_OK, rmw_subscription_content_filter_options_init( filter_expression, expression_parameters_count, expression_parameters, &allocator, &options)); @@ -84,45 +84,45 @@ TEST(rmw_subscription_content_filtered_topic_options, options_init) } EXPECT_EQ( - RMW_RET_OK, rmw_subscription_content_filtered_topic_options_fini(&options, &allocator)); + RMW_RET_OK, rmw_subscription_content_filter_options_fini(&options, &allocator)); } } -TEST(rmw_subscription_content_filtered_topic_options, options_set) +TEST(rmw_subscription_content_filter_options, options_set) { - rmw_subscription_content_filtered_topic_options_t options = - rmw_get_zero_initialized_content_filtered_topic_options(); + rmw_subscription_content_filter_options_t options = + rmw_get_zero_initialized_content_filter_options(); EXPECT_EQ(options.filter_expression, nullptr); EXPECT_EQ(options.expression_parameters, nullptr); rcutils_allocator_t allocator = rcutils_get_default_allocator(); EXPECT_EQ( - RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( + RMW_RET_OK, rmw_subscription_content_filter_options_init( "filter='p'", 0, nullptr, &allocator, &options)); EXPECT_STREQ(options.filter_expression, "filter='p'"); EXPECT_EQ( RMW_RET_INVALID_ARGUMENT, - rmw_subscription_content_filtered_topic_options_set( + rmw_subscription_content_filter_options_set( nullptr, 0, nullptr, &allocator, &options)); rmw_reset_error(); EXPECT_EQ( RMW_RET_INVALID_ARGUMENT, - rmw_subscription_content_filtered_topic_options_set( + rmw_subscription_content_filter_options_set( "filter='p'", 1, nullptr, &allocator, &options)); rmw_reset_error(); EXPECT_EQ( RMW_RET_INVALID_ARGUMENT, - rmw_subscription_content_filtered_topic_options_set( + rmw_subscription_content_filter_options_set( "filter='p'", 0, nullptr, &allocator, nullptr)); rmw_reset_error(); { EXPECT_EQ( - RMW_RET_OK, rmw_subscription_content_filtered_topic_options_set( + RMW_RET_OK, rmw_subscription_content_filter_options_set( "filter='p1'", 0, nullptr, &allocator, &options)); EXPECT_STREQ(options.filter_expression, "filter='p1'"); } @@ -130,11 +130,11 @@ TEST(rmw_subscription_content_filtered_topic_options, options_set) { const char * filter_expression = "(filter1=%0 OR filter1=%1) AND filter2=%2"; const char * expression_parameters[] = { - "p1", "p2", "q1", + "1", "2", "3", }; size_t expression_parameters_count = sizeof(expression_parameters) / sizeof(char *); EXPECT_EQ( - RMW_RET_OK, rmw_subscription_content_filtered_topic_options_set( + RMW_RET_OK, rmw_subscription_content_filter_options_set( filter_expression, expression_parameters_count, expression_parameters, &allocator, &options)); @@ -146,42 +146,42 @@ TEST(rmw_subscription_content_filtered_topic_options, options_set) } EXPECT_EQ( - RMW_RET_OK, rmw_subscription_content_filtered_topic_options_fini(&options, &allocator)); + RMW_RET_OK, rmw_subscription_content_filter_options_fini(&options, &allocator)); } - EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_fini(&options, &allocator)); + EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filter_options_fini(&options, &allocator)); } -TEST(rmw_subscription_content_filtered_topic_options, options_copy) { - rmw_subscription_content_filtered_topic_options_t source = - rmw_get_zero_initialized_content_filtered_topic_options(); +TEST(rmw_subscription_content_filter_options, options_copy) { + rmw_subscription_content_filter_options_t source = + rmw_get_zero_initialized_content_filter_options(); rcutils_allocator_t allocator = rcutils_get_default_allocator(); const char * filter_expression = "(filter1=%0 OR filter1=%1) AND filter2=%2"; const char * expression_parameters[] = { - "p1", "p2", "q1", + "1", "2", "3", }; size_t expression_parameters_count = sizeof(expression_parameters) / sizeof(char *); EXPECT_EQ( - RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( + RMW_RET_OK, rmw_subscription_content_filter_options_init( filter_expression, expression_parameters_count, expression_parameters, &allocator, &source)); - rmw_subscription_content_filtered_topic_options_t destination = - rmw_get_zero_initialized_content_filtered_topic_options(); + rmw_subscription_content_filter_options_t destination = + rmw_get_zero_initialized_content_filter_options(); EXPECT_EQ( RMW_RET_INVALID_ARGUMENT, - rmw_subscription_content_filtered_topic_options_copy(nullptr, &allocator, &destination)); + rmw_subscription_content_filter_options_copy(nullptr, &allocator, &destination)); rcutils_reset_error(); EXPECT_EQ( RMW_RET_INVALID_ARGUMENT, - rmw_subscription_content_filtered_topic_options_copy(&source, nullptr, &destination)); + rmw_subscription_content_filter_options_copy(&source, nullptr, &destination)); rcutils_reset_error(); EXPECT_EQ( RMW_RET_INVALID_ARGUMENT, - rmw_subscription_content_filtered_topic_options_copy(&source, &allocator, nullptr)); + rmw_subscription_content_filter_options_copy(&source, &allocator, nullptr)); rcutils_reset_error(); rcutils_allocator_t failing_allocator = get_time_bomb_allocator(); @@ -190,14 +190,14 @@ TEST(rmw_subscription_content_filtered_topic_options, options_copy) { set_time_bomb_allocator_malloc_count(failing_allocator, i); EXPECT_EQ( RMW_RET_BAD_ALLOC, - rmw_subscription_content_filtered_topic_options_copy( + rmw_subscription_content_filter_options_copy( &source, &failing_allocator, &destination)); rcutils_reset_error(); } EXPECT_EQ( RMW_RET_OK, - rmw_subscription_content_filtered_topic_options_copy(&source, &allocator, &destination)); + rmw_subscription_content_filter_options_copy(&source, &allocator, &destination)); EXPECT_STREQ(source.filter_expression, destination.filter_expression); int res = 0; @@ -209,41 +209,41 @@ TEST(rmw_subscription_content_filtered_topic_options, options_copy) { { // second copy operation - rmw_subscription_content_filtered_topic_options_t source2 = - rmw_get_zero_initialized_content_filtered_topic_options(); + rmw_subscription_content_filter_options_t source2 = + rmw_get_zero_initialized_content_filter_options(); const char * filter_expression = "filter='p1'"; EXPECT_EQ( - RMW_RET_OK, rmw_subscription_content_filtered_topic_options_init( + RMW_RET_OK, rmw_subscription_content_filter_options_init( filter_expression, 0, nullptr, &allocator, &source2)); EXPECT_STREQ(source2.filter_expression, filter_expression); EXPECT_EQ( RMW_RET_OK, - rmw_subscription_content_filtered_topic_options_copy(&source2, &allocator, &destination)); + rmw_subscription_content_filter_options_copy(&source2, &allocator, &destination)); EXPECT_STREQ(source2.filter_expression, destination.filter_expression); EXPECT_EQ(nullptr, destination.expression_parameters); EXPECT_EQ( - RMW_RET_OK, rmw_subscription_content_filtered_topic_options_fini(&source2, &allocator)); + RMW_RET_OK, rmw_subscription_content_filter_options_fini(&source2, &allocator)); } - EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_fini(&source, &allocator)); + EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filter_options_fini(&source, &allocator)); EXPECT_EQ( RMW_RET_OK, - rmw_subscription_content_filtered_topic_options_fini(&destination, &allocator)); + rmw_subscription_content_filter_options_fini(&destination, &allocator)); } -TEST(rmw_subscription_content_filtered_topic_options, content_filtered_topic_options_fini) { +TEST(rmw_subscription_content_filter_options, content_filter_options_fini) { rcutils_allocator_t allocator = rcutils_get_default_allocator(); EXPECT_EQ( RMW_RET_INVALID_ARGUMENT, - rmw_subscription_content_filtered_topic_options_fini(nullptr, &allocator)); + rmw_subscription_content_filter_options_fini(nullptr, &allocator)); rcutils_reset_error(); - rmw_subscription_content_filtered_topic_options_t options = - rmw_get_zero_initialized_content_filtered_topic_options(); + rmw_subscription_content_filter_options_t options = + rmw_get_zero_initialized_content_filter_options(); EXPECT_EQ( RMW_RET_INVALID_ARGUMENT, - rmw_subscription_content_filtered_topic_options_fini(&options, nullptr)); + rmw_subscription_content_filter_options_fini(&options, nullptr)); rcutils_reset_error(); - EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filtered_topic_options_fini(&options, &allocator)); + EXPECT_EQ(RMW_RET_OK, rmw_subscription_content_filter_options_fini(&options, &allocator)); } diff --git a/rmw/test/test_subscription_options.cpp b/rmw/test/test_subscription_options.cpp index 37750e10..42660467 100644 --- a/rmw/test/test_subscription_options.cpp +++ b/rmw/test/test_subscription_options.cpp @@ -24,5 +24,5 @@ TEST(rmw_subscription_options, get_default_subscription_options) EXPECT_EQ( options.require_unique_network_flow_endpoints, RMW_UNIQUE_NETWORK_FLOW_ENDPOINTS_NOT_REQUIRED); - EXPECT_EQ(options.content_filtered_topic_options, nullptr); + EXPECT_EQ(options.content_filter_options, nullptr); } From 5f2abd7a97c0d16e4bb9dd2e6e7c8526089802bb Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Tue, 1 Mar 2022 13:59:05 +0800 Subject: [PATCH 10/14] update doc for parameters maximun size to fit the DDS specification Signed-off-by: Chen Lihui --- rmw/include/rmw/subscription_content_filter_options.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/rmw/include/rmw/subscription_content_filter_options.h b/rmw/include/rmw/subscription_content_filter_options.h index f6aa545b..ff557b9b 100644 --- a/rmw/include/rmw/subscription_content_filter_options.h +++ b/rmw/include/rmw/subscription_content_filter_options.h @@ -40,8 +40,7 @@ typedef struct RMW_PUBLIC_TYPE rmw_subscription_content_filter_options_s * filter_expression. The number of supplied parameters must fit with the requested values. * * It can be NULL if there is no "%n" tokens placeholder in filter_expression. - * The maximun size allowance depends on concrete DDS vendor. - * (i.e., it cannot be greater than 100 on RTI_Connext.) + * The maximun size allowance must be smaller than 100. */ rcutils_string_array_t * expression_parameters; } rmw_subscription_content_filter_options_t; From 643c0d04098911807e20abca7fb101a8877ce327 Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Tue, 1 Mar 2022 14:41:39 +0800 Subject: [PATCH 11/14] index number rather than size Signed-off-by: Chen Lihui --- rmw/include/rmw/subscription_content_filter_options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rmw/include/rmw/subscription_content_filter_options.h b/rmw/include/rmw/subscription_content_filter_options.h index ff557b9b..e0850a7d 100644 --- a/rmw/include/rmw/subscription_content_filter_options.h +++ b/rmw/include/rmw/subscription_content_filter_options.h @@ -40,7 +40,7 @@ typedef struct RMW_PUBLIC_TYPE rmw_subscription_content_filter_options_s * filter_expression. The number of supplied parameters must fit with the requested values. * * It can be NULL if there is no "%n" tokens placeholder in filter_expression. - * The maximun size allowance must be smaller than 100. + * The maximum index number must be smaller than 100. */ rcutils_string_array_t * expression_parameters; } rmw_subscription_content_filter_options_t; From da68d2b93f2877a994c6e86cc734a0ec828ad093 Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Thu, 10 Mar 2022 10:31:24 +0800 Subject: [PATCH 12/14] update api comments Signed-off-by: Chen Lihui --- rmw/include/rmw/subscription_content_filter_options.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rmw/include/rmw/subscription_content_filter_options.h b/rmw/include/rmw/subscription_content_filter_options.h index e0850a7d..f3d854e6 100644 --- a/rmw/include/rmw/subscription_content_filter_options.h +++ b/rmw/include/rmw/subscription_content_filter_options.h @@ -30,13 +30,13 @@ extern "C" typedef struct RMW_PUBLIC_TYPE rmw_subscription_content_filter_options_s { /** - * specify the criteria to select the data samples of interest. + * Specify the criteria to select the data samples of interest. * * It is similar to the WHERE part of an SQL clause. */ char * filter_expression; /** - * give values to the tokens placeholder ‘parameters’ (i.e., "%n" tokens begin from 0) in the + * Give values to the tokens placeholder ‘parameters’ (i.e., "%n" tokens begin from 0) in the * filter_expression. The number of supplied parameters must fit with the requested values. * * It can be NULL if there is no "%n" tokens placeholder in filter_expression. From 8d7d286692c10cc266bd7b90023320de2cd6cb31 Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Thu, 17 Mar 2022 10:19:30 +0800 Subject: [PATCH 13/14] use stack memory for rcutils_string_array_t Signed-off-by: Chen Lihui --- .../rmw/subscription_content_filter_options.h | 2 +- rmw/src/subscription_content_filter_options.c | 52 ++++++------------- ...st_subscription_content_filter_options.cpp | 26 +++++----- 3 files changed, 30 insertions(+), 50 deletions(-) diff --git a/rmw/include/rmw/subscription_content_filter_options.h b/rmw/include/rmw/subscription_content_filter_options.h index f3d854e6..b0a28a01 100644 --- a/rmw/include/rmw/subscription_content_filter_options.h +++ b/rmw/include/rmw/subscription_content_filter_options.h @@ -42,7 +42,7 @@ typedef struct RMW_PUBLIC_TYPE rmw_subscription_content_filter_options_s * It can be NULL if there is no "%n" tokens placeholder in filter_expression. * The maximum index number must be smaller than 100. */ - rcutils_string_array_t * expression_parameters; + rcutils_string_array_t expression_parameters; } rmw_subscription_content_filter_options_t; diff --git a/rmw/src/subscription_content_filter_options.c b/rmw/src/subscription_content_filter_options.c index f78bacfa..ad98962b 100644 --- a/rmw/src/subscription_content_filter_options.c +++ b/rmw/src/subscription_content_filter_options.c @@ -22,12 +22,10 @@ rmw_subscription_content_filter_options_t rmw_get_zero_initialized_content_filter_options() { - static rmw_subscription_content_filter_options_t zero_initialized_options = { - .filter_expression = NULL, - .expression_parameters = NULL, - }; - - return zero_initialized_options; + return (const rmw_subscription_content_filter_options_t) { + .filter_expression = NULL, + .expression_parameters = rcutils_get_zero_initialized_string_array() + }; // NOLINT(readability/braces): false positive } rmw_ret_t @@ -48,7 +46,6 @@ rmw_subscription_content_filter_options_init( rmw_ret_t ret = RMW_RET_OK; rcutils_ret_t rcutils_ret; char * new_filter_expression = NULL; - rcutils_string_array_t * new_expression_parameters = NULL; size_t i; new_filter_expression = rcutils_strdup(filter_expression, *allocator); @@ -59,16 +56,8 @@ rmw_subscription_content_filter_options_init( } if (expression_parameters_argc > 0) { - new_expression_parameters = - allocator->allocate(sizeof(rcutils_string_array_t), allocator->state); - if (!new_expression_parameters) { - RMW_SET_ERROR_MSG("failed to allocate expression parameters"); - ret = RMW_RET_BAD_ALLOC; - goto failed; - } - *new_expression_parameters = rcutils_get_zero_initialized_string_array(); rcutils_ret_t rcutils_ret = rcutils_string_array_init( - new_expression_parameters, expression_parameters_argc, allocator); + &options->expression_parameters, expression_parameters_argc, allocator); if (RCUTILS_RET_OK != rcutils_ret) { RMW_SET_ERROR_MSG("failed to init string array for expression parameters"); ret = RMW_RET_BAD_ALLOC; @@ -76,9 +65,9 @@ rmw_subscription_content_filter_options_init( } for (i = 0; i < expression_parameters_argc; i++) { - new_expression_parameters->data[i] = + options->expression_parameters.data[i] = rcutils_strdup(expression_parameter_argv[i], *allocator); - if (!new_expression_parameters->data[i]) { + if (!options->expression_parameters.data[i]) { RMW_SET_ERROR_MSG("failed to copy expression parameter"); ret = RMW_RET_BAD_ALLOC; goto clear_expression_parameters; @@ -87,18 +76,16 @@ rmw_subscription_content_filter_options_init( } options->filter_expression = new_filter_expression; - options->expression_parameters = new_expression_parameters; return RMW_RET_OK; clear_expression_parameters: - rcutils_ret = rcutils_string_array_fini(new_expression_parameters); + rcutils_ret = rcutils_string_array_fini(&options->expression_parameters); if (RCUTILS_RET_OK != rcutils_ret) { RCUTILS_SAFE_FWRITE_TO_STDERR("Failed to fini string array.\n"); } failed: - allocator->deallocate(new_expression_parameters, allocator->state); allocator->deallocate(new_filter_expression, allocator->state); return ret; @@ -135,12 +122,7 @@ rmw_subscription_content_filter_options_copy( RMW_CHECK_ARGUMENT_FOR_NULL(src, RMW_RET_INVALID_ARGUMENT); RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); RMW_CHECK_ARGUMENT_FOR_NULL(dst, RMW_RET_INVALID_ARGUMENT); - size_t expression_parameters_size = 0; - char ** expression_parameters_data = NULL; - if (src->expression_parameters) { - expression_parameters_size = src->expression_parameters->size; - expression_parameters_data = src->expression_parameters->data; - } + rmw_ret_t ret = rmw_subscription_content_filter_options_fini(dst, allocator); if (ret != RMW_RET_OK) { return ret; @@ -148,8 +130,8 @@ rmw_subscription_content_filter_options_copy( return rmw_subscription_content_filter_options_init( src->filter_expression, - expression_parameters_size, - (const char **)expression_parameters_data, + src->expression_parameters.size, + (const char **)src->expression_parameters.data, allocator, dst ); @@ -168,14 +150,10 @@ rmw_subscription_content_filter_options_fini( options->filter_expression = NULL; } - if (options->expression_parameters) { - rcutils_ret_t ret = rcutils_string_array_fini(options->expression_parameters); - if (RCUTILS_RET_OK != ret) { - RCUTILS_SAFE_FWRITE_TO_STDERR("Failed to fini string array.\n"); - return RMW_RET_ERROR; - } - allocator->deallocate(options->expression_parameters, allocator->state); - options->expression_parameters = NULL; + rcutils_ret_t ret = rcutils_string_array_fini(&options->expression_parameters); + if (RCUTILS_RET_OK != ret) { + RCUTILS_SAFE_FWRITE_TO_STDERR("Failed to fini string array.\n"); + return RMW_RET_ERROR; } return RMW_RET_OK; diff --git a/rmw/test/test_subscription_content_filter_options.cpp b/rmw/test/test_subscription_content_filter_options.cpp index d0f6d3c8..7cf689e5 100644 --- a/rmw/test/test_subscription_content_filter_options.cpp +++ b/rmw/test/test_subscription_content_filter_options.cpp @@ -25,7 +25,8 @@ TEST(rmw_subscription_content_filter_options, get_zero_init) rmw_subscription_content_filter_options_t options = rmw_get_zero_initialized_content_filter_options(); EXPECT_EQ(options.filter_expression, nullptr); - EXPECT_EQ(options.expression_parameters, nullptr); + EXPECT_EQ(options.expression_parameters.size, 0u); + EXPECT_EQ(options.expression_parameters.data, nullptr); } TEST(rmw_subscription_content_filter_options, options_init) @@ -33,7 +34,8 @@ TEST(rmw_subscription_content_filter_options, options_init) rmw_subscription_content_filter_options_t options = rmw_get_zero_initialized_content_filter_options(); EXPECT_EQ(options.filter_expression, nullptr); - EXPECT_EQ(options.expression_parameters, nullptr); + EXPECT_EQ(options.expression_parameters.size, 0u); + EXPECT_EQ(options.expression_parameters.data, nullptr); rcutils_allocator_t allocator = rcutils_get_default_allocator(); EXPECT_EQ( @@ -77,10 +79,9 @@ TEST(rmw_subscription_content_filter_options, options_init) &options)); EXPECT_STREQ(options.filter_expression, filter_expression); - ASSERT_NE(nullptr, options.expression_parameters); - ASSERT_EQ(expression_parameters_count, options.expression_parameters->size); + ASSERT_EQ(expression_parameters_count, options.expression_parameters.size); for (size_t i = 0; i < expression_parameters_count; ++i) { - EXPECT_STREQ(options.expression_parameters->data[i], expression_parameters[i]); + EXPECT_STREQ(options.expression_parameters.data[i], expression_parameters[i]); } EXPECT_EQ( @@ -93,7 +94,8 @@ TEST(rmw_subscription_content_filter_options, options_set) rmw_subscription_content_filter_options_t options = rmw_get_zero_initialized_content_filter_options(); EXPECT_EQ(options.filter_expression, nullptr); - EXPECT_EQ(options.expression_parameters, nullptr); + EXPECT_EQ(options.expression_parameters.size, 0u); + EXPECT_EQ(options.expression_parameters.data, nullptr); rcutils_allocator_t allocator = rcutils_get_default_allocator(); @@ -139,10 +141,9 @@ TEST(rmw_subscription_content_filter_options, options_set) &options)); EXPECT_STREQ(options.filter_expression, filter_expression); - ASSERT_NE(nullptr, options.expression_parameters); - ASSERT_EQ(expression_parameters_count, options.expression_parameters->size); + ASSERT_EQ(expression_parameters_count, options.expression_parameters.size); for (size_t i = 0; i < expression_parameters_count; ++i) { - EXPECT_STREQ(options.expression_parameters->data[i], expression_parameters[i]); + EXPECT_STREQ(options.expression_parameters.data[i], expression_parameters[i]); } EXPECT_EQ( @@ -185,7 +186,7 @@ TEST(rmw_subscription_content_filter_options, options_copy) { rcutils_reset_error(); rcutils_allocator_t failing_allocator = get_time_bomb_allocator(); - constexpr int expected_num_malloc_calls = 5; + constexpr int expected_num_malloc_calls = 4; for (int i = 0; i < expected_num_malloc_calls; ++i) { set_time_bomb_allocator_malloc_count(failing_allocator, i); EXPECT_EQ( @@ -204,7 +205,7 @@ TEST(rmw_subscription_content_filter_options, options_copy) { EXPECT_EQ( RCUTILS_RET_OK, rcutils_string_array_cmp( - source.expression_parameters, destination.expression_parameters, &res)); + &source.expression_parameters, &destination.expression_parameters, &res)); EXPECT_EQ(res, 0); { @@ -220,7 +221,8 @@ TEST(rmw_subscription_content_filter_options, options_copy) { RMW_RET_OK, rmw_subscription_content_filter_options_copy(&source2, &allocator, &destination)); EXPECT_STREQ(source2.filter_expression, destination.filter_expression); - EXPECT_EQ(nullptr, destination.expression_parameters); + EXPECT_EQ(source2.expression_parameters.size, 0u); + EXPECT_EQ(source2.expression_parameters.data, nullptr); EXPECT_EQ( RMW_RET_OK, rmw_subscription_content_filter_options_fini(&source2, &allocator)); } From f7e2abb3e6e8e0e7aa736a81e5d9467d9a30be1f Mon Sep 17 00:00:00 2001 From: Chen Lihui Date: Sat, 19 Mar 2022 10:45:32 +0800 Subject: [PATCH 14/14] use the helper function set directly for copy Signed-off-by: Chen Lihui --- rmw/src/subscription_content_filter_options.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/rmw/src/subscription_content_filter_options.c b/rmw/src/subscription_content_filter_options.c index ad98962b..44051745 100644 --- a/rmw/src/subscription_content_filter_options.c +++ b/rmw/src/subscription_content_filter_options.c @@ -123,12 +123,7 @@ rmw_subscription_content_filter_options_copy( RCUTILS_CHECK_ALLOCATOR(allocator, return RMW_RET_INVALID_ARGUMENT); RMW_CHECK_ARGUMENT_FOR_NULL(dst, RMW_RET_INVALID_ARGUMENT); - rmw_ret_t ret = rmw_subscription_content_filter_options_fini(dst, allocator); - if (ret != RMW_RET_OK) { - return ret; - } - - return rmw_subscription_content_filter_options_init( + return rmw_subscription_content_filter_options_set( src->filter_expression, src->expression_parameters.size, (const char **)src->expression_parameters.data,