Why do I get a content filter compile error?
You might see the following messages in the DDS log.
PRESParticipant_createContentFilteredTopicPolicy:content filter compile error 1
or
PRESParticipant_createContentFilteredTopicPolicy:content filter compile error 2
Although the compile()
function considers these messages real errors, they are not necessarily errors to the application. If you are not catching these when log verbosity level is NDDS_CONFIG_LOG_VERBOSITY_ERROR
, these are not considered an error by the middleware and will not impact functionality.
What do these messages mean?
In our current implementation, compilation of the content filter occurs (1) when registering the content-filtered topic (CFT) with the DomainParticipant or (2) upon receiving a CFT expression during discovery. In the latter case, the DomainParticipant will try to compile the CFT expression regardless of whether you have a reader or writer registered for this topic. One might later register a matching writer and want to do writer-side filtering. Thus currently we do the compilation upon discovery of the CFT reader.
Compiling the content filter expression requires both the expression and the type definition. When you register a CFT, both the expression and type definition are available. When compiling upon a discovery event, the implementation is slightly different depending on the language of your application. When the application is C/C++, we look for the type definition in the discovery data. When the application is written in Java, we use the package name from the discovery data and use reflexion to find out if the type has been registered with the DomainParticipant.
What does compile error 1 mean?
- If you see this message when discovering a CFT reader, this is a warning. (Note: before version 4.4d, this was incorrectly reported in this use case as an error.) If the application is written in C/C++, it is possible that we did not receive the typecode. This occurs when the CFT reader application was not able to send the typecode, likely because the typecode was larger than
participant_qos.resource_limits.type_code_max_serialized_length
(the default is 2000). In this case, the only impact is that a matching writer will not do any filtering -- all the filtering will occur on the reader side. Nevertheless, the data will be filtered correctly.
If you see this message when registering a CFT, this is indicative of a real error. Here are some potential reasons for seeing a content filter compile error:
- Incorrect content-filter length
When creating a ContentFilteredTopic, make sure that the filter's size does not exceed
contentfilter_property_max_length
in the DomainParticipantResourceLimits QoS policy. If the filter data is larger thancontentfilter_property_max_length
, you will see the compile error 1 when creating the ContentFilteredTopic.contentfilter_property_max_length
is the maximum length of all data related to aContentFilteredTopic
. It is the sum of the lengths of:- the content filter name,
- the related topic name,
- the filter expression,
- the filter parameters, and
- the filter name.
\0
') character. - Incorrect filter expression
Another common reason for seeing a compile error has to do with quotation marks used in strings. If there is a string in the expression, it must be enclosed in single-quotes. For example, the expression could be:
“mystring = ‘hello’”
Or, if you are using a parameter value, the expression would look like this:
“mystring = %0”
And the parameter would look like this (notice the singe quotes surrounding hello):param[0] = DDS_String_dup(“’hello’”);
The expression should not look like this; it would cause a compile error:
// Wrong! “mystring = ‘%0’” param[0] = “hello”;
- Incorrect content-filter length
What does compile error 2 mean?
Compile error 2 indicates that the type has not been registered with the DomainParticipant, so the middleware cannot find the type definition and complete the compilation. This error is expected when your application is written in Java. The only impact is that, if a matching writer is created later, content filtering will occur on the reader side, not on the writer side. Nevertheless, to the receiving application, data will be filtered correctly.
Comments
fercs77
Sun, 10/25/2020 - 15:46
Permalink
Update for new releases
Connext DDS 5.0.0 and higher
The compilation of the content filter from a remote DataReader is not done when the remote DataReader is discovered but when the remote DataReader is matched with a DataWriter. Also, the compilation is done using the local TypeCode and not the remote TypeCode. Therefore:
The CFT errors are more specific than in previous releases. For example, when you don't use quotation marks used in strings (“mystring = hello”) you will get the following error:
Connext DDS 6.0.0 and higher
Code Generator no longer supports the -notypecode option. Because of that you cannot get CFT errors because the type is not available.