DDS_DynamicData bind_complex_member returns error when binding with member name and member ID

4 posts / 0 new
Last post
Offline
Last seen: 7 years 5 months ago
Joined: 03/03/2015
Posts: 19
DDS_DynamicData bind_complex_member returns error when binding with member name and member ID

Hey,

I'm currentlly working with nested structures. My data type looks like this:

Struct OuterStruct

{

    sequence<256, DDS_Long> LongSeq;

    Struct InnerStruct{

    string<256> string

    }

}

 

I've created a DDS_DynamicData sample using the "create_data" function of the created Dynamic Data Type Support based on the type described above.

The problem is that I am trying to bind a DDS_DynamicData object to the "InnerStruct" using its member name and member ID;

 

The DDS_DynamicDataTypeSupport code looks like this:

DDS_StructMemberSeq outerStructMembers;

DDS_TypeCode* typeCode = factory->create_struct_tc("OuterStruct", outerStructMembers, exception);

DDS_TypeCode* sequenceTc = factory->create_sequence_tc(256, factory->get_primitive_tc(DDS_TK_LONG), exception);

typeCode->add_member("LongSequence", 1/*member_id = 1*/, sequenceTc, DDS_TYPECODE_NONKEY_MEMBER, exception);

DDS_StructMemberSeq innerStructMembers;
DDS_TypeCode* innerStructTypeCode= factory->create_struct_tc("InnerStruct", innerStructMembers, exception);
DDS_TypeCode* stringTc = factory->create_string_tc(256, exception);
innerStructTypeCode->add_member("string", 2, stringTc, DDS_TYPECODE_NONKEY_MEMBER, exception);

typeCode->add_member("InnerStruct", 3, innerStructTypeCode, DDS_TYPECODE_NONKEY_MEMBER, exception);

DDSDynamicDataTypeSupport* my_type_support = new DDSDynamicDataTypeSupport(typeCode, DDS_DYNAMIC_DATA_PROPERTY_DEFAULT);

 

The code above sucessfully creates the type code. I then try to do the following operations:

DDS_DynamicData* write_data = my_type_support->create_data();

DDS_DynamicData complexMember(NULL, DDS_DYNAMIC_DATA_PROPERTY_DEFAULT);

DDS_ReturnCode_t retcode = write_data->bind_complex_member(complexMember, "InnerStruct", 3); // I'm trying to bind to the complex member named "InnerStruct" and has the memberID equal to 3.

This returns with error code 1 (DDS_RETCODE_ERROR);

However, if I just try to bind with the member name, and set the memberID to "DDS_DYNAMIC_DATA_MEMBER_ID_UNSPECIFIED" the call works. 

Is there a way to call "bind_complex_member" using the member ID as well, or even the member ID only?

Thank you,

 

Best Regards,

Andrei

Organization:
gianpiero's picture
Offline
Last seen: 10 months 1 week ago
Joined: 06/02/2010
Posts: 177

Hello Andrei,

Is there a way to call "bind_complex_member" using the member ID as well, or even the member ID only?



I just checked the bind_complex_member documentation here, and it appears to me that, to you ONLY the member_id  you have to have the memeber_name se to null:

DDS_ReturnCode_t DDS_DynamicData::bind_complex_member(DDS_DynamicData &value_out, const char *member_name, DDS_DynamicDataMemberIdmember_id  )

 

Parameters
value_out<<out>> The object that you wish to bind to the field.
member_name<<in>> The name of the member or NULL to look up the member by its ID.
member_id<<in>> The ID of the member or DDS_DYNAMIC_DATA_MEMBER_ID_UNSPECIFIED to look up by name. See Member Names and IDs.
Returns
One of the Standard Return Codes
Best,
  Gianpiero
Offline
Last seen: 7 years 5 months ago
Joined: 03/03/2015
Posts: 19

Hello Gianpiero,

Thank you for the answer. It seems I was able to bind to a complex member by ID only. However, I didn't manage to bind to an inner struct by only using the member ID.

If I try to bind to the inner struct by ID, I get a DDS_RETCODE_ERROR. If I try to bind to the inner struct by name only, the binding is successfull.

Do you know why inner structs cannot be bound by ID? Is that a DDS "rule"?

 

Many thanks,

Best,

Andrei

Offline
Last seen: 3 weeks 4 days ago
Joined: 01/13/2016
Posts: 58

sorry to bother you, i want to dynamic create topic idl like this:
struct SimData {
long nRow;
long nCol;
char Data[16];
};
i don't know how to create member "char Data[16]", its an array of primitive char type. i use the codes in the fowllowing:
struct DDS_UnsignedLongSeq dimensions;
DDS_TypeCode* sz = DDS_TypeCodeFactory_create_array_tc(factory, &dimensions, DDS_TypeCodeFactory_get_primitive_tc(factory, DDS_TK_CHAR), &ex);
if (ex != DDS_NO_EXCEPTION_CODE)
{
return NULL;
}

DDS_TypeCode_add_member(portTc, "Data", DDS_MEMBER_ID_INVALID, sz, DDS_TYPECODE_NONKEY_REQUIRED_MEMBER, &ex);
if (ex != DDS_NO_EXCEPTION_CODE)
{
return NULL;
}
i know the variable dimensions is not setting correctlly. can you help me?