Skip to content

Commit d48fb11

Browse files
author
Chen Lihui
authored
add content-filtered-topic interfaces (#894)
* to support a feature of content filtered topic Signed-off-by: Chen Lihui <Lihui.Chen@sony.com> * Update function description Signed-off-by: Chen Lihui <Lihui.Chen@sony.com> * Nit. Signed-off-by: Chen Lihui <Lihui.Chen@sony.com> * Update based on review Signed-off-by: Chen Lihui <lihui.chen@sony.com> * Not to reset error if subscrption is invalid. Signed-off-by: Chen Lihui <Lihui.Chen@sony.com> * remove copy function for subscription_options Signed-off-by: Chen Lihui <Lihui.Chen@sony.com> * update comments to make linelength <= 100 Signed-off-by: Chen Lihui <Lihui.Chen@sony.com> * Update comments Signed-off-by: Chen Lihui <Lihui.Chen@sony.com> * add test for filter data by all cft interfaces with rcl_take Signed-off-by: Chen Lihui <Lihui.Chen@sony.com> * update interface Signed-off-by: Chen Lihui <lihui.chen@sony.com> * update test Signed-off-by: Chen Lihui <lihui.chen@sony.com> * add lost test file Signed-off-by: Chen Lihui <lihui.chen@sony.com> * update test case Signed-off-by: Chen Lihui <lihui.chen@sony.com> * nit Signed-off-by: Chen Lihui <lihui.chen@sony.com> * fix for unsupported cft and unscrutify Signed-off-by: Chen Lihui <lihui.chen@sony.com> * fix unscrutify Signed-off-by: Chen Lihui <lihui.chen@sony.com> * rename Signed-off-by: Chen Lihui <lihui.chen@sony.com> * refactor test Signed-off-by: Chen Lihui <lihui.chen@sony.com> * fix for uncrustify and typo Signed-off-by: Chen Lihui <lihui.chen@sony.com> * relate to `rcutils_string_array_t expression_parameters` changed in rmw Signed-off-by: Chen Lihui <lihui.chen@sony.com> * add necessary structure for fallback interfaces Signed-off-by: Chen Lihui <lihui.chen@sony.com> * remove the implementation temporary, add them with fallback in the feature use stack/inline storage Signed-off-by: Chen Lihui <lihui.chen@sony.com> * address comments Signed-off-by: Chen Lihui <lihui.chen@sony.com> * update comments Signed-off-by: Chen Lihui <lihui.chen@sony.com> * add DDS content filter implementation without fallback Signed-off-by: Chen Lihui <lihui.chen@sony.com> * waiting to allow for filter propagation Signed-off-by: Chen Lihui <lihui.chen@sony.com> * use = instead of match symbol as it is not standard Signed-off-by: Chen Lihui <lihui.chen@sony.com> * remove unnecessary code and update error message Signed-off-by: Chen Lihui <lihui.chen@sony.com> * update test case name and use BasicTypes Signed-off-by: Chen Lihui <lihui.chen@sony.com> * use the rcl_subscription_option_t allocator instead Signed-off-by: Chen Lihui <lihui.chen@sony.com> * set the option data directly seems a bit more complicated Signed-off-by: Chen Lihui <lihui.chen@sony.com> * explicitly check the cft supported by rmw_connextdds and rmw_fastrtps_cpp Signed-off-by: Chen Lihui <lihui.chen@sony.com> * increase the maximun time for events and content filter propagation Signed-off-by: Chen Lihui <lihui.chen@sony.com> * set test timeout to 120 Signed-off-by: Chen Lihui <lihui.chen@sony.com>
1 parent 35a31b0 commit d48fb11

5 files changed

Lines changed: 1427 additions & 2 deletions

File tree

rcl/include/rcl/subscription.h

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ typedef struct rcl_subscription_options_s
5353
rmw_subscription_options_t rmw_subscription_options;
5454
} rcl_subscription_options_t;
5555

56+
typedef struct rcl_subscription_content_filter_options_s
57+
{
58+
rmw_subscription_content_filter_options_t rmw_subscription_content_filter_options;
59+
} rcl_subscription_content_filter_options_t;
60+
5661
/// Return a rcl_subscription_t struct with members set to `NULL`.
5762
/**
5863
* Should be called to get a null rcl_subscription_t before passing to
@@ -209,6 +214,225 @@ RCL_WARN_UNUSED
209214
rcl_subscription_options_t
210215
rcl_subscription_get_default_options(void);
211216

217+
/// Reclaim resources held inside rcl_subscription_options_t structure.
218+
/**
219+
* <hr>
220+
* Attribute | Adherence
221+
* ------------------ | -------------
222+
* Allocates Memory | Yes
223+
* Thread-Safe | No
224+
* Uses Atomics | No
225+
* Lock-Free | No
226+
*
227+
* \param[in] option The structure which its resources have to be deallocated.
228+
* \return `RCL_RET_OK` if the memory was successfully freed, or
229+
* \return `RCL_RET_INVALID_ARGUMENT` if option is NULL, or
230+
* \return `RCL_RET_BAD_ALLOC` if deallocating memory fails.
231+
*/
232+
RCL_PUBLIC
233+
RCL_WARN_UNUSED
234+
rcl_ret_t
235+
rcl_subscription_options_fini(rcl_subscription_options_t * option);
236+
237+
/// Set the content filter options for the given subscription options.
238+
/**
239+
* <hr>
240+
* Attribute | Adherence
241+
* ------------------ | -------------
242+
* Allocates Memory | Yes
243+
* Thread-Safe | No
244+
* Uses Atomics | No
245+
* Lock-Free | No
246+
*
247+
* \param[in] filter_expression The filter expression is similar to the WHERE part of an SQL clause.
248+
* \param[in] expression_parameters_argc The maximum of expression parameters argc is 100.
249+
* \param[in] expression_parameter_argv The expression parameters argv are the tokens placeholder
250+
* ‘parameters’ (i.e., "%n" tokens begin from 0) in the filter_expression.
251+
*
252+
* It can be NULL if there is no "%n" tokens placeholder in filter_expression.
253+
* \param[out] options The subscription options to be set.
254+
* \return `RCL_RET_OK` if set options successfully, or
255+
* \return `RCL_RET_INVALID_ARGUMENT` if arguments invalid, or
256+
* \return `RCL_RET_BAD_ALLOC` if allocating memory fails.
257+
*/
258+
RCL_PUBLIC
259+
RCL_WARN_UNUSED
260+
rcl_ret_t
261+
rcl_subscription_options_set_content_filter_options(
262+
const char * filter_expression,
263+
size_t expression_parameters_argc,
264+
const char * expression_parameter_argv[],
265+
rcl_subscription_options_t * options);
266+
267+
/// Return the zero initialized subscription content filter options.
268+
RCL_PUBLIC
269+
RCL_WARN_UNUSED
270+
rcl_subscription_content_filter_options_t
271+
rcl_get_zero_initialized_subscription_content_filter_options(void);
272+
273+
/// Initialize the content filter options for the given subscription options.
274+
/**
275+
* <hr>
276+
* Attribute | Adherence
277+
* ------------------ | -------------
278+
* Allocates Memory | Yes
279+
* Thread-Safe | No
280+
* Uses Atomics | No
281+
* Lock-Free | No
282+
*
283+
* \param[in] subscription the handle to the subscription.
284+
* \param[in] filter_expression The filter expression is similar to the WHERE part of an SQL clause,
285+
* use empty ("") can reset (or clear) the content filter setting of a subscription.
286+
* \param[in] expression_parameters_argc The maximum of expression parameters argc is 100.
287+
* \param[in] expression_parameter_argv The expression parameters argv are the tokens placeholder
288+
* ‘parameters’ (i.e., "%n" tokens begin from 0) in the filter_expression.
289+
*
290+
* It can be NULL if there is no "%n" tokens placeholder in filter_expression.
291+
* \param[out] options The subscription options to be set.
292+
* \return `RCL_RET_OK` if set options successfully, or
293+
* \return `RCL_RET_SUBSCRIPTION_INVALID` if subscription is invalid, or
294+
* \return `RCL_RET_INVALID_ARGUMENT` if arguments invalid, or
295+
* \return `RCL_RET_BAD_ALLOC` if allocating memory fails.
296+
*/
297+
RCL_PUBLIC
298+
RCL_WARN_UNUSED
299+
rcl_ret_t
300+
rcl_subscription_content_filter_options_init(
301+
const rcl_subscription_t * subscription,
302+
const char * filter_expression,
303+
size_t expression_parameters_argc,
304+
const char * expression_parameter_argv[],
305+
rcl_subscription_content_filter_options_t * options);
306+
307+
/// Set the content filter options for the given subscription options.
308+
/**
309+
* <hr>
310+
* Attribute | Adherence
311+
* ------------------ | -------------
312+
* Allocates Memory | Yes
313+
* Thread-Safe | No
314+
* Uses Atomics | No
315+
* Lock-Free | No
316+
*
317+
* \param[in] subscription the handle to the subscription.
318+
* \param[in] filter_expression The filter expression is similar to the WHERE part of an SQL clause,
319+
* use empty ("") can reset (or clear) the content filter setting of a subscription.
320+
* \param[in] expression_parameters_argc The maximum of expression parameters argc is 100.
321+
* \param[in] expression_parameter_argv The expression parameters argv are the tokens placeholder
322+
* ‘parameters’ (i.e., "%n" tokens begin from 0) in the filter_expression.
323+
*
324+
* It can be NULL if there is no "%n" tokens placeholder in filter_expression.
325+
* \param[out] options The subscription options to be set.
326+
* \return `RCL_RET_OK` if set options successfully, or
327+
* \return `RCL_RET_SUBSCRIPTION_INVALID` if subscription is invalid, or
328+
* \return `RCL_RET_INVALID_ARGUMENT` if arguments invalid, or
329+
* \return `RCL_RET_BAD_ALLOC` if allocating memory fails.
330+
*/
331+
RCL_PUBLIC
332+
RCL_WARN_UNUSED
333+
rcl_ret_t
334+
rcl_subscription_content_filter_options_set(
335+
const rcl_subscription_t * subscription,
336+
const char * filter_expression,
337+
size_t expression_parameters_argc,
338+
const char * expression_parameter_argv[],
339+
rcl_subscription_content_filter_options_t * options);
340+
341+
/// Reclaim rcl_subscription_content_filter_options_t structure.
342+
/**
343+
* <hr>
344+
* Attribute | Adherence
345+
* ------------------ | -------------
346+
* Allocates Memory | Yes
347+
* Thread-Safe | No
348+
* Uses Atomics | No
349+
* Lock-Free | No
350+
*
351+
* \param[in] subscription the handle to the subscription.
352+
* \param[in] options The structure which its resources have to be deallocated.
353+
* \return `RCL_RET_OK` if the memory was successfully freed, or
354+
* \return `RCL_RET_SUBSCRIPTION_INVALID` if subscription is invalid, or
355+
* \return `RCL_RET_INVALID_ARGUMENT` if option is NULL, or
356+
* if its allocator is invalid and the structure contains initialized memory.
357+
*/
358+
RCL_PUBLIC
359+
RCL_WARN_UNUSED
360+
rcl_ret_t
361+
rcl_subscription_content_filter_options_fini(
362+
const rcl_subscription_t * subscription,
363+
rcl_subscription_content_filter_options_t * options);
364+
365+
/// Check if the content filtered topic feature is enabled in the subscription.
366+
/**
367+
* Depending on the middleware and whether cft is enabled in the subscription.
368+
*
369+
* \return `true` if the content filtered topic of `subscription` is enabled, otherwise `false`
370+
*/
371+
RCL_PUBLIC
372+
RCL_WARN_UNUSED
373+
bool
374+
rcl_subscription_is_cft_enabled(const rcl_subscription_t * subscription);
375+
376+
/// Set the filter expression and expression parameters for the subscription.
377+
/**
378+
* This function will set a filter expression and an array of expression parameters
379+
* for the given subscription.
380+
*
381+
* <hr>
382+
* Attribute | Adherence
383+
* ------------------ | -------------
384+
* Allocates Memory | No
385+
* Thread-Safe | No
386+
* Uses Atomics | Maybe [1]
387+
* Lock-Free | Maybe [1]
388+
*
389+
* \param[in] subscription The subscription to set content filter options.
390+
* \param[in] options The rcl content filter options.
391+
* \return `RCL_RET_OK` if the query was successful, or
392+
* \return `RCL_RET_INVALID_ARGUMENT` if `subscription` is NULL, or
393+
* \return `RCL_RET_INVALID_ARGUMENT` if `options` is NULL, or
394+
* \return `RCL_RET_UNSUPPORTED` if the implementation does not support content filter topic, or
395+
* \return `RCL_RET_ERROR` if an unspecified error occurs.
396+
*/
397+
RCL_PUBLIC
398+
RCL_WARN_UNUSED
399+
rcl_ret_t
400+
rcl_subscription_set_content_filter(
401+
const rcl_subscription_t * subscription,
402+
const rcl_subscription_content_filter_options_t * options
403+
);
404+
405+
/// Retrieve the filter expression of the subscription.
406+
/**
407+
* This function will return an filter expression by the given subscription.
408+
*
409+
* <hr>
410+
* Attribute | Adherence
411+
* ------------------ | -------------
412+
* Allocates Memory | Yes
413+
* Thread-Safe | No
414+
* Uses Atomics | Maybe [1]
415+
* Lock-Free | Maybe [1]
416+
*
417+
* \param[in] subscription The subscription object to inspect.
418+
* \param[out] options The rcl content filter options.
419+
* It is up to the caller to finalize this options later on, using
420+
* rcl_subscription_content_filter_options_fini().
421+
* \return `RCL_RET_OK` if the query was successful, or
422+
* \return `RCL_RET_INVALID_ARGUMENT` if `subscription` is NULL, or
423+
* \return `RCL_RET_INVALID_ARGUMENT` if `options` is NULL, or
424+
* \return `RCL_RET_BAD_ALLOC` if memory allocation fails, or
425+
* \return `RCL_RET_UNSUPPORTED` if the implementation does not support content filter topic, or
426+
* \return `RCL_RET_ERROR` if an unspecified error occurs.
427+
*/
428+
RCL_PUBLIC
429+
RCL_WARN_UNUSED
430+
rcl_ret_t
431+
rcl_subscription_get_content_filter(
432+
const rcl_subscription_t * subscription,
433+
rcl_subscription_content_filter_options_t * options
434+
);
435+
212436
/// Take a ROS message from a topic using a rcl subscription.
213437
/**
214438
* It is the job of the caller to ensure that the type of the ros_message

0 commit comments

Comments
 (0)