Modern C++ API and lookup_datareader

4 posts / 0 new
Last post
Last seen: 6 years 1 month ago
Joined: 07/12/2012
Posts: 51
Modern C++ API and lookup_datareader


It does not seem lookup_datareader() is implemnted in the moderm C++ API (RTI version 5.2.3)

It is mentioned in

in the "Detailed description" paragraph. However it is not documented in the subscriber API and it does not seem to be implemented. Is it possible to clarify its implementation status ?



Francisco Porcel's picture
Last seen: 2 weeks 5 days ago
Joined: 11/07/2016
Posts: 24

Hi Nico,

In Modern C++, you should use the method find_datareader_by_name(). Let me provide you with a snippet:

// Create a subscriber
 dds::sub::Subscriber subscriber(participant);
// Create a DataReader with Qos setting its name
dds::sub::qos::DataReaderQos reader_qos = participant->default_datareader_qos();
dds::sub::DataReader<test> reader(subscriber, topic, reader_qos); 

// Find the DataReader from within the subscriber, using the DataReader's name 
const std::string name("MyReader");
dds::sub::DataReader<test> found_reader =
        rti::sub::find_datareader_by_name<dds::sub::DataReader<test>>(subscriber, name);
if (found_reader != dds::core::null) { 
    std::cout << "Found DataReader's name is: " << found_reader->qos()-> << std::endl; 
} else {
    return -1;

The output of the cout line is: Found DataReader's name is: MyReader. There are more methods to find more entities. If you go to the Modern C++ API website and type "find", the autocompletion will show you the available methods.

Please, let me know if this helps.



Last seen: 6 years 1 month ago
Joined: 07/12/2012
Posts: 51

Hi Fran,

Through your example I discovered that I actually needed find_datareader_by_topic_name(). Your explanation was very helpful



Last seen: 3 years 9 months ago
Joined: 03/12/2018
Posts: 32

Hi.  How would this work if one is searching for the presence of a reader on another node?

I have publisher code that needs to wait for a subscriber before it publishes.  It can't count subscribers because other things out there might be subscribed, like recorders and the admin console.