Using "union" in IDL

4 posts / 0 new
Last post
frgo's picture
Offline
Last seen: 6 years 1 month ago
Joined: 12/28/2011
Posts: 20
Using "union" in IDL

Hello,

I am trying to use the union construct to define data as follows:

// Data Package Kinds

enum data_packet_kind
{
EVENT,
REQUEST,
RESPONSE,
COMMAND,
COMMAND_RESULT,
CAT,
CAT_REPLY,
TEXT_MESSAGE
};

// all types are defined - see attached IDL file

struct data_packet_t
{
data_packet_kind packet_kind;

union data switch ( data_packet_kind )
{
case EVENT:
event_t event;

case REQUEST:
request_t request;

case RESPONSE:
response_t response;

case COMMAND:
command_t command;

case COMMAND_RESULT:
command_result_t command_result;

case CAT:
cat_t cat;

case CAT_REPLY:
cat_reply_t cat_reply;

case TEXT_MESSAGE:
text_msg_t text_message;
};
}; // This is line 154 in the IDL file

When running rtiddsgen I get:

Running rtiddsgen version 4.5f, please wait ...
/var/data/consequor/swdev/pib/idl/pib.idl:154:10:unexpected token: ;
Done (failures)

I triple (well, at least) checked the union { } construct to no avail. Any hints from the experts ?
(see attached IDL file)

Thank you in advance !

Kind regards
Frank

AttachmentSize
Plain text icon PIB IDL File4.15 KB
Keywords:
Gerardo Pardo's picture
Offline
Last seen: 3 weeks 1 day ago
Joined: 06/02/2010
Posts: 601

Hello Frank,

You need to move the declaration of the union type outside its use within the strcture as in:

      union data switch ( data_packet_kind )
        {
	  case EVENT:
	    event_t  event;

	  case REQUEST:
	    request_t  request;

	  case RESPONSE:
	    response_t  response;

	  case COMMAND:
	    command_t  command;

	  case COMMAND_RESULT:
	    command_result_t  command_result;

	  case CAT:
	    cat_t  cat;

	  case CAT_REPLY:
	    cat_reply_t  cat_reply;

  	  case TEXT_MESSAGE:
            text_msg_t   text_message;
	};

      struct data_packet_t
      {
        data_packet_kind  packet_kind;
        data value;
      };

See the attached file.

Also presence of the data_packet_kind within the struct data_packet_t  is redundant. The mapping to C, C++, Java or any language of the union type will already include a field for teh discriminator so you do not need to put it explicitly in the data_packet_t

Regards,

Gerardo

File Attachments: 
frgo's picture
Offline
Last seen: 6 years 1 month ago
Joined: 12/28/2011
Posts: 20

Gerardo,

as always very helpful! Thanks, works like a charm now.

Regards,
Frank

P.S.: I know you're the DDS man - hope you have other hobbies, too ;-) Nice WE !

Gerardo Pardo's picture
Offline
Last seen: 3 weeks 1 day ago
Joined: 06/02/2010
Posts: 601

Hello Frank,

Glad it is working now for you now!  

Worry not. I have a lot of hobbies beyond working on DDS. Some would say too many :)

One more comment. It seems like you are setting up data-types to do request-repy type interections.  I am not sure if you were aware, but our RTI Connext Messaging packege already contains all the libraries to do request-reply on top of DDS.  Of course you could do it all yourself, but the the API takes care automatically of many things: Creating the matched request & reply topics, setting the correct content filters to have clients receive replies only to their own requests, setting the right meta-data to correlate requests with their replies, supporting all different wait, callback, and timeout scenarios, etc.  It has also been designed to be very scalable.   This is not so easy to do so I would really recommend using it.  You can find more details on Part 4 of the the RTI Connext Users Manual and also the on-line documentation RTI Connext Messaging documentation section on Request Reply.

One thing to note is that RTI Connext Messaging is not included in the "Open Community Source" license so you would need to upgrade to commercial license to get it. I am not sure if that would be concern for you.

Regards,

Gerardo