About samples_info[i]->publication_handle

I got in trouble!!!SampleInfo structure in <> contains publication_handle...and the meaning is :
The publication handle is a unique identifier for the DataWriter who wrote this sample.

As I know,the publication handle is the id of the datawriter ...but when i use DataWriter::get_instance_handle() to output the infomation ,I found these are different, I don't know why , what the publication handle's actual meaning ...

the Infomation I want to get is that the actual datawriter who write the sample datareader read ...this is so difficult when there are two datawriter writer the same topic type,and the content is also the same ...when datareader read a sample , we don't know which datawriter writer it...

thank you !!!!!


Handles in DDS

It is possible to get some additional information about the DataWriter associated with a sample received by a DataReader. To do this, use the

DDS_DataReader_get_matched_publication_data( )

method. Provide the publication_handle from the relevant SampleInfo structure. This will give you information on the DataWriter that produced the sample, including it's QoS policy settings, its Topic, and its DomainParticipant. Here is an example:

DDS_ReturnCode_t retval;
DDS_PublicationBuiltinTopicData publication_data;

/* ... */

/* get info about a data writer identitifed by 'publication_handle' */

retval = DDS_DataReader_get_matched_publication_data(dr,

if (retval != DDS_RETCODE_OK)

printf("get_matched_publication_data failed: %s\n", DDS_error(retval));

/* use the 'publication_data' */

/* clean up */

Handles, in general, are relevant only within a DomainParticipant, so it is not possible to use them to directly map to an external Entity.

I hope this information helps you! Feel free to contact us directly at support@twinoakscomputing.com in addition to posting on this forum with any questions.