DDS_TypeCode *
sequence_get_typecode(DDS_TypeCodeFactory *tcf) {
    static DDS_TypeCode * tc = NULL;
    DDS_TypeCode * seqElementTC = NULL;
    DDS_ExceptionCode_t err;

    seqElementTC = sequence_element_get_typecode(tcf);
    if (seqElementTC == NULL) {
        fprintf(stderr, "! Unable to create typeCode\n");
        goto fail;
    }

    /* We create the typeCode for the sequence */
    tc = DDS_TypeCodeFactory_create_sequence_tc(tcf, MAX_SEQ_LEN, seqElementTC,
            &err);
    if (err != DDS_NO_EXCEPTION_CODE) {
        fprintf(stderr, "! Unable to create the sequence TC\n");
        goto fail;
    }

    if (seqElementTC != NULL) {
        DDS_TypeCodeFactory_delete_tc(tcf, seqElementTC, &err);
    }
    return tc;

    fail:
    if (seqElementTC != NULL) {
        DDS_TypeCodeFactory_delete_tc(tcf, seqElementTC, &err);
    }

    if (tc != NULL) {
        DDS_TypeCodeFactory_delete_tc(tcf, tc, &err);
    }

    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;
}