HelloWorld IDL

The HelloWorld data type is described in a language-independent way and stored in the HelloWorldData.idl file:

module HelloWorldData
{
    struct Msg
    {
        @key long userID;
        string message;
    };
};

The data definition language used for DDS corresponds to a subset of the OMG Interface Definition Language (IDL). In our simple example, the HelloWorld data model is made of one module HelloWorldData. A module can be seen as a namespace where data with interrelated semantics are represented together in the same logical set.

The structMsg is the data type that shapes the data used to build topics. As already mentioned, a topic is an association between a data type and a string name. The topic name is not defined in the IDL file, but the application business logic determines it at runtime.

In our simplistic case, the data type Msg contains two fields: userID and message payload. The userID is used to uniquely identify each message instance. This is done using the @key annotation.

For further information, refer to IDL.

The IDL compiler translates the IDL datatype into a C struct with a name made of the<ModuleName>_<DataTypeName> .

typedef struct HelloWorldData_Msg
{
    int32_t userID;
    char * message;
} HelloWorldData_Msg;

Generated files with the IDL compiler

The IDL compiler is a C program that processes .idl files.

idlc HelloWorldData.idl

This results in new HelloWorldData.c and HelloWorldData.h files that need to be compiled, and their associated object file must be linked with the Hello World! publisher and subscriber application business logic. When using the provided CMake project, this step is done automatically.

As described earlier, the IDL compiler generates one source and one header file. The header file (HelloWorldData.h) contains the shared messages’ data type. While the source file has no direct use from the application developer’s perspective.

HelloWorldData.h* needs to be included in the application code as it contains the actual message type and contains helper macros to allocate and free memory space for the HelloWorldData_Msg type.

typedef struct HelloWorldData_Msg
{
    int32_t userID;
    char * message;
} HelloWorldData_Msg;

HelloWorldData_Msg_alloc()
HelloWorldData_Msg_free(d,o)

The header file also contains an extra variable that describes the data type to the DDS middleware. This variable needs to be used by the application when creating the topic.

HelloWorldData_Msg_desc

HelloWorld business logic

As well as the HelloWorldData.h/c generated files, the HelloWorld example also contains two application-level source files (subscriber.c and publisher.c), containing the business logic.