Пример #1
0
d_storeResult
d_groupInfoDataInject(
    d_groupInfo _this,
    const d_store store,
    d_group group)
{
    d_storeResult result;
    struct d_instanceInjectArg inject;
    c_type mmfMessageType;
    c_char* typeName;

    if(_this && group){
        inject.vgroup = d_groupGetKernelGroup(group);

        mmfMessageType = d_topicInfoGetMessageType(_this->topic);
        typeName = c_metaScopedName(c_metaObject(mmfMessageType));

        inject.messageType = c_type(c_metaResolveType(
                c_metaObject(c_getBase(inject.vgroup)), typeName));

        if(inject.messageType){
            inject.result = D_STORE_RESULT_OK;

            c_tableWalk(_this->instances, d_instanceInject, &inject);

            c_free(inject.messageType);
            result = inject.result;
        } else {
            result = D_STORE_RESULT_PRECONDITION_NOT_MET;
        }
        c_free(inject.vgroup);
        c_free(mmfMessageType);
        os_free(typeName);
    } else {
        result = D_STORE_RESULT_ILL_PARAM;
    }
    return result;
}
Пример #2
0
/*
 * Check if each usage of a char array as a key has a corresponding
 * "#pragma cats" declaration.
 */
static c_bool
idl_checkCatsUsage(
    c_base base,
    const char* filename)
{
    char errorBuffer [IDL_MAX_ERRORSIZE];
    idl_keyDef keyDef = idl_keyDefDefGet();
    c_long keyMapIdx;
    idl_keyMap keyMap;
    c_type type;
    c_structure structure;
    c_iter keysList;
    os_uint32 keysListSize;
    os_uint32 keyIdx;
    c_char* keyName;
    os_uint32 i;
    c_iter keyNameList;
    os_uint32 keyNameListSize;
    c_structure tmpStructure;
    c_specifier sp;
    c_type subType;
    c_string typeName;
    c_type spType;

    if (keyDef != NULL) {
        /* check all key definition list elements */
        for (keyMapIdx = 0; keyMapIdx < c_iterLength(keyDef->keyList); keyMapIdx++) {
            keyMap = c_iterObject(keyDef->keyList, keyMapIdx);
            /* if a keylist is defined for the type */
            if (keyMap->keyList && strlen(keyMap->keyList) > 0) {
                /* find meteobject for the type */
                type = c_type(c_metaResolveType(keyMap->scope, keyMap->typeName));
                if (!type) {
                    snprintf(errorBuffer, IDL_MAX_ERRORSIZE-1, errorText[idl_UndeclaredIdentifier], keyMap->typeName);
                    idl_printError(filename, errorBuffer);
                    return OS_FALSE;
                }
                /* type can be a typedef. Determine the actual type. */
                type = c_typeActualType(type);

                /* type should be a structure */
                if (c_baseObject(type)->kind != M_STRUCTURE) {
                    snprintf(errorBuffer, IDL_MAX_ERRORSIZE-1, errorText[idl_IllegalKeyFields]);
                    idl_printError(filename, errorBuffer);
                    return OS_FALSE;
                }
                structure = c_structure(type);

                /* for each key in keyList, check if type is a char array */
                keysList = c_splitString(keyMap->keyList, ",");
                keysListSize = c_iterLength(keysList);
                for(keyIdx = 0; keyIdx < keysListSize; keyIdx++)
                {
                    keyName = c_iterTakeFirst(keysList);
                    /* We might be dealing with a field of a field definition in
                     * the keylist, so let's split this up
                     */
                    keyNameList = c_splitString(keyName, ".");
                    keyNameListSize = c_iterLength(keyNameList);
                    tmpStructure = structure;
                    for(i = 0; i < keyNameListSize; i++)
                    {

                        keyName = c_iterTakeFirst(keyNameList);
                        /* Now get the actual member defined by the name */
                        sp = c_specifier(c_metaFindByName(
                            c_metaObject(tmpStructure),
                            keyName,
                            CQ_FIXEDSCOPE | CQ_MEMBER | CQ_CASEINSENSITIVE));
                        if(sp)
                        {
                            spType = c_typeActualType(sp->type);
                            /* If the member is a structure, we need to
                             * recurse deeper.
                             */
                            if(c_baseObject(spType)->kind == M_STRUCTURE)
                            {
                                tmpStructure = c_structure(spType);
                            }
                            /* If the member is a collection then we need to
                             * ensure it is not a character array, but if it
                             * is we need to ensure a corresponding CATS pragma
                             * can be located
                             */
                            else if(c_baseObject(spType)->kind == M_COLLECTION && c_collectionType(spType)->kind == C_ARRAY)
                            {
                                subType = c_typeActualType(c_collectionType(spType)->subType);
                                if(c_baseObject(subType)->kind == M_PRIMITIVE &&
                                   c_primitive(subType)->kind == P_CHAR)
                                {

                                    typeName = c_metaName(c_metaObject(tmpStructure));
                                    /* check if there is corresponding catsDef */
                                    if (!idl_isCatsDefFor(c_metaObject(tmpStructure)->definedIn,
                                                          typeName,
                                                          keyName))
                                    {
                                        snprintf(
                                            errorBuffer,
                                            IDL_MAX_ERRORSIZE-1,
                                            errorText[idl_NoCorrespondingCats],
                                            c_metaObject(structure)->name,
                                            keyName);
                                        idl_printError(filename, errorBuffer);
                                        return OS_FALSE;
                                    }
                                    c_free(typeName);
                                }

                            }
                        }
                    }
                }
            }
        }
    }

    return OS_TRUE;
}
Пример #3
0
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;
}