Modern C++ API and lookup_datareader

4 posts / 0 new
Last post
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
Joined: 11/07/2016
Posts: 18

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.



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



Joined: 03/12/2018
Posts: 26

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.