Example #1
0
static c_type
createKeyType(
    const c_char *name,
    c_array keyList)
{
    c_base base;
    c_type foundType;
    c_char *typeName;
    c_char keyName[16];
    c_long i, length, sres;
    c_array members;
    c_metaObject o;
    c_field field;

    if (keyList == NULL) {
        return NULL;
    }
    base = c_getBase(keyList);
    length = c_arraySize(keyList);
    if (length == 0) {
        return NULL;
    }
    o = c_metaDefine(c_metaObject(base),M_STRUCTURE);
    members = c_arrayNew(c_member_t(base),length);

    for (i=0;i<length;i++) {
        field = keyList[i];
        assert(field != NULL);
        members[i] = (c_voidp)c_metaDefine(c_metaObject(base),M_MEMBER);
            sprintf(keyName,"field%d",i);
            c_specifier(members[i])->name = c_stringNew(base,keyName);
            c_specifier(members[i])->type = c_keep(c_fieldType(field));
    }
    c_structure(o)->members = members;
    c_metaObject(o)->definedIn = c_metaObject(base);
    c_metaFinalize(o);
#define KEY_NAME   "<Key>"
#define KEY_FORMAT "%s<Key>"

    if (name != NULL) {
        length = sizeof(KEY_NAME) + strlen(name);
        typeName = os_malloc(length);
        sres = snprintf(typeName,length,KEY_FORMAT,name);
        assert(sres == (length-1));
    } else {
        assert(FALSE);
        length = 100;
        typeName = os_malloc(length);
        os_sprintf(typeName,PA_ADDRFMT KEY_NAME,(c_address)o);
    }
#undef KEY_NAME
#undef KEY_FORMAT
    foundType = c_type(c_metaBind(c_metaObject(base),typeName,o));

    c_free(o);
    os_free(typeName);

    return foundType;

}
Example #2
0
static qp_result
prepareQosSample(
        const char *qosName,
        qp_entityAttr attr,
        qp_parseContext ctx)
{
    qp_result result;
    const c_type qosSampleType = attr->qosSampleType;
    assert(qosSampleType);

    assert(qosName);
    assert(ctx);

    ctx->scope = QP_SCOPE_QOSPOLICY;
    ctx->qosSample = c_new(qosSampleType);
    if (ctx->qosSample == NULL){
        result = QP_RESULT_OUT_OF_MEMORY;
        goto err_new_qosSample;
    }
    c_cloneIn(qosSampleType, attr->defaultQosTmplt, &ctx->qosSample);
    ctx->currentField = c_fieldNew(qosSampleType, qosName);
    if (ctx->currentField == NULL){
        result = QP_RESULT_OUT_OF_MEMORY;
        goto err_fieldNew;
    }
    ctx->currentFieldType = c_fieldType(ctx->currentField);
    assert(ctx->currentFieldType);

    ctx->qosTable = attr->qosTable;
    return QP_RESULT_OK;

/* Error handling */
err_fieldNew:
    c_free(ctx->qosSample);
    ctx->qosSample = NULL;
err_new_qosSample:
    return result;
}