Dynamic Data API to access attributes of union cases

1 post / 0 new
Last seen: 4 months 1 week ago
Joined: 10/23/2013
Posts: 42
Dynamic Data API to access attributes of union cases


I am writing an application that uses only the dynamic data type APIs and have a question about unions.  I have read through the examples posted here , here  and the File Exchange, but in all of these examples, the code to write a sample assumes knowledge of the union ( number of cases, name of each case member, data type for each case member, etc ) at compile time.  For my application, the definition of the topic type, including the union, is not known at compile time.  My application will only know the value of the discriminatorID as shown in the following example.  Unfortunately, get_member_info_by_index() doesn't appear to work.  I am looking for the following:

  1. Is there a way to get info for a given case?   
  2. Is there a way to get the total number of cases in the union?

/* Creates an instance of the data we are about to send. */

dynamicData = DDS_DynamicDataTypeSupport_create_data(typeSupport);

/* discriminator will be default case. */

DDS_DynamicData_get_member_info_by_index(dynamicData, &discrimiatorInfo, 0);

/* Get info about one of the cases in the union.  We need to know data type of the selected case so that proper API can be used to write data.*/

/* this doesn't work.  caseInfo is not populated. */
DDS_DynamicData_get_member_info_by_index(dynamicData, &caseInfo, discriminatorID);