Jump to content
OpenSplice DDS Forum
Sign in to follow this  
slewman

content filter topic question

Recommended Posts

Im still semi new to OSPL, but, i cant seem to figure out how to use content filtered topics. Basically, what i am trying to do is create a data type as follows:

 

struct Host

{

string name;

long id;

};

#pragma keylist Host name

 

I will have multiple instances of "Host" under the same topic name, lets say we call it "SystemHosts", but, each instance will have a unique name (ie. "user1" user2" etc...). I believe I can subscribe to all updates to the "Host" type by simply subscribing to the topic name "SystemHosts" (please correct me if im wrong).

 

But, what if I am trying to find a specific instance of "Host" within the topic name "SystemHosts"? I know i can search for a topic name, but, if I have multiple instances of that type within the same topic name, how can I get access to all instances??

 

any help is greatly appreciated

 

thanks

Share this post


Link to post
Share on other sites

Hi Slewman,

 

A topic is basically a combinbation of a datatype (in this case "Host") and a set of QosPolicies applied to it (TopicQos). This combination can be given a unique name which we call topic name ("SystemHosts" in your case). So basically it is possible to have multiple topics of type "Host", each topic having its own Qos applied to it and each topic having its own unique name. Publication and Subscription is based on topic, so if I subscribe to topic "SystemHosts", it won't receive samples from any topic other than "SystemHosts", not even if some of those other topics are also specified to be of the "Host" datatype.

 

Once you subscribe to a topic, your reader will receive all instances of that topic ("user1", "user2", ..., "user[n]" in your case). By just using an ordinary read/take on your DataReader, you will receive an overview of all instances currently available. If you only want to access the sample of 1 particular instance, you can do a number of things:

  • You can apply a ContentFilter to your Reader. This content filter is expressed in terms of SQL and could in your case be written as "name = 'user1'" or "name = %0" where %0 represents a variable whose actual value you can manipulate at a later time using the set_expression_parameters function. Basically a filter prevents samples that do not match the filter expression from entering your DataReader. In the before-mentioned example this means that the Reader will never contain more than 1 instance. You apply a ContentFilter to a reader by first creating a ContentFilteredTopic (create_contentfilteredtopic on the DomainParticipant) where you specify your SQL expression, and then making your Reader subscribe to this ContentFilteredTopic instead of to the original topic.
  • You can lookup an instance by its keyfield. So instead of reading all instances from your Reader, you could create a dummy "Host" sample in which you specify the keyvalue that you are interested in (e.g. name = "user1"). You then pass this dummy sample to the lookup_instance operation on your DataReader, which returns to you an instance_handle, which is like the pointer to the administration of the instance that is represented by this particular keyvalue. If you want to access the latest state of this particular instance, you can invoke the read/take_instance operations passing the instance_handle you just obtained. You will then only get those samples that represent the instance in question. Mind you that this means the Reader contains ALL instances, but now only returns the samples belonging to 1 particular instance.
  • You can create a query in terms of SQL and apply the query to the content of the Reader. The SQL query is specified in a similar way as for the ContentFilteredTopic, but is now not applied at sample insertion time, but only at sample access time. That means the Reader still contains ALL instances, but you only access those instances that match the Query. You apply a Query by first creating a QueryCondition (create_querycondition on the DataReader) where you specify your SQL expression. You apply the query by using the read/take_w_condition operations on the DataReader where you pass the appriopriate QueryCondition as a parameter. The Reader will then only return samples that match your Query expression.

Which mechanism you prefer depends entirely on what you intent to do with the Data. Filters help you to save storage space in your datareader, but assume you don't have dynamic interest. (Once a sample has been blocked by the filter from entering your Reader, it cannot be undone by afterwards changing the filter parameters). Queries are more appropriate when your interest changes over time: your Reader has all information available but you dynamically focus on different parts of the data model. The read/take_instance is very lightweight and can be used when you want to the overhead of looking up an instance by key value only once, and then quickly access its latest value time and time again.

 

Hope that answers your questions.

 

Regards,

Erik Hendriks.

 

 

Share this post


Link to post
Share on other sites

Thank you so much for the help! Just one more quick question. The lookup_instance function returns a DDS_InstanceHandle_t, how exactly do i use this to access the data?

Share this post


Link to post
Share on other sites

See above. You can use it in combination with the read/take_instance operation on the DataReader where you pass the instance_handle you obtained by means of the lookup_instance to only access samples that match the instance you looked up by means of its keyvalue.

 

To get a little bit more feeling about Queries and Filters. read the Tutorial that comes with the OpenSplice release. Even more background can be found in the Reference Manuals that are also included with the product.

 

Regards,

Erik Hendriks.

Share this post


Link to post
Share on other sites

Haha yea, immediately after I posted my question I saw that. Again, I apologize ahead of time for the simplicity of my question, but, when I call a read on the instance_handle, where is the data that is read stored. Is it in either the DDS_sequence or the DDS_SampleInfoSeq?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×