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 DDSContentFilteredTopic (the function called is shown in parenthesis).
See DDSContentFilter::compile for details.
See DDSContentFilter::evaluate for details.
See DDSContentFilter::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 MyContentFilter::compile( void** new_compile_data, const char * /* expression */, const DDS_StringSeq& parameters,const DDS_TypeCode* /* type_code */, const char * /* type_class_name */, void * /* old_compile_data */) { *new_compile_data = (void*)DDS_String_dup(parameters[0]); return DDS_RETCODE_OK; }
DDS_Boolean MyContentFilter::evaluate( 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 MyContentFilter::finalize( void* compile_data) { /* free parameter string from compile function */ DDS_String_free((char *)compile_data); }
DDSDomainParticipant *myParticipant=NULL; /* myParticipant = .... */ DDSContentFilter *myCustomFilter = new MyContentFilter(); if (myParticipant->register_contentfilter( (char*)"MyCustomFilter", myCustomFilter) != DDS_RETCODE_OK) { printf("Failed to register custom filter\n"); }
DDSDomainParticipant *myParticipant = NULL; /* myParticipant = .... */ DDSContentFilter *myCustomFilter = myParticipant->lookup_contentfilter((char*)"MyCustomFilter"); if (myCustomFilter != NULL) { if (myParticipant->unregister_contentfilter( (char*)"MyCustomFilter") != DDS_RETCODE_OK) { printf("Failed to unregister custom filter\n"); } delete myCustomFilter; }