This HOWTO explains how to write your own custom filter and is divided into the following sections:
A custom content filter is used by RTI Data Distribution Service at the following times during the life-time of a DDS_ContentFilteredTopic (the function called is shown in parenthesis).
See DDS_ContentFilter::compile for details.
See DDS_ContentFilter::evaluate for details.
See DDS_ContentFilter::finalize for details.
You want to write a custom filter function that will drop all samples where the value of Foo.x > x and x is a value determined by an expression parameter. The filter will only be used to filter samples of type Foo.
Below is the entire compile function.
DDS_ReturnCode_t howto_write_simple_compile_function(void *handle, void **new_compile_data, const char *expression, const struct DDS_StringSeq *parameters, const struct DDS_TypeCode *type_code, const char *type_class_name, void *old_compile_data) { *new_compile_data = (void*)DDS_String_dup(*DDS_StringSeq_get_reference(parameters,0)); return DDS_RETCODE_OK; }
DDS_Boolean howto_write_simple_evaluate_function(void *filter_data, void *compile_data, const void *sample) { char *parameter = (char*)compile_data; DDS_Long x; Foo *foo_sample = (Foo*)sample; sscanf(parameter,"%d",&x); return (foo_sample->x > x ? DDS_BOOLEAN_FALSE : DDS_BOOLEAN_TRUE); }
void howto_write_simple_finalize_function(void *filter_data, void *compile_data) { /* free parameter string from compile function */ DDS_String_free((char *)compile_data); }
struct DDS_ContentFilter filter = DDS_ContentFilter_INITIALIZER; filter.compile = howto_write_simple_compile_function; filter.evaluate = howto_write_simple_evaluate_function; filter.finalize = howto_write_simple_finalize_function; filter.filter_data = NULL; if (DDS_DomainParticipant_register_contentfilter( participant, "MyCustomFilter", &filter) != DDS_RETCODE_OK) { printf("Failed to register custom filter\n"); }
if (DDS_DomainParticipant_unregister_contentfilter( participant, "MyCustomFilter" ) != DDS_RETCODE_OK) { printf("Failed to unregister custom filter\n"); }