struct DDS_TypeCode *create_type_code(struct DDS_TypeCodeFactory *factory) { struct DDS_TypeCode *unionTC = NULL; DDS_ExceptionCode_t ex; /* First, we create the typeCode for a union */ /* Default-member index refers to which member of the union * will be the default one. In this example index = 1 refers * to the the member 'aLong'. Take into account that index * starts in 0 */ unionTC = DDS_TypeCodeFactory_create_union_tc(factory, "Foo", DDS_TypeCodeFactory_get_primitive_tc(factory, DDS_TK_LONG), 1, /* default-member index */ NULL, /* For now, it does not have any member */ &ex); if (ex != DDS_NO_EXCEPTION_CODE) { fprintf(stderr, "! Unable to create union TC\n"); goto fail; } /* Case 1 will be a short named aShort */ DDS_TypeCode_add_member(unionTC, "aShort", DDS_DYNAMIC_DATA_MEMBER_ID_UNSPECIFIED, DDS_TypeCodeFactory_get_primitive_tc(factory, DDS_TK_SHORT), DDS_TYPECODE_NONKEY_MEMBER, &ex); if (ex != DDS_NO_EXCEPTION_CODE) { fprintf(stderr, "! Unable to add member aShort\n"); goto fail; } /* Case 2, the default, will be a long named aLong */ DDS_TypeCode_add_member(unionTC, "aLong", 2, DDS_TypeCodeFactory_get_primitive_tc(factory, DDS_TK_LONG), DDS_TYPECODE_NONKEY_MEMBER, &ex); if (ex != DDS_NO_EXCEPTION_CODE) { fprintf(stderr, "! Unable to add member aLong\n"); goto fail; } /* Case 3 will be a double named aDouble */ DDS_TypeCode_add_member(unionTC, "aDouble", 3, DDS_TypeCodeFactory_get_primitive_tc(factory, DDS_TK_DOUBLE), DDS_TYPECODE_NONKEY_MEMBER, &ex); if (ex != DDS_NO_EXCEPTION_CODE) { fprintf(stderr, "! Unable to add member aDouble\n"); goto fail; } return unionTC; fail: if (unionTC != NULL) { DDS_TypeCodeFactory_delete_tc(factory, unionTC, &ex); } return NULL; }
DDS_TypeCode * sequence_element_get_typecode(DDS_TypeCodeFactory *tcf) { static DDS_TypeCode * tc = NULL; struct DDS_StructMemberSeq members = DDS_SEQUENCE_INITIALIZER; DDS_ExceptionCode_t err; /* First, we create the typeCode for the simple struct */ tc = DDS_TypeCodeFactory_create_struct_tc(tcf, "SimpleStruct", &members, &err); if (err != DDS_NO_EXCEPTION_CODE) { fprintf(stderr, "! Unable to create sequence TC\n"); goto fail; } DDS_TypeCode_add_member(tc, "a_member", DDS_TYPECODE_MEMBER_ID_INVALID, DDS_TypeCodeFactory_get_primitive_tc(tcf, DDS_TK_LONG), DDS_TYPECODE_NONKEY_MEMBER, &err); if (err != DDS_NO_EXCEPTION_CODE) { fprintf(stderr, "! Unable to add a_member to SimpleStruct\n"); goto fail; } return tc; fail: if (tc != NULL) { DDS_TypeCodeFactory_delete_tc(tcf, tc, &err); } return NULL; }
DDS_TypeCode * inner_struct_get_typecode(struct DDS_TypeCodeFactory *tcf) { static DDS_TypeCode *tc = NULL; struct DDS_StructMemberSeq members = DDS_SEQUENCE_INITIALIZER; DDS_ExceptionCode_t ex; /* First, we create the typeCode for a struct */ tc = DDS_TypeCodeFactory_create_struct_tc(tcf, "InnerStruct", &members, &ex); if (ex != DDS_NO_EXCEPTION_CODE) { fprintf(stderr, "! Unable to create struct TC\n"); goto fail; } /* Member 1 will be a double named x */ DDS_TypeCode_add_member(tc, "x", DDS_TYPECODE_MEMBER_ID_INVALID, DDS_TypeCodeFactory_get_primitive_tc(tcf, DDS_TK_DOUBLE), DDS_TYPECODE_NONKEY_REQUIRED_MEMBER, &ex); if (ex != DDS_NO_EXCEPTION_CODE) { fprintf(stderr, "! Unable to add member x\n"); goto fail; } /* Member 2 will be a double named y */ DDS_TypeCode_add_member(tc, "y", DDS_TYPECODE_MEMBER_ID_INVALID, DDS_TypeCodeFactory_get_primitive_tc(tcf, DDS_TK_DOUBLE), DDS_TYPECODE_NONKEY_REQUIRED_MEMBER, &ex); if (ex != DDS_NO_EXCEPTION_CODE) { fprintf(stderr, "! Unable to add member y\n"); goto fail; } DDS_StructMemberSeq_finalize(&members); return tc; fail: if (tc != NULL) { DDS_TypeCodeFactory_delete_tc(tcf, tc, &ex); } DDS_StructMemberSeq_finalize(&members); return NULL; }
/* This function creates the typecode */ DDS_TypeCode * RTI_RoutingServiceFileAdapter_create_type_code() { struct DDS_TypeCodeFactory * factory = NULL; struct DDS_TypeCode * sequence_tc = NULL; /* type code for octet */ struct DDS_TypeCode * struct_tc = NULL; /* Top-level typecode */ struct DDS_StructMemberSeq member_seq = DDS_SEQUENCE_INITIALIZER; DDS_ExceptionCode_t ex = DDS_NO_EXCEPTION_CODE; /* we get the instance of the type code factory */ factory = DDS_TypeCodeFactory_get_instance(); if (factory == NULL) { fprintf(stderr, "ERROR: Unable to get type code factory singleton\n"); goto done; } /* create a sequence for DDS_Octet, so we use a general type */ sequence_tc = DDS_TypeCodeFactory_create_sequence_tc( factory, MAX_PAYLOAD_SIZE, DDS_TypeCodeFactory_get_primitive_tc(factory, DDS_TK_OCTET), &ex); if (ex != DDS_NO_EXCEPTION_CODE) { fprintf(stderr, "ERROR: Unable to create 'payload' sequence typecode:" " %d\n", ex); goto done; } /* create top-level typecode */ struct_tc = DDS_TypeCodeFactory_create_struct_tc( factory, "TextLine", &member_seq, &ex); if (ex != DDS_NO_EXCEPTION_CODE) { fprintf(stderr, "Unable to create struct typecode, error = %d \n", ex); goto done; } DDS_TypeCode_add_member(struct_tc, "value", DDS_MEMBER_ID_INVALID, sequence_tc, DDS_TYPECODE_NONKEY_MEMBER, &ex); if (ex != DDS_NO_EXCEPTION_CODE) { fprintf(stderr,"Error adding member to struct typecode, error=%d\n", ex); goto done; } if (sequence_tc !=NULL) { DDS_TypeCodeFactory_delete_tc(factory,sequence_tc,&ex); } return struct_tc; done: if (sequence_tc != NULL) { DDS_TypeCodeFactory_delete_tc(factory, sequence_tc, &ex); } if (struct_tc != NULL) { DDS_TypeCodeFactory_delete_tc(factory, struct_tc, &ex); } return NULL; }