Get topic name of DataWriter that is leaving the domain

2 posts / 0 new
Last post
Last seen: 8 years 5 months ago
Joined: 09/18/2015
Posts: 5
Get topic name of DataWriter that is leaving the domain

What is the best way to get the topic name of a DataWriter that is leaving the domain.

I am currently subscribing to the topic 

_builtinPublicationReader = (DDSPublicationBuiltinTopicDataDataReader*)builtinSubscriber->lookup_datareader(DDS_PUBLICATION_TOPIC_NAME);
if(_builtinPublicationReader == NULL)
std::cerr <<; "Unable to retreive built-in Publication Reader." << std::endl;
return false;

The on_data_avaiable function is being called, but SampleInfo.valid_data if false and not TopicData is available.  I understand this is the expected behavior.  So, what is the best way to get the topic name? I have tried to use the publication instance handle that is provided in the SampleInfo, but I get the following error,  DDS_DomainParticipant_get_publication_data:ERROR: Bad parameter: publication_handle.

ajimenez's picture
Last seen: 1 year 10 months ago
Joined: 09/29/2017
Posts: 21
Hi Charles,
The way to collect information about DataWriter is using built-in discovery service.
In this Knowledge Base article, you can find information how to define them. 
The process to get the topic of a DataWriter leaving is using the built-in Topic
  • When a new DataWriter is matched, the instance_handle and the topic_name is saved in an std::map.
  • When a DataWriter is leaving, we can access to the instance_handle but not to the topic_name. Then the topic_name can be got from the instance_handle using the previous std::map.
You can find a simple example attached which displays the topic_name of a DataWriter leaving.
Let me know if you have further questions.
File Attachments: