diff --git a/rmw/CMakeLists.txt b/rmw/CMakeLists.txt index 2795ee58..33530f30 100644 --- a/rmw/CMakeLists.txt +++ b/rmw/CMakeLists.txt @@ -25,6 +25,7 @@ include(cmake/configure_rmw_library.cmake) set(rmw_sources "src/allocators.c" + "src/content_filtered_topic_options.c" "src/convert_rcutils_ret_to_rmw_ret.c" "src/event.c" "src/init.c" diff --git a/rmw/include/rmw/rmw.h b/rmw/include/rmw/rmw.h index 7bc8ac27..12ff8e53 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" @@ -1115,11 +1116,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 @@ -1130,23 +1130,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] content_filtered_topic_options The content filtered topic options. + * Use `content_filtered_topic_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 @@ -1154,12 +1146,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_content_filtered_topic_options_t * content_filtered_topic_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 @@ -1170,20 +1161,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] content_filtered_topic_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 @@ -1191,8 +1177,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_content_filtered_topic_options_t * content_filtered_topic_options); /// Take an incoming ROS message. /** diff --git a/rmw/include/rmw/types.h b/rmw/include/rmw/types.h index 42a22c1d..06b5b82b 100644 --- a/rmw/include/rmw/types.h +++ b/rmw/include/rmw/types.h @@ -27,6 +27,7 @@ extern "C" // map rcutils specific log levels to rmw speicfic type #include +#include "rmw/content_filtered_topic_options.h" #include "rmw/events_statuses/events_statuses.h" #include "rmw/init.h" #include "rmw/init_options.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_content_filtered_topic_options_t * content_filtered_topic_options; } rmw_subscription_options_t; typedef struct RMW_PUBLIC_TYPE rmw_subscription_s 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..2450e651 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_content_filtered_topic_options + test_content_filtered_topic_options.cpp + # Append the directory of librmw so it is found at test time. + APPEND_LIBRARY_DIRS "$" +) +if(TARGET test_content_filtered_topic_options) + target_link_libraries(test_content_filtered_topic_options ${PROJECT_NAME}) +endif() 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); }