Modern C++ API and lookup_datareader

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

Hi

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

It is mentioned in https://community.rti.com/static/documentation/connext-dds/5.3.0/doc/api/connext_dds/api_cpp2/group__DDSBuiltInTopicModule.html

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 ?

 

Thanks

Organization:
Francisco Porcel's picture
Offline
Last seen: 3 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();
reader_qos->subscription_name.name("MyReader");  
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()->subscription_name.name().get() << 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.

-Fran

 

Offline
Last seen: 6 years 3 weeks 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

Thanks

Nico

Offline
Last seen: 3 years 8 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.