Multi-language library

2 posts / 0 new
Last post
Offline
Last seen: 2 years 7 months ago
Joined: 01/22/2021
Posts: 8
Multi-language library

We are trying to build a multi-language library on top of RTI Connext DDS Pro. Ideally we would like to write the library in modern C++ and then write wrappers for other languages (Java and C# first).

As an example, I want to write a send() function that creates a Topic, DataWriter, etc. as necessary and sends a message:

template <class T> void send(const T& msg) { writer.write(msg); }

The problem is that templates really don't play well accross language boundaries and probably wouldn't work at all here because the other languages would need to have a notion of the C++ class generated from rtiddsgen.

There are a couple of solutions that I can think of:

  • Fully implement the library in all required languages. Use each language's notion of generics/templates. Use rtiddsgen to generate classes for each language.
  • Pass the structure of the type to the send method/class and use dynamic data to create the message type at runtime.
  • Pass the IDL filename to the send method. Call rtiddsgen through the C++ code to generate the class in a temporary folder. Delete the temporary generated files when the application exits.

Can anyone think of a better solution than these? Is this a solved problem already? I'm relatively new to RTI Connext so I may just not be seeing something obvious.

 

Howard's picture
Offline
Last seen: 1 week 18 hours ago
Joined: 11/29/2012
Posts: 567

Sorry, but I don't think that your problem area really has much to do with DDS.  Generically, you're trying to write a library in C++ for which you can simple wrappers in other languages.

However, the wrapper API has to pass data structures to the C++ layer.  As you say, there is no translation of templates between programming languages.  I'm not a programming expert, but I don't see how you can define a templated API with one programming language that calls a templated API in a different programming language.  That's the fundamental problem...not DDS.  And thus, I don't see how DDS can help you solve this in a way that would be any different than if DDS was not involved.

Of course, if you don't design your wrapper API to use templates to pass data, then you don't have to tackle that problem.

RTI Connext DDS offers full APIs in C/C++/Java/.NET.  If you want your library to be independent of concrete types (i.e., defined via IDL and linked with generated type-specific code), then you can certainly use the DynamicData API and expose a DynamicData object via your wrapper layer...but your application code will be using the DDSDynamicData API at that level.