Skip to content

Commit

Permalink
add content-filtered-topic interfaces (#894)
Browse files Browse the repository at this point in the history
* to support a feature of content filtered topic

Signed-off-by: Chen Lihui <[email protected]>

* Update function description

Signed-off-by: Chen Lihui <[email protected]>

* Nit.

Signed-off-by: Chen Lihui <[email protected]>

* Update based on review

Signed-off-by: Chen Lihui <[email protected]>

* Not to reset error if subscrption is invalid.

Signed-off-by: Chen Lihui <[email protected]>

* remove copy function for subscription_options

Signed-off-by: Chen Lihui <[email protected]>

* update comments to make linelength <= 100

Signed-off-by: Chen Lihui <[email protected]>

* Update comments

Signed-off-by: Chen Lihui <[email protected]>

* add test for filter data by all cft interfaces with rcl_take

Signed-off-by: Chen Lihui <[email protected]>

* update interface

Signed-off-by: Chen Lihui <[email protected]>

* update test

Signed-off-by: Chen Lihui <[email protected]>

* add lost test file

Signed-off-by: Chen Lihui <[email protected]>

* update test case

Signed-off-by: Chen Lihui <[email protected]>

* nit

Signed-off-by: Chen Lihui <[email protected]>

* fix for unsupported cft and unscrutify

Signed-off-by: Chen Lihui <[email protected]>

* fix unscrutify

Signed-off-by: Chen Lihui <[email protected]>

* rename

Signed-off-by: Chen Lihui <[email protected]>

* refactor test

Signed-off-by: Chen Lihui <[email protected]>

* fix for uncrustify and typo

Signed-off-by: Chen Lihui <[email protected]>

* relate to `rcutils_string_array_t expression_parameters` changed in rmw

Signed-off-by: Chen Lihui <[email protected]>

* add necessary structure for fallback interfaces

Signed-off-by: Chen Lihui <[email protected]>

* remove the implementation temporary, add them with fallback in the feature

use stack/inline storage

Signed-off-by: Chen Lihui <[email protected]>

* address comments

Signed-off-by: Chen Lihui <[email protected]>

* update comments

Signed-off-by: Chen Lihui <[email protected]>

* add DDS content filter implementation without fallback

Signed-off-by: Chen Lihui <[email protected]>

* waiting to allow for filter propagation

Signed-off-by: Chen Lihui <[email protected]>

* use = instead of match symbol as it is not standard

Signed-off-by: Chen Lihui <[email protected]>

* remove unnecessary code and update error message

Signed-off-by: Chen Lihui <[email protected]>

* update test case name and use BasicTypes

Signed-off-by: Chen Lihui <[email protected]>

* use the rcl_subscription_option_t allocator instead

Signed-off-by: Chen Lihui <[email protected]>

* set the option data directly

seems a bit more complicated

Signed-off-by: Chen Lihui <[email protected]>

* explicitly check the cft supported by rmw_connextdds and rmw_fastrtps_cpp

Signed-off-by: Chen Lihui <[email protected]>

* increase the maximun time for events and content filter propagation

Signed-off-by: Chen Lihui <[email protected]>

* set test timeout to 120

Signed-off-by: Chen Lihui <[email protected]>
  • Loading branch information
Chen Lihui authored Apr 4, 2022
1 parent 35a31b0 commit d48fb11
Show file tree
Hide file tree
Showing 5 changed files with 1,427 additions and 2 deletions.
224 changes: 224 additions & 0 deletions rcl/include/rcl/subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ typedef struct rcl_subscription_options_s
rmw_subscription_options_t rmw_subscription_options;
} rcl_subscription_options_t;

typedef struct rcl_subscription_content_filter_options_s
{
rmw_subscription_content_filter_options_t rmw_subscription_content_filter_options;
} rcl_subscription_content_filter_options_t;

/// Return a rcl_subscription_t struct with members set to `NULL`.
/**
* Should be called to get a null rcl_subscription_t before passing to
Expand Down Expand Up @@ -209,6 +214,225 @@ RCL_WARN_UNUSED
rcl_subscription_options_t
rcl_subscription_get_default_options(void);

/// Reclaim resources held inside rcl_subscription_options_t structure.
/**
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | Yes
* Thread-Safe | No
* Uses Atomics | No
* Lock-Free | No
*
* \param[in] option The structure which its resources have to be deallocated.
* \return `RCL_RET_OK` if the memory was successfully freed, or
* \return `RCL_RET_INVALID_ARGUMENT` if option is NULL, or
* \return `RCL_RET_BAD_ALLOC` if deallocating memory fails.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_subscription_options_fini(rcl_subscription_options_t * option);

/// Set the content filter options for the given subscription options.
/**
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | Yes
* Thread-Safe | No
* Uses Atomics | No
* Lock-Free | No
*
* \param[in] filter_expression The filter expression is similar to the WHERE part of an SQL clause.
* \param[in] expression_parameters_argc The maximum of expression parameters argc is 100.
* \param[in] expression_parameter_argv The expression parameters argv are the tokens placeholder
* ‘parameters’ (i.e., "%n" tokens begin from 0) in the filter_expression.
*
* It can be NULL if there is no "%n" tokens placeholder in filter_expression.
* \param[out] options The subscription options to be set.
* \return `RCL_RET_OK` if set options successfully, or
* \return `RCL_RET_INVALID_ARGUMENT` if arguments invalid, or
* \return `RCL_RET_BAD_ALLOC` if allocating memory fails.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_subscription_options_set_content_filter_options(
const char * filter_expression,
size_t expression_parameters_argc,
const char * expression_parameter_argv[],
rcl_subscription_options_t * options);

/// Return the zero initialized subscription content filter options.
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_subscription_content_filter_options_t
rcl_get_zero_initialized_subscription_content_filter_options(void);

/// Initialize the content filter options for the given subscription options.
/**
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | Yes
* Thread-Safe | No
* Uses Atomics | No
* Lock-Free | No
*
* \param[in] subscription the handle to the subscription.
* \param[in] filter_expression The filter expression is similar to the WHERE part of an SQL clause,
* use empty ("") can reset (or clear) the content filter setting of a subscription.
* \param[in] expression_parameters_argc The maximum of expression parameters argc is 100.
* \param[in] expression_parameter_argv The expression parameters argv are the tokens placeholder
* ‘parameters’ (i.e., "%n" tokens begin from 0) in the filter_expression.
*
* It can be NULL if there is no "%n" tokens placeholder in filter_expression.
* \param[out] options The subscription options to be set.
* \return `RCL_RET_OK` if set options successfully, or
* \return `RCL_RET_SUBSCRIPTION_INVALID` if subscription is invalid, or
* \return `RCL_RET_INVALID_ARGUMENT` if arguments invalid, or
* \return `RCL_RET_BAD_ALLOC` if allocating memory fails.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_subscription_content_filter_options_init(
const rcl_subscription_t * subscription,
const char * filter_expression,
size_t expression_parameters_argc,
const char * expression_parameter_argv[],
rcl_subscription_content_filter_options_t * options);

/// Set the content filter options for the given subscription options.
/**
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | Yes
* Thread-Safe | No
* Uses Atomics | No
* Lock-Free | No
*
* \param[in] subscription the handle to the subscription.
* \param[in] filter_expression The filter expression is similar to the WHERE part of an SQL clause,
* use empty ("") can reset (or clear) the content filter setting of a subscription.
* \param[in] expression_parameters_argc The maximum of expression parameters argc is 100.
* \param[in] expression_parameter_argv The expression parameters argv are the tokens placeholder
* ‘parameters’ (i.e., "%n" tokens begin from 0) in the filter_expression.
*
* It can be NULL if there is no "%n" tokens placeholder in filter_expression.
* \param[out] options The subscription options to be set.
* \return `RCL_RET_OK` if set options successfully, or
* \return `RCL_RET_SUBSCRIPTION_INVALID` if subscription is invalid, or
* \return `RCL_RET_INVALID_ARGUMENT` if arguments invalid, or
* \return `RCL_RET_BAD_ALLOC` if allocating memory fails.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_subscription_content_filter_options_set(
const rcl_subscription_t * subscription,
const char * filter_expression,
size_t expression_parameters_argc,
const char * expression_parameter_argv[],
rcl_subscription_content_filter_options_t * options);

/// Reclaim rcl_subscription_content_filter_options_t structure.
/**
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | Yes
* Thread-Safe | No
* Uses Atomics | No
* Lock-Free | No
*
* \param[in] subscription the handle to the subscription.
* \param[in] options The structure which its resources have to be deallocated.
* \return `RCL_RET_OK` if the memory was successfully freed, or
* \return `RCL_RET_SUBSCRIPTION_INVALID` if subscription is invalid, or
* \return `RCL_RET_INVALID_ARGUMENT` if option is NULL, or
* if its allocator is invalid and the structure contains initialized memory.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_subscription_content_filter_options_fini(
const rcl_subscription_t * subscription,
rcl_subscription_content_filter_options_t * options);

/// Check if the content filtered topic feature is enabled in the subscription.
/**
* Depending on the middleware and whether cft is enabled in the subscription.
*
* \return `true` if the content filtered topic of `subscription` is enabled, otherwise `false`
*/
RCL_PUBLIC
RCL_WARN_UNUSED
bool
rcl_subscription_is_cft_enabled(const rcl_subscription_t * subscription);

/// 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.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | No
* Thread-Safe | No
* Uses Atomics | Maybe [1]
* Lock-Free | Maybe [1]
*
* \param[in] subscription The subscription to set content filter options.
* \param[in] options The rcl content filter options.
* \return `RCL_RET_OK` if the query was successful, or
* \return `RCL_RET_INVALID_ARGUMENT` if `subscription` is NULL, or
* \return `RCL_RET_INVALID_ARGUMENT` if `options` is NULL, or
* \return `RCL_RET_UNSUPPORTED` if the implementation does not support content filter topic, or
* \return `RCL_RET_ERROR` if an unspecified error occurs.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_subscription_set_content_filter(
const rcl_subscription_t * subscription,
const rcl_subscription_content_filter_options_t * options
);

/// Retrieve the filter expression of the subscription.
/**
* This function will return an filter expression by the given subscription.
*
* <hr>
* Attribute | Adherence
* ------------------ | -------------
* Allocates Memory | Yes
* Thread-Safe | No
* Uses Atomics | Maybe [1]
* Lock-Free | Maybe [1]
*
* \param[in] subscription The subscription object to inspect.
* \param[out] options The rcl content filter options.
* It is up to the caller to finalize this options later on, using
* rcl_subscription_content_filter_options_fini().
* \return `RCL_RET_OK` if the query was successful, or
* \return `RCL_RET_INVALID_ARGUMENT` if `subscription` is NULL, or
* \return `RCL_RET_INVALID_ARGUMENT` if `options` is NULL, or
* \return `RCL_RET_BAD_ALLOC` if memory allocation fails, or
* \return `RCL_RET_UNSUPPORTED` if the implementation does not support content filter topic, or
* \return `RCL_RET_ERROR` if an unspecified error occurs.
*/
RCL_PUBLIC
RCL_WARN_UNUSED
rcl_ret_t
rcl_subscription_get_content_filter(
const rcl_subscription_t * subscription,
rcl_subscription_content_filter_options_t * options
);

/// Take a ROS message from a topic using a rcl subscription.
/**
* It is the job of the caller to ensure that the type of the ros_message
Expand Down
Loading

0 comments on commit d48fb11

Please sign in to comment.