AppCreator & Use of Keyed Type with Enumeration

6 posts / 0 new
Last post
Offline
Last seen: 11 years 1 month ago
Joined: 02/05/2013
Posts: 16
AppCreator & Use of Keyed Type with Enumeration

Hello-

We have adopted App Creator as a way of defining a public interface contract between a number of participants in our distributed system.  Some topics appear to be good candidates for "keying".  To be explicit I wish to define all possible instances (keys) in the interface.  To do this, we figure using an enumeration type in the IDL as the keyed field would work well.  Furthermore, we expect to use Content Filters to limit receipt of data to only those other readers that are interested in instances of interest.  I think we can achieve writer-side filtering as a bonus.

Mixed with App Creator & IDL-defined types, is this possible?  The content filter in XML refers to an enumeration in a "user defined" type. I believe compilation of the content filter occurs at RTI library load time, even before we are able to register all our user-defined types. The code is failing now at startup and I suspect this is why.

Here's an example type:

module General {
  enum IDLType_TestType_Keys {
    KEY_1,
    KEY_2,
    KEY_3
  }; //@top-level false
 

  struct IDLType_Test {
    IDLType_TestType_Keys key; //@key
    unsigned long value;
  }; //@resolve-name LANG_SPEC custom processing
  //@top-level true
};

Any insight would be appreciated.

Thanks-

Todd

asanchez's picture
Offline
Last seen: 4 years 6 months ago
Joined: 11/16/2011
Posts: 50

Hello Todd,


It is possible to use user-generated types with content filter together in XML App Creator. They are orthogonal features, meaning you can use content filter without type generation, viceversa or both. I don't know what problem you are experiencing, so I would appreciate if you could post the output of your application.

Something that I don't understand though is the "user-defined" enumeration value that you mention. Assuming that you're using SQL, as far as I know there shouldn't be any limitation with enumerated types, and from the XML there shouldn't be any incompability either. However, when specifying a SQL expression through XML we have to be careful with special symbols such as "<" and ">". Before getting there,  I would like to review with you the process of using user-generated types and content filters with XML App Creator. Let's see the two key steps for that:

  • User-generated types: A type in XML shall look like this:
<register_type name="registeredTypeName" kind="userGenerated"/>

The key here is to set the kind to "userGenerated" (which in this case this enumeration value is possible) and call DDS_DomainParticipantFactory_register_type_support_exp to supply the registration of the types before you call DDS_DomainParticipantFactory_create_participant_from_config_exp.

  • Define a filter within a DataReader tag:
<data_reader name="reader" topic_ref="topic">
	<filter name="filteredTopic" kind="builtin.sql">
		<expression>myField &lt; %0</expression>
		<parameter_list>
			<param>myParam</param>
		</parameter_list>
	</filter>
</data_reader>

In this case, the DataReader will be created from a content filter topic whose filter class is the built-in SQL. So with the "kind" attribute you can specify the filter class to be used, and the two possible values allowed by the schema are builtin.sql and builtin.stringMatch, hence no custom filters are possible.

An important part for the <filter> tag is the <expression> element. This is parsed data, and as such, we cannot use invalid characters that will result in a parsing error. For the SQL case, there are many of those characters. For instance in the example above, we want to use the expression "myField < %0". However this canot be written right away in the XML since "<" is not allowed, and it must be replaced with "&lt;".

For the question of the filter compilation, if you're referring to when the "compile" operation is called, this occurs several times along the lifecycle of the content filter topic, but the first time occurs on ContentFitleredTopic creation. The only requirement for this to work is that a ContentFilter object for a specified filter class must be already registered in the DomainParticipant (similar to type registration).

So in order for XML APP Creation to support custom filter, I would suggest the feature must be able to load a dynamic library containing the filter implemenation, so that it can create a corresponding ContentFilter object to be registered with participants. The library along with the entry point can be specified via XML, and then filter kind could support a "user-generated" value the same way as the <register_type>.

Let me know any other question.

Antonio

Offline
Last seen: 11 years 1 month ago
Joined: 02/05/2013
Posts: 16

Thanks for your quick reply, Antonio.

Let me elaborate on my scenario by adding to what I had already posted.

Assume that the XML does indeed register the type, such as:

<register_typename="RegisteredTypeName_General_Test"kind="userGenerated"/>

The IDL for my test type is shown above.  In the code, we register the actual class (this is modified a bit since we use a data-centric table of type and iterate the table):

DomainParticipantFactory.get_instance().register_type_support_exp(
             IDLType_TestTypeSupport.get_instance(),
             "RegisteredTypeName_General_Test" );

 For my example, I wish for the data reader to content filter such that it only receives data for instances keyed with KEY_1.  My best guess presently is to configure this as follows:

<data_readername="ReaderName_General_Test" topic_ref="TopicName_General_Test">
  <filtername="TopicName_General_Test" kind="builtin.sql">
          <expression>key = 'General.IDLType_TestType_Keys.KEY_1'</expression>
      
</filter>
    
</data_reader>

I do not specify parameters since it is, at least for this simple example, hardcoded against a concrete key value specified in the enumeration. Perhaps my expression is wrong but I believe from the SQL BNF that dot notation is supported.

I am not trying to use a custom filter so I don't think I need to register one via create_contentfilteredtopic_with_filter().

asanchez's picture
Offline
Last seen: 4 years 6 months ago
Joined: 11/16/2011
Posts: 50

Hi Todd,


I have created my own application with your IDL and filter configurations, and I got a compilation error. Even though the error message is little descriptive I figured out that the problem is in the expression: the enumerated value does not have the correct form. I took a look to the user's manual and in section 5.4.6.7 there is the syntax for enumerations. So for this use case, we would need to write it as follows:

key = 'KEY_1'

According to the documentation, only the enumerated value is needed without the fully qualified name as you were setting. This would have been easier to detect with better error messages, but at least we know that if you get an error like this:

[D0000|CREATE CFTopic|T=IDLTypeReader::IDLTypeFilter]PRESParticipant_createContentFilteredTopic:content filter compile error 1

that shows an error code equal to 1, then it is a compilation error due to a malformed expression.

Attached you can find the XML configuration file I used to reproduce your use case but with the correct expression. You can use it to verify if that works in your environment.

Let me know if this solves the problem.

Antonio

File Attachments: 
Offline
Last seen: 11 years 1 month ago
Joined: 02/05/2013
Posts: 16

Antonio-

I also worked the Content Filter Topc example from the website.  Indeed I am able to get the example working when the content filter is created programmatically, and you've demonstrated it when the type is define created in the XML..  I moved the type definition into the IDL and have that working now as well.

Technically I think the ' should be escaped in XML as well using &apos; but it appears to work in any event.

Thanks for your help yet again!

-Todd

asanchez's picture
Offline
Last seen: 4 years 6 months ago
Joined: 11/16/2011
Posts: 50

You're very welcome Todd! Glad I could help :)


Antonio