Jump to content
OpenSplice DDS Forum
luca.gherardi

Instance state and view state

Recommended Posts

Hi all,

 

In order to understand better how Opensplice works I've modified the Hello World example in this way:

- The publisher sends at 50 Hz the Hello World message. Every time a new message is sent the userID field is increased by 1.

- The subscriber checks at 50 Hz if new messages are available, and in that case prints some information (see the code below)

- The subscriber data reader uses the take function, with the arguments reported below

ReturnCode_t status = HelloWorldReader->take(msgList, infoSeq, LENGTH_UNLIMITED, NOT_READ_SAMPLE_STATE, ANY_VIEW_STATE, ANY_INSTANCE_STATE);
checkStatus(status, "msgDataReader::take");
for (DDS::ULong j = 0; j < msgList.length(); j++) {

  cout << "userID  : " << msgList[j].userID 
       << " - Msg: " << msgList[j].message
       << " - Sample state: " << infoSeq[j].sample_state
       << " - Instance alive: " << infoSeq[j].instance_state
       << " - View state: " << infoSeq[j].view_state << endl;

}
status = HelloWorldReader->return_loan(msgList, infoSeq);

If I run subscriber and publisher, let the publisher writing some messages (e.g. 100), and then stop the publisher but not the subscriber:

  • The subscriber regularly receives the 100 messages with the following states: Sample state: 2 - Instance alive: 1 - View state: 1
  • As soon as the data writer, publisher, topic, and participant are deleted, the subscriber receives again the same 100 messages. However this time the states are:  Sample state: 2 - Instance alive: 4 - View state: 2

Now, I know that I could configure the take function in such a way to receive only messages from alive instances and not viewed before.

However I would like to understand why these messages are received a second time.

 

Some additional information:

  • I configured the topic to have a VOLATILE durability QoS
  • I'm using open splice under Ubuntu 14.04, compiler GCC, default XML configuration file, and latest version downloaded from github.

Thanks,
Luca

Share this post


Link to post
Share on other sites

Hi Luca

 

I think the messages you are receiving the second time are the so-called "dummy" samples that DDS delivers to inform the subscriber side about status changes when there is no existing sample in the reader cache.  That makes sense here because you are using "take" which of course removes samples from the cache each time.

 

The instance state the second time is 4, which I suspect is NOT_ALIVE_NO_WRITERS and would tie in with the that theory.

 

One thing you could change in the code to verify that is to check the valid_data flag of each sampleInfo.  DDS sets the valid_data flag to true when it corresponds to data that has actually been sent by the user, and false otherwise (indicating a dummy sample as described above).  Hopefully printing that flag will show that - otherwise I'm barking up the wrong tree ;)

 

The idea is that you should only interpret the actual sample data where the valid_data flag is true (I guess that was just left out of the example you've got)

 

 

Best,

James

Share this post


Link to post
Share on other sites

Hi James,

 

Just a last question on this topic.

Is it guaranteed that when I call the take functions with parameters 

- DDS::NOT_READ_SAMPLE_STATE

- DDS::ANY_VIEW_STATE

- DDS::ALIVE_INSTANCE_STATE

The returned sample will always be valid (i.e. valid_data flag set to true).

 

If not, is there a way to retrieve only valid data?

 

Thanks,
Luca

Share this post


Link to post
Share on other sites

Hi James, 

 

thanks for the answer.

 

I read the post and it looks interesting.

However the CPP reference manual states that the policy 'reader_data_lifecycle.enable_invalid_samples' is deprecated and should be replaced by 'reader_data_lifecycle.invalid_sample_visibility'.

 

Does setting reader_data_lifecycle.invalid_sample_visibility to NO_INVALID_SAMPLES as the same effect as setting reader_data_lifecycle.enable_invalid_samples to false?

 

The documentation says that "applications will be notified of instance_state change only if there is a sample available in the data reader". I guess that this is a sample that has not yet been taken. What would be the instance_state of this sample?

 

In other words, if I set reader_data_lifecycle.invalid_sample_visibility to NO_INVALID_SAMPLES am I guaranteed that I will never receive a invalid sample when I use the options DDS::NOT_READ_SAMPLE_STATE, DDS::ANY_VIEW_STATE, and DDS::ALIVE_INSTANCE_STATE with the Take function?

 

Thanks,
Luca

 

Share this post


Link to post
Share on other sites

Hi James,

 

I'm just trying to figure out which one is the best away to abstract all the information returned by the take function without affecting to much the performances.

 

Thanks,

Luca

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

×