How do I use the Traditional C++ and Modern C++ APIs in the same application?

Note: Applies to RTI Connext DDS 5.2.0 and above.


The Modern C++ API was introduced with RTI Connext DDS 5.2.0. This solution explains how to use the Modern and Traditional C++ APIs in the same application.

To make them work together, you must not use both of them in the same .cpp file. That is, do not include headers from both APIs. This is a technical restriction due to the way certain common C headers are implemented. You will need to compile code that uses each API into separate objects and define an interface between them.

The following example demostrates this. It uses RTI Connext DDS to send and receive sensor information by using the Modern C++ API and request/reply from the Traditional C++ API to select the sensor of interest.

The source code files are divided into three types: publisher, subscriber, and data type. The header file uses the pImpl pattern to not expose implementation-specific APIs.

Publisher

  • Publisher: Main application and command-line interface. It creates the objects and sleeps for 3 seconds, then sends the sensor information. If it has not received a stop message, it will repeat the process of sleeping 3 seconds, sending the sensor information, and checking for stop message.
  • DdsPublisher (Modern): DDS publisher to publish sensor information.
  • SensorReplier (Traditional): DDS replier that receives requests and replies to them. It can receive two types of messages:
    • sensorX: Tell the publisher to send information about a specific sensor.
    • stop: Set a flag to stop the exit the application cleanly in the next iteration.

Subscriber

  • Subscriber: Main application and command-line interface. It creates the objects, sends the user inputs, and shows the received data.
  • DdsSubscriber (Modern): DDS subscriber to receive sensor information.
  • SensorRequester (Traditional): DDS requester that sends the user input.

Type

This folder contains the IDL used in the example and will contain all the files generated by rtiddsgen.

Programming Language:
Keywords: