Topic Creation Failure

4 posts / 0 new
Last post
Offline
Last seen: 2 years 7 months ago
Joined: 03/31/2022
Posts: 11
Topic Creation Failure

Folks,

I created a DataWriter for my topic, which succeeds, I then attempt to create a DataReader for the same topic (I want to extract any existing old instances for recovery purposes).

The reader has its own instance of the topic variable. When I attempt to create the reader, I get "DDS_Topic_CreateI:!create presentation topic" and a dds::core:Error exception is thrown.

I am using the Modern C++ Interface. Both reader and writer create a topic the same way :

_topic = dds::topic::Topic<Topic>(GetDomainParticipant(), sTopicName);

GetDomainParticipant returns a reference to the domain participant I am using. sTopicName is the same for both.

Any idea why I might be getting this. I thought that a recreation of the topic was safe.

Thanks,

Dale Pennington

Howard's picture
Offline
Last seen: 1 week 2 days ago
Joined: 11/29/2012
Posts: 618

No, you cannot create the same topic twice.  If there's a possibility that a topic (with the same name) has been created already, you need to see if that's the case by looking up the topic by name and only creating it if the topic doesn't exist.

In the Modern C++ API, you need to use this function:

https://community.rti.com/static/documentation/connext-dds/6.1.1/doc/api/connext_dds/api_cpp2/classdds_1_1topic_1_1Topic.html#a7520cb8425f188b5e2f5e44edf8107d6

 

 

Offline
Last seen: 2 years 7 months ago
Joined: 03/31/2022
Posts: 11

Sounds good, if only I could figure out how to invoke it. It appears to be in the dds::topic namespace, but so far I have tried

topic = dds::topic::find(domain,sTopicName);

topic = dds::topic::find<MyTopic>(domain,sTopicName);

topic = dds::topic::Topic<MyTopic>::find(domain,sTopicName);

topic = dds::topic::Topic::find(domain,sTopicName);

I figure either I am totally blind, or it in somewhere else in the dds::topic namespace.

Thanks,

Dale Penington

Howard's picture
Offline
Last seen: 1 week 2 days ago
Joined: 11/29/2012
Posts: 618

    auto found_topic = dds::topic::find<dds::topic::Topic<MyDataType>>(participant, sTopicName);

    if (found_topic == dds::core::null) {
        std::cout << "Topic not found" << std::endl;
    }
    else {
        std::cout << "Topic found" << std::endl;
    }

 

Note an exception can be thrown if a Topic with the name is found but is of a different datatype.