コード例 #1
0
ファイル: c_metafactory.c プロジェクト: osrf/opensplice
c_constant
c_constantNew(
    c_metaObject scope,
    const c_char *name,
    c_value value)
{
    c_constant o;
    c_literal l;

    o = c_constant(c_metaDeclare(scope,name,M_CONSTANT));
    l = c_literal(c_metaDefine(scope,M_LITERAL));
    l->value = value;
    o->operand = c_operand(l);

    return o;
}
コード例 #2
0
ファイル: c_field.c プロジェクト: diorahman/opensplice
void
c_fieldInit (
    c_base base)
{
    c_object scope;

    scope = c_metaDeclare((c_object)base,"c_field",M_CLASS);
        C_META_ATTRIBUTE_(c_field,scope,kind,c_valueKind_t(base));
        C_META_ATTRIBUTE_(c_field,scope,offset,c_address_t(base));
        C_META_ATTRIBUTE_(c_field,scope,name,c_string_t(base));
        C_META_ATTRIBUTE_(c_field,scope,path,c_array_t(base));
        C_META_ATTRIBUTE_(c_field,scope,refs,c_array_t(base));
        C_META_ATTRIBUTE_(c_field,scope,type,c_type_t(base));
    c__metaFinalize(scope,FALSE);
    c_free(scope);
}
コード例 #3
0
ファイル: d_topicInfo.c プロジェクト: xrl/opensplice_dds
static c_type
createInstanceType(
    c_type messageType,
    d_topicInfo topicInfo)
{
    c_type instanceType, baseType, foundType;
    c_metaObject o;
    c_char *name;
    c_long length,sres;
    c_base base;

    base = c_getBase(messageType);
    baseType = c_resolve(base,"durabilityModule2::d_instanceTemplate");
    assert(baseType != NULL);

    instanceType = c_type(c_metaDefine(c_metaObject(base),M_CLASS));
    c_class(instanceType)->extends = c_class(baseType);

    foundType = createTopicKeyType(messageType, topicInfo->keyExpr);

    if ( foundType != NULL) {
        o = c_metaDeclare(c_metaObject(instanceType),"key",M_ATTRIBUTE);
        c_property(o)->type = foundType;
        c_free(o);
    }
    c_metaObject(instanceType)->definedIn = c_keep(base);
    c_metaFinalize(c_metaObject(instanceType));

#define INSTANCE_NAME "d_instance<d_sample<>>"
#define INSTANCE_FORMAT "d_instance<d_sample<%s>>"

    length = sizeof(INSTANCE_NAME) + strlen(topicInfo->name);
    name = os_malloc(length);
    sres = snprintf(name,length,INSTANCE_FORMAT,topicInfo->name);
    assert(sres == (length-1));
#undef INSTANCE_NAME
#undef INSTANCE_FORMAT

    foundType = c_type(c_metaBind(c_metaObject(base),
                                  name,
                                  c_metaObject(instanceType)));
    os_free(name);
    c_free(instanceType);

    return foundType;
}
コード例 #4
0
ファイル: d_topicInfo.c プロジェクト: xrl/opensplice_dds
static c_type
messageTypeNew(
    c_base base,
    const c_char *typeName)
{
    c_metaObject o;
    c_type baseType,dataType,type, foundType;
    c_char *name;
    c_long length, sres;

    if (base == NULL) {
        return NULL;
    }
    dataType = c_resolve(base,typeName);
    if (dataType == NULL) {
        return NULL;
    }
    baseType = c_resolve(base, "kernelModule::v_message");
    assert(baseType != NULL);

    type = c_type(c_metaDefine(c_metaObject(base),M_CLASS));
    c_class(type)->extends = c_keep(c_class(baseType));
    o = c_metaDeclare(c_metaObject(type),
                      USERDATA_FIELD_NAME,
                      M_ATTRIBUTE);
    c_property(o)->type = dataType;
    c_free(o);
    c_metaObject(type)->definedIn = c_keep(base);
    c_metaFinalize(c_metaObject(type));


#define MESSAGE_FORMAT "v_message<%s>"
#define MESSAGE_NAME "v_message<>"
    length = sizeof(MESSAGE_NAME) + strlen(typeName);
    name = os_malloc(length);
    sres = snprintf(name,length,MESSAGE_FORMAT,typeName);
    assert(sres == (length-1));
#undef MESSAGE_FORMAT
#undef MESSAGE_NAME
    foundType = c_type(c_metaBind(c_metaObject(base),name,c_metaObject(type)));
    os_free(name);
    c_free(type);

    return foundType;
}
コード例 #5
0
ファイル: c_metafactory.c プロジェクト: osrf/opensplice
c_iter
c_bindTypes(
    c_metaObject scope,
    c_iter declarations,
    c_type type)
{
    c_iter typeDefs;
    c_declarator d;
    c_metaObject o;

    typeDefs = NULL;
    d = (c_declarator)c_iterTakeFirst(declarations);
    while (d != NULL) {
        o = c_metaDeclare(scope,d->name,M_TYPEDEF);
        c_typeDef(o)->alias = c_declaratorType(d,type);
        c_metaFinalize(o);
        typeDefs = c_iterInsert(typeDefs,o);
        os_free(d);
        d = (c_declarator)c_iterTakeFirst(declarations);
    }
    c_iterFree(declarations);
    return typeDefs;
}
コード例 #6
0
ファイル: v_index.c プロジェクト: osrf/opensplice
static c_type
sampleTypeNew(
    v_topic topic)
{
    c_metaObject o;
    c_type msgType,sampleType,foundType;
    c_base base;
    c_char *name;
    os_size_t length;
    int sres;

    assert(C_TYPECHECK(topic,v_topic));
    assert(topic);

    name = NULL;
    foundType = NULL;

    if (v_topicName(topic) == NULL) {
        OS_REPORT(OS_ERROR,
                  "v_index::sampleTypeNew failed",V_RESULT_ILL_PARAM,
                  "failed to retreive topic name");
        return NULL;
    }

    base = c_getBase(topic);

    if (base == NULL) {
        OS_REPORT(OS_ERROR,
                  "v_index::sampleTypeNew failed",V_RESULT_ILL_PARAM,
                  "failed to retreive base");
        return NULL;
    }

    msgType = c_keep(v_topicMessageType(topic));

    if (msgType == NULL) {
        OS_REPORT(OS_ERROR,
                  "v_index::sampleTypeNew failed",V_RESULT_ILL_PARAM,
                  "failed to retreive topic message type");
        return NULL;
    }

    sampleType = c_type(c_metaDefine(c_metaObject(base),M_CLASS));
    if (sampleType) {
        c_class(sampleType)->extends = v_dataReaderSample_t(base);
        o = c_metaDeclare(c_metaObject(sampleType),"message",M_ATTRIBUTE);
        if (o) {
            c_property(o)->type = c_keep(msgType);
            c_metaObject(sampleType)->definedIn = c_keep(base);
            c_metaFinalize(c_metaObject(sampleType));

#define SAMPLE_FORMAT "v_indexSample<%s>"
#define SAMPLE_NAME   "v_indexSample<>"
            /* sizeof contains \0 */
            length = sizeof(SAMPLE_NAME) + strlen(v_topicName(topic));
            name = os_malloc(length);
            sres = snprintf(name,length,SAMPLE_FORMAT,v_topicName(topic));
            assert(sres >= 0 && (os_size_t) sres == (length-1));
            OS_UNUSED_ARG(sres);
#undef SAMPLE_FORMAT
#undef SAMPLE_NAME

            foundType = c_type(c_metaBind(c_metaObject(base),
                                          name,
                                          c_metaObject(sampleType)));
            c_free(o);
        } else {
            foundType = NULL;
        }
        c_free(sampleType);
    } else {
        OS_REPORT(OS_ERROR,
                  "v_index::sampleTypeNew failed",V_RESULT_ILL_PARAM,
                  "failed to retreive topic sample type");
    }
    os_free(name);
    c_free(msgType);

    return foundType;
}
コード例 #7
0
ファイル: v_index.c プロジェクト: osrf/opensplice
static c_type
createInstanceType (
    v_topic topic,
    c_char *keyExpr,
    c_array *keyListRef)
{
    c_metaObject o;
    c_type instanceType, baseType, foundType;
    c_type sampleType, keyType, keyInstanceType;
    c_base base;
    c_char *name;
    os_size_t length;
    int sres;

    assert(C_TYPECHECK(topic,v_topic));

    foundType = NULL;
    if (keyExpr) {
        keyType = v_topicKeyTypeCreate(topic,keyExpr,keyListRef);
    } else {
        keyExpr = v_topicKeyExpr(topic);
        keyType = v_topicKeyType(topic);
        *keyListRef = c_keep(v_topicMessageKeyList(topic));
    }
    sampleType = sampleTypeNew(topic);
    if (sampleType) {
        base = c_getBase(topic);
        baseType = v_dataReaderInstance_t(base);
        instanceType = c_type(c_metaDefine(c_metaObject(base),M_CLASS));
        if (instanceType != NULL) {
            c_class(instanceType)->extends = c_keep(c_class(baseType));
            o = c_metaDeclare(c_metaObject(instanceType),
                              "sample",M_ATTRIBUTE);
            c_property(o)->type = c_keep(sampleType);
            c_free(o);
            o = c_metaDeclare(c_metaObject(instanceType),
                              "oldest",M_ATTRIBUTE);
            c_property(o)->type = (c_type)c_metaResolveType(c_metaObject(base),
                                                    "c_voidp");
            assert(c_property(o)->type);
            c_free(o);
            c_metaFinalize(c_metaObject(instanceType));
#define INSTANCE_NAME   "v_indexInstance<v_indexSample<>>"
#define INSTANCE_FORMAT "v_indexInstance<v_indexSample<%s>>"
            /* The sizeof contains \0 */
            length = sizeof(INSTANCE_NAME) + strlen(v_topicName(topic));
            name = os_alloca(length);
            sres = snprintf(name,length,INSTANCE_FORMAT,v_topicName(topic));
            assert(sres >= 0 && (os_size_t) sres == (length-1));
            OS_UNUSED_ARG(sres);
#undef INSTANCE_NAME
#undef INSTANCE_FORMAT
            foundType = c_type(c_metaBind(c_metaObject(base),
                                          name,
                                          c_metaObject(instanceType)));
            if (foundType == NULL) {
                OS_REPORT(OS_ERROR,
                        "v_index::createInstanceType",V_RESULT_INTERNAL_ERROR,
                        "Could not create instance type");
            }

            os_freea(name);

            if (keyType != NULL) {
                keyInstanceType = c_type(c_metaDefine(c_metaObject(base),M_CLASS));
                if (keyInstanceType) {
                    c_class(keyInstanceType)->extends = c_keep(c_class(instanceType));
                    o = c_metaDeclare(c_metaObject(keyInstanceType),
                                      "key",M_ATTRIBUTE);
                    c_property(o)->type = c_keep(keyType);
                    c_free(o);
                    c_metaFinalize(c_metaObject(keyInstanceType));
#define INSTANCE_NAME   "v_indexKeyInstance<v_indexSample<>,>"
#define INSTANCE_FORMAT "v_indexKeyInstance<v_indexSample<%s>,%s>"
                    /* The sizeof contains \0 */
                    length = sizeof(INSTANCE_NAME) +
                             strlen(v_topicName(topic)) +
                             strlen(keyExpr);
                    name = os_alloca(length);
                    sres = snprintf(name,
                                    length,
                                    INSTANCE_FORMAT,
                                    v_topicName(topic),
                                    keyExpr);
                    assert(sres >= 0 && (os_size_t) sres == (length-1));
                    OS_UNUSED_ARG(sres);
#undef INSTANCE_NAME
#undef INSTANCE_FORMAT
                    c_free(foundType); /* Will be overwritten, so free */
                    foundType = c_type(c_metaBind(c_metaObject(base),
                                                  name,
                                                  c_metaObject(keyInstanceType)));
                    if (foundType == NULL) {
                        OS_REPORT(OS_ERROR,
                                  "v_index::createInstanceType",V_RESULT_INTERNAL_ERROR,
                                  "Could not create key instance type");
                    }
                    os_freea(name);
                    c_free(keyInstanceType);
                }
                c_free(keyType);
            }
            c_free(instanceType);
            c_free(baseType);
        } else {
            foundType = baseType; /* transfer refCount to caller */
        }
        c_free(sampleType);
    }

    return foundType;
}
コード例 #8
0
ファイル: v_messageExt.c プロジェクト: osrf/opensplice
struct v_messageExtCdrInfo *
v_messageExtCdrInfoNew(
    c_type topicMessageType,
    const struct sd_cdrControl *control)
{
    static const char headerTypeName[] = "kernelModule::v_messageExt";
    c_base base = c_getBase (topicMessageType);
    c_property userDataProperty = c_property(c_metaResolve(c_metaObject(topicMessageType),"userData"));
    c_type topicDataType = userDataProperty->type;
    c_type headerClass = c_resolve (base, headerTypeName);
    c_type dataClass;
    c_type type;
    c_object o;
    c_array members;
    struct v_messageExtCdrInfo *xci;
    struct c_type_s const *tstk[2];
    c_free(userDataProperty);

    /* Wrap user data in a class, so that we can make a struct with a pointer to it */
    dataClass = c_type(c_metaDefine(c_metaObject(base), M_CLASS));
    c_class(dataClass)->extends = NULL;
    o = c_metaDeclare(c_metaObject(dataClass), "userData", M_ATTRIBUTE);
    c_property(o)->type = c_keep(topicDataType);
    c_metaObject(dataClass)->definedIn = c_keep(base);
    c_metaFinalize(c_metaObject(dataClass));
    c_free(o);

    /* Make a struct containing two pointers, one to the v_messageExt class, and one to
     the just-created anonymous dataClass type, corresponding to struct v_messageExtCdrTmp */
    type = c_type(c_metaDefine(c_metaObject(base),M_STRUCTURE));
    members = c_arrayNew(c_member_t(base),2);
    members[0] = (c_voidp)c_metaDefine(c_metaObject(base),M_MEMBER);
    c_specifier(members[0])->name = c_stringNew(base,"h");
    c_specifier(members[0])->type = c_keep(headerClass);
    members[1] = (c_voidp)c_metaDefine(c_metaObject(base),M_MEMBER);
    c_specifier(members[1])->name = c_stringNew(base,"d");
    c_specifier(members[1])->type = c_keep(dataClass);
    c_structure(type)->members = members;
    c_metaObject(type)->definedIn = c_keep(base);
    c_metaFinalize(c_metaObject(type));
    c_free(dataClass);
    c_free(headerClass);

    xci = os_malloc(sizeof(*xci));
    xci->ci = sd_cdrInfoNewControl(type, control);

    /* Note: current simplistic annotation processing requires the annotations
     to be made in the order in which they are encountered when walking the
     type */
    tstk[0] = type;
    tstk[1] = headerClass;
    if (sd_cdrNoteQuietRef(xci->ci, 2, tstk) < 0) {
        goto err_note;
    }
    tstk[1] = dataClass;
    if (sd_cdrNoteQuietRef(xci->ci, 2, tstk) < 0) {
        goto err_note;
    }

    if (sd_cdrCompile(xci->ci) < 0) {
        goto err_compile;
    }
    xci->vmsgType = c_keep(topicMessageType);
    c_free(type);
    return xci;

err_compile:
err_note:
    os_free(xci);
    c_free(type);
    return NULL;
}