Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Golang wrapper for RTI DDS

NotificationsYou must be signed in to change notification settings

jhbe/rtiddsgo

Repository files navigation

The rtiddsgo package enables golang applications to use RTI DDS. It containsRTI DDS wrappers and tools to generate go files given DDS topics in .xmlfiles generated by the RTI tools from IDL files.

The generated types use golang built-in types; no DDS basic types are visible. Atype may contain another DDS type, but sooner or later they all resolveto golang built-in types.

This package was designed to be easy to use and require little type conversionat the expense of performance; the type code does not try to be efficient whencopying between the DDS representations and the golang representation.

Quick Start!

Update the NDDSHOME and RTILIBDIR variables in the Makefile. Then:

make./examplesub

...and is a separate terminal:

./examplepub

Build

To generate the goddsgen tool:

make goddsgen

Usage

Each IDL file must first be converted by the rtiddsgen tool and the -convertToXml optionto an XML represention.

The ./goddsgen executable is then used to parse the XML files and generate golang codefor the structs, unions, enums and constants found in the XML file:

goddsgen <xml_file_name> <rti_install_dir> <rti_lib_dir> <out_path> <package_name>

The arguments are:

  • The name of the XML file to read with path if necessary.
  • The path to the directory containing the RTI DDS installation, such as "/opt/rti_connext_dds-5.3.1".
  • The path to the directory containing the RTI DDS libraries, typically "/opt/rti_connext_dds-5.3.1/lib/x64Linux3gcc5.4.0".
  • The file name using in the C-files for the type.
  • The path to directory in which the generated golang files should go.
  • The packages name to use in all generated golang files.

The generated source code depend on the C code generated for the same IDL byrtiddsgen.

The generated source code have the following characteristics:

  • All names of types and variables found in the IDL files have a leading uppercasecharacter in the golang representation to make them visible from outside thepackage. Most have uppercase characters starting every word.
  • Names use an underscore to separate modules; "Com_This_That_Blah".
  • Strings are unbound. The maximum length as defined in the IDL file is NOTenforced.
  • Sequences are converted to golang slices. The maximum length as defined inthe IDL file is NOT enforced.
  • A union Foo have a variable _Discriminant acting as the discriminant.

Once the XML file has been parsed and golang source code generated, an applicationuses the rtiddsgo package together with the generated source code to createand use DDS. The rtiddsgo package contains code for:

  • Participants
  • Publishers
  • Subscribers
  • Topics

while the generated source code provide:

  • Type definition
  • DataWriter for the type
  • DataReader for the type
  • All-in-one participant, publisher, topic and datawriter support for the type
  • All-in-one participant, subscriber, topic and datareader support for the type

Do not use the DataReader and DataWriter found in the rtiddsgo package, theyare used by the generated code, not directly by an application.

An application can use a pre-canned Participant/Publisher/Topic/DataWriter for the struct ("Com_Ex_A" is the name of the type) foud in the allinone files:

w := example.NewWriterCom_Ex_A(33, "TheTopicName", "", "", "", "")defer w.Free()w.Dw.Write(example.Com_Ex_A{0, "Hello"})

or it can manage each separately:

p, err := rtiddsgo.New(33, "", "")if err != nil {    log.Fatal(err)}defer p.Free()err = example.Com_Ex_A_RegisterType(p)if err != nil {    log.Fatal(err)}topic, err := p.CreateTopic("MyMessage", example.Com_Ex_A_GetTypeName(), "", "")if err != nil {    log.Fatal(err)}defer topic.Free()pub, err := p.CreatePublisher("", "")if err != nil {    log.Fatal(err)}defer pub.Free()dw, err := example.NewCom_Ex_ADataWriter(pub, topic, "", "")if err != nil {    log.Fatal(err)}defer dw.Free()dw.Write(example.Com_Ex_A{0, "Hello"})

The same is true for subscribers.

Types are mapped as follows:

IDLXMLCGo
booleanbooleanDDS_Booleanbool
octetbyteDDS_Octetuint8
shortint16DDS_Shortint16
unsigned shortuint16DDS_UnsignedShortuint16
longint32DDS_Longint32
unsigned longuint32DDS_UnsignedLonguint32
floatfloat32DDS_Floatfloat32
doublefloat64DDS_Doublefloat64
stringstringDDS_Char *string

Example

The Makefile builds an example publisher and subscriber, found in theexample directory.

Limitations

The "//@key" and "//@top-level" IDL directives are NOT used by rtiddsgo.All structs have datawriter and datareader support.

A type is expected to be either fully qualified ("com::this::that") or bedefined in the same module it is used. Example:

module A {  struct B {    string C;  };    struct D {    B myB;  // This is OK.  };    module E {    struct F {      B myB;  // This is NOT ok. Must be A::B, not just B.    };  };};

Sequences must be bounded.

Sequences cannot have the index based on an enum.

A union discriminant cannot be a typedef type.

Internal Design

The three parts making up this package are:

PackageDescription
rtiddsgoStatic golang package for participants, publishers, subscribers and topic support.
rtiddsgo/parseParses the XML file and extracts constans, enums, structs, unions and typedefs.
rtiddsgo/generateGolang source code generation based on the result of the rtiddsgo/parse package.
rtiddsgo/mainMain for the goddsgen tool itself.

Parse

FileDescription
constantsCreates a collection of all constants found in the IDL file.
enumsCreates a collection of all enums found in the IDL file.
structsCreates a collection of all structs found in the IDL file.
typedefsCreates a collection of all typedefs found in the IDL file.
unionsCreates a collection of all unions found in the IDL file.
traverseProvides functions for traversing the content of the parsed XML file.
utilsVarious functions for converting names to other formats
xmlParses the XML file.

Generate

FileDescription
allinoneGenerates the all-in-one go source code for a DDS type.
constsGenerates the go source code for a DDS constants.
datareaderGenerates the DDS data reader go source code for a DDS type.
datawriterGenerates the DDS data writer go source code for a DDS type.
enumsGenerates the go source code for a DDS enums.
structsGenerates the go source code for a DDS struct type.
typedefsGenerates the go source code for a DDS typedef type.
unionsGenerates the go source code for a DDS union type.
flagsDefines the CGO flags.
retreiveProvides a function for generating the DDS type Retrieve go source code.
storeProvides a function for generating the DDS type Store go source code.

TODO

  • Function comments.
  • Register and dispose support.
  • Why doesn't verificationsub always stop properly?

About

Golang wrapper for RTI DDS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp