Hello all,
I try to create two topics with the same name, same publisher, etc. but in different C++ classes. This leads to the following exception:
DDS_Topic_createI:!create presentation topic
terminate called after throwing an instance of 'dds::core::Error'
what(): Failed to create Topic
I don't understand why I cannot subscribe to the same topic in two different classes in the same application.
Best regards,
Andreas
Hi Andreas,
The creation of the
Topic
fails because you cannot create two Topics with the same name within the same DomainParticipant. You can create multiple DataWriters and DataReaders to that sameTopic
. But you have to use the sameTopic
object, not create a new object each time.You can either save a reference to the
Topic
somewhere in your application so that you can reuse it when you need to create the additional DataWriter or DataReaders or alternatively you can use the lookup_topicdescription operation on the DomainParticipant to retrive a previously-createdTopic
given its name. This operation can also be used to check if theTopic
has already been created.Gerardo
Thank you for the quick answer! Is such a function also available in the modern C++11 API?
I found it: dds::topic::find. But I cannot get it to work. I give it a domain participant and a topic name as std::string but I always get:
error: no matching function for call to 'find(const DomainParticipant&, const string&)' auto Topic = dds::topic::find(participant, str);
Looking at the documentation of Topic::find() in the modern C++ API it seems like it only supports the underlying find() operation and not the lookup_topidescription() operation which is the one you need. I am checking with the developers to see if there is a workaround or different API you can use...
Gerardo
Fixed it, the syntax is:
dds::topic::find<dds::topic::Topic<TopicType> >(dds::domain::find(0), "TopicName");
Ah OK, that makes sense! I had mis-interpreted the warning that appears in the function documentation to mean that it was not doing a lookup_topicdescription, when in fact what is says is that the find() operation will only find Topic(s) but not other TopicDescription objects like ContentFilteredTopic...
Of course you only need to call
dds::domain::find(0)
if you want to also find the DomainParticipant from the domain_id. If you have the DomainParticipant you could use it...I stand corrected and I am glad you found the solution!
Gerardo