Пример #1
0
/* Check if the specified meta object is specified with associated with
   the specified file in the specified file map
*/
c_bool
idl_fileMapObject(
    /* QAC EXPECT 3673; No solution to the message here, but no problem either */
    const idl_fileMap fileMap,
    const char *fileName,
    const c_baseObject object)
{
    idl_file file;
    c_baseObject o;
    c_bool result = FALSE;

    if (fileMap != NULL) {
	/* find the file in the file map */
        file = c_iterResolve(fileMap->files, idl_fileCompare, (c_iterResolveCompareArg)fileName);
        if (file) {
	    /* find the meta object in the file association */
            o = c_iterResolve (file->contains, idl_objectCompare, object);
            if (o) {
              /* if the object is found, the association is true */
                result = TRUE;
            }
        }
    }
    return result;
}
Пример #2
0
/* Create source */
c_iter
idl_fileMapGetObjects(
    const idl_fileMap fileMap,
    const char *fileName)
{
    idl_file file;
    c_iter result;

    result = 0;

    if(fileMap != NULL) {
        /* Lookup file */
        file = c_iterResolve(fileMap->files, idl_fileCompare, (c_iterResolveCompareArg)fileName);
        if (file) {
            result = c_iterNew(0);

            /* Walk metaobjects in filemap, add to source. */
            if(file->contains) {
                c_iterWalk(file->contains, (c_iterWalkAction)idl_fileMapFillList, result);
            }
        }
    }

    return result;
}
Пример #3
0
static void
q_countVarWalk(
    q_expr e,
    c_iter list)
{
    q_list l;
    q_expr found;

    if (e != NULL) {
        switch(e->kind) {
        case T_VAR:
            found = c_iterResolve(list,compareVar,e);
            if (found == NULL) {
                list = c_iterInsert(list,e);
            }
        break;
        case T_FNC:
            if (e->info.function->tag == Q_EXPR_CALLBACK) {
                q_countVarWalk(q_getPar(e,2),list);
            } else {
                l = e->info.function->params;
                while (l != NULL) {
                    q_countVarWalk(l->expr,list);
                    l = l->next;
                }
            }
        break;
        default:
        break;
        }
    }
}
Пример #4
0
static void*
d_waitsetEventHandlerRunToCompletion(
    void* userData)
{
    d_subscriber subscriber;
    d_durability durability;
    d_admin admin;
    d_waitset waitset;
    c_iter events = NULL;
    d_waitsetEntity we;
    c_time time;
    u_waitsetEvent event;

    waitset          = d_waitset(userData);
    subscriber       = d_waitsetGetSubscriber(waitset);
    admin            = d_subscriberGetAdmin(subscriber);
    durability       = d_adminGetDurability(admin);
    time.seconds     = 1;
    time.nanoseconds = 0;

    while(waitset->terminate == FALSE) {
        if(waitset->timedWait == TRUE){
            u_waitsetTimedWaitEvents(waitset->uwaitset, time,&events);
        } else {
            u_waitsetWaitEvents(waitset->uwaitset,&events);
        }
        if(d_durabilityGetState(durability) != D_STATE_TERMINATING){
            if(waitset->terminate == FALSE){
                d_lockLock(d_lock(waitset));

                event = u_waitsetEvent(c_iterTakeFirst(events));

                while(event){
                    we = c_iterResolve(waitset->entities, d_waitsetEntityFind, event->entity);

                    if(we){
                        we->action(we->dispatcher, event, we->usrData);
                    }
                    u_waitsetEventFree(event);
                    event = u_waitsetEvent(c_iterTakeFirst(events));
                }
            }
            d_lockUnlock(d_lock(waitset));
        }
        if(events){/* events may be null if waitset was deleted */
            c_iterFree(events);
        }
    }
    return NULL;
}
Пример #5
0
u_result
u_dispatcherRemoveListener(
    u_dispatcher _this,
    u_dispatcherListener listener)
{
    u_listener ul;
    v_observer ko;
    os_threadId tid;
    u_result result = U_RESULT_OK;
    struct compareArg arg;

    if ((_this != NULL) && (listener != NULL)) {
        os_mutexLock(&_this->mutex);
        arg.listener = listener;
        ul = (u_listener) c_iterResolve(_this->listeners, compare, &arg);
        tid = _this->threadId;
        if (ul != NULL) {
            c_iterTake(_this->listeners, ul);
            if (c_iterLength(_this->listeners) == 0) {
                result = u_entityReadClaim(u_entity(_this), (v_entity*)(&ko));
                if(result == U_RESULT_OK) {
                    assert(ko);
                    /* Wakeup the dispatch thread */
                    v_observerLock(ko);
                    v_observerNotify(ko, NULL, NULL);
                    v_observerUnlock(ko);
                    result = u_entityRelease(u_entity(_this));
                    if (result != U_RESULT_OK) {
                        OS_REPORT(OS_ERROR, "u_dispatcherRemoveListener", 0,
                                  "Release observer failed.");
                    }
                } else {
                    OS_REPORT(OS_WARNING, "u_dispatcherRemoveListener", 0,
                              "Failed to claim Dispatcher.");
                }
            }
            u_listenerFree(ul);
        }
        os_mutexUnlock(&_this->mutex);
        if ((c_iterLength(_this->listeners) == 0)
            && (os_threadIdToInteger(tid) != 0U)) {
            os_threadWaitExit(tid, NULL);
        }
    } else {
        OS_REPORT(OS_ERROR,"u_dispatcherInsertListener",0,
                  "Illegal parameter.");
        result = U_RESULT_ILL_PARAM;
    }
    return result;
}
Пример #6
0
u_result
u_waitsetDetachFromDomain(
    _Inout_ u_waitset _this,
    _Inout_ u_domain domain)
{
    u_result result;
    os_result osr;
    u_waitsetEntry entry;

    assert(_this != NULL);
    assert(domain != NULL);

    osr = os_mutexLock_s(&_this->mutex);
    if (osr == os_resultSuccess) {
        entry = c_iterResolve(_this->entries, compare_domain, domain);
        if (entry != NULL) {
            _this->notifyDetached = OS_TRUE;
            result = u_objectClose(entry);
            if (result == U_RESULT_ALREADY_DELETED) {
                result = U_RESULT_OK;
            }
            if (result == U_RESULT_OK) {
                /* The entry is already freed but the address value can still
                 * be used to update the administration because it only removes
                 * the address value from the list.
                 */
                c_iterTake(_this->entries, entry);
            } else {
                result = U_RESULT_INTERNAL_ERROR;
                OS_REPORT(OS_ERROR,
                            "u_waitsetDetachFromDomain", result,
                            "Operation u_waitsetEntryFree failed: "
                            "Waitset = 0x%"PA_PRIxADDR", result = %s",
                             (os_address)_this, u_resultImage(result));
                assert(FALSE);
            }
        } else {
            result = U_RESULT_PRECONDITION_NOT_MET;
        }
        (void)u_domainRemoveWaitset(domain, _this);
        os_mutexUnlock(&_this->mutex);
    } else {
        result = U_RESULT_INTERNAL_ERROR;
        OS_REPORT(OS_WARNING, "u_waitsetDetachFromDomain", result,
                  "Could not claim waitset.");
    }

    return result;
}
Пример #7
0
/* idl_searchObject will search in the specified "file"
   association for the object specified in map->object.
   If the object is found, it is returned and the associated
   filename is stored in map->fileName.
*/
static void
idl_searchObject(
    /* QAC EXPECT 3673; No solution to the message here, but no problem either */
    const idl_file file,
    const idl_map map)
{
    c_baseObject o;

    /* Search for the object in the specified "file" */
    o = c_iterResolve(file->contains, idl_objectMap, map);
    if (o != NULL) {
        /* Store the associated filename */
        map->fileName = file->fileName;
    }
}
Пример #8
0
/* Add the specified meta object to the specified file */
static void
idl_fileObjectAdd(
    /* QAC EXPECT 3673; No solution to the message here, but no problem either */
    const idl_file file,
    const c_baseObject object)
{
    c_baseObject o;

    /* find the meta object in the specified file */
    o = c_iterResolve(file->contains, idl_objectCompare, object);
    if (o == NULL) {
        /* if not found, add it to the file */
        c_iterInsert (file->contains, object);
    }
}
Пример #9
0
/* Add an meta object association to a file for a specified file map */
void
idl_fileMapAssociation(
    /* QAC EXPECT 3673; No solution to the message here, but no problem either */
    const idl_fileMap fileMap,
    const c_baseObject object,
    const char *fileName)
{
    idl_file file;

    /* Find the file based upon the spcified filename */
    file = c_iterResolve(fileMap->files, idl_fileCompare, (c_iterResolveCompareArg)fileName);
    /* QAC EXPECT 3416; No side effect here */
    assert(file);
    /* Add the object association to the file */
    idl_fileObjectAdd(file, object);
}
Пример #10
0
/* Add a file to the file map */
void
idl_fileMapAdd(
    /* QAC EXPECT 3673; No solution to the message here, but no problem either */
    const idl_fileMap fileMap,
    const char *fileName)
{
    idl_file file;

    /* Find the file in the file map based on the file name */
    file = c_iterResolve(fileMap->files, idl_fileCompare, (c_iterResolveCompareArg)fileName);
    if (file == NULL) {
        /* If not found, then add it now */
        file = idl_fileNew(fileName);
        c_iterAppend(fileMap->files, file);
    }
}
Пример #11
0
c_bool idl_fileMapCheckFinalized(
    const idl_fileMap fileMap,
    const char* fileName)
{
    idl_file file;
    int count;

    count = 0;

    if(fileMap != NULL) {
        file = c_iterResolve(fileMap->files, (c_iterResolveCompare)idl_fileCompare, (c_iterResolveCompareArg)fileName);
        if(file) {

            c_iterWalk(file->contains, (c_iterWalkAction)idl_checkFinalized, &count);
        }
    }
    return !count;
}
Пример #12
0
c_bool
d_groupCreationQueueAdd(
    d_groupCreationQueue queue,
    d_group group)
{
    c_bool result;
    d_group found;
    d_durability durability;
    assert(d_objectIsValid(d_object(queue), D_GROUP_CREATION_QUEUE) == TRUE);

    result = FALSE;

    if(queue) {
        d_lockLock(d_lock(queue));

        found = c_iterResolve(queue->groups, (c_iterResolveCompare)compareGroups, group);

        if(found == NULL){
            queue->groups = c_iterInsert(queue->groups, group);

            switch(d_groupGetKind(group)){
            case D_DURABILITY_VOLATILE:
                queue->groupsToCreateVolatile++;
                break;
            case D_DURABILITY_TRANSIENT:
            case D_DURABILITY_TRANSIENT_LOCAL:
                queue->groupsToCreateTransient++;
                break;
            case D_DURABILITY_PERSISTENT:
                queue->groupsToCreatePersistent++;
                break;
            default:
                assert(FALSE);
                break;
            }
            durability = d_adminGetDurability(queue->admin);
            d_durabilityUpdateStatistics(durability, d_statisticsUpdateGroupsToCreate, queue);
            result = TRUE;
        }
        d_lockUnlock(d_lock(queue));

    }
    return result;
}
Пример #13
0
static void
checkTopicKeyList (
    v_entity e,
    c_voidp arg)
{
    c_array keyList = v_topicMessageKeyList(e);
    checkTopicKeyListArg *info  = (checkTopicKeyListArg *) arg;
    c_long i;
    gapi_char *name;
    c_long size;
    c_iter iter;
    gapi_boolean equal = TRUE;

    iter = c_splitString(info->keyList, " \t,");

    if ( iter ) {
        size = c_arraySize(keyList);

        for ( i = 0; equal && (i < size); i++ ) {
            name = (gapi_char *)c_iterResolve(iter,
                                              topicKeyCompare,
                                              keyNameFromField(keyList[i]));
            if ( !name ) {
                equal = FALSE;
                OS_REPORT_2(OS_API_INFO,
                            "gapi::kernelCheckTopicKeyList", 0,
                            "incompatible key <%s> found for topic <%s>",
                            keyNameFromField(keyList[i]),
                            v_entityName(e));
            }
        }
        name = c_iterTakeFirst(iter);
        while ( name ) {
            os_free(name);
            name = c_iterTakeFirst(iter);
        }
        c_iterFree(iter);
    }
    info->equal = equal;
}
Пример #14
0
/* This operation scans through the list of items within the 'stac' pragma.
 * For each structure that is identified it will locate the corresponding
 * meta structure. It will then locate each member mentioned in the 'stac'
 * pragma within the member list of said meta structure. It will verify the
 * located member is indeed a character array.
 * It will then proceed to replace the meta data describing the located member
 * with new meta data with as goal to have the new meta data identify the member
 * as a string instead of as a character array.
 * All replaced meta data is stored in out variables to facilitate restore the
 * member list of the meta structure back into it's original configuration.
 * This operation is needed then the meta data of the found structure is
 * converted to XML. As the XML generation code is located in the database and
 * we do not want the database to get knowledge of the 'stac' pragma.
 */
c_iter
idl_stacDefConvertAll(
    idl_stacDef stacDef)
{
    os_uint32 size;
    os_uint32 i;
    idl_stacMap stacMapItem;
    c_structure structure;
    c_iter memberNames;
    os_uint32 memberNamesSize;
    os_uint32 j;
    os_char* memberName;
    os_int32 memberIndex;
    c_member member;
    c_member newMember;
    os_uint32* replacedIndex;
    idl_stacDefReplaceInfo replaceData;
    c_iter replaceInfo = NULL;
    c_base base;
    c_iter boundedStringToBeConverted;
    os_boolean stacCanBeApplied = OS_TRUE;
    os_boolean onlyExclusionlistings;

    if(stacDef)
    {

        /* Create collections to hold the original members and their respective
         * indexes in the member collection so we can easily restore the meta
         * structure to it's original configuration at a later time.
         */
        replaceInfo = c_iterNew(NULL);
        size = c_iterLength (stacDef->stacList);
        for(i = 0; i < size; i++)
        {
            stacMapItem = c_iterObject (stacDef->stacList, i);
            /* find the matching structure in the meta data */
            structure = idl_stacDefFindMetaStructureResolved(
                stacMapItem->scope,
                stacMapItem->typeName);
            assert(structure);
            replaceData = os_malloc(C_SIZEOF(idl_stacDefReplaceInfo));
            replaceData->structure = structure;
            replaceData->replacedIndexes = c_iterNew(NULL);
            replaceData->replacedMembers = c_iterNew(NULL);
            memberNames = c_splitString(stacMapItem->stacList, ",");
            onlyExclusionlistings = idl_stacDefOnlyExclusionsDefined(stacMapItem->stacList);
            memberNamesSize = c_iterLength(memberNames);
            boundedStringToBeConverted = c_iterNew(NULL);
            if(memberNamesSize == 0 || onlyExclusionlistings)
            {
                os_uint32 membersSize;
                membersSize = c_arraySize(structure->members);
                for(j = 0; j < membersSize; j++)
                {
                    member = c_member(structure->members[j]);
                    memberName = c_specifier(member)->name;
                    /* check if this member is in the list of member names when
                     * the member names list contains exclusion listings
                     */
                    if((onlyExclusionlistings && c_iterResolve(memberNames, idl_stacDefNamesAreEqual, memberName) == NULL) ||
                       memberNamesSize == 0)
                    {
                        stacCanBeApplied = idl_stacDefCanStacBeAppliedToMember(c_specifier(member)->type);
                        if(stacCanBeApplied)
                        {
                            /* this is a bounded string, so we want to convert */
                            c_iterInsert(boundedStringToBeConverted, member);
                        }
                    }
                }
            }
            else
            {
                for(j = 0; j < memberNamesSize; j++)
                {
                    memberName = c_iterTakeFirst(memberNames);
                    if(memberName[0] == '!')
                    {
                        printf("FATAL ERROR | #pragma stac: Illegal syntax combination detected. "
                               "The pragma stac definition for structure %s contains both normal "
                               "member listings (without the '!' character in front of them) as "
                               "well as exclusion member listings (with the '!' character in front "
                               "of them). This has no relevant meaning, please see the deployment manual "
                               "for information on usage of pragma stac.\n"
                               "Ignoring the following member defintion: '%s'\n",
                               c_metaScopedName(c_metaObject(structure)),
                               memberName);
                        exit(-2);
                    }
                    memberIndex = idl_stacDefFindMemberIndexByName(
                        structure->members,
                        memberName);
                    if(memberIndex == -1)
                    {
                        printf("FATAL ERROR | #pragma stac: Unable to locate member %s "
                            "within structure %s.\n",
                            memberName, c_metaScopedName(c_metaObject(structure)));
                        exit(-2);
                    }
                    member = structure->members[memberIndex];
                    /* Verify the member is a bounded string as required */
                    stacCanBeApplied = idl_stacDefCanStacBeAppliedToMember(c_specifier(member)->type);
                    if(!stacCanBeApplied)
                    {
                        printf("FATAL ERROR | #pragma stac: Member %s within structure "
                            "%s is not a bounded string (note: may be embedded within an array or sequence) as required.\n",
                            memberName, c_metaScopedName(c_metaObject(structure)));
                            assert(0);
                        exit(-2);
                    }
                    /* this is a bounded string, so we want to convert */
                    c_iterInsert(boundedStringToBeConverted, member);
                }

            }

            while(c_iterLength(boundedStringToBeConverted) > 0)
            {
                member = c_iterTakeFirst(boundedStringToBeConverted);
                memberIndex = idl_stacDefFindMemberIndexByName(
                    structure->members,
                    c_specifier(member)->name);
                assert(memberIndex != -1);
                newMember = c_metaDefine(c_metaObject(structure), M_MEMBER);
                base = c_getBase(member);
                c_specifier(newMember)->name = c_stringNew(base, c_specifier(member)->name);
                 c_specifier(newMember)->type = idl_stacDefConvertStacApprovedMember(structure, c_specifier(member)->type);
                if(!c_specifier(newMember)->type)
                {
                    printf("FATAL ERROR | #pragma stac: An internal error occured. Member %s within structure "
                        "%s failed to convert from a bounded string to a character array.\n",
                        c_specifier(newMember)->name, c_metaScopedName(c_metaObject(structure)));
                        assert(0);
                    exit(-2);
                }
                structure->members[memberIndex] = newMember;
                c_iterInsert(replaceData->replacedMembers, member);
                replacedIndex = os_malloc(sizeof(os_uint32));
                *replacedIndex = (os_uint32)memberIndex;
                c_iterInsert(replaceData->replacedIndexes, replacedIndex);
            }
            c_iterInsert(replaceInfo, replaceData);
        }
    }
    return replaceInfo;
}
Пример #15
0
u_result
u_waitsetDetach_s(
    const u_waitset _this,
    const u_observable observable)
{
    u_waitsetEntry entry;
    u_domain domain;
    u_result result;
    os_result osr;

    assert(_this != NULL);
    assert(observable != NULL);

    osr = os_mutexLock_s(&_this->mutex);
    if (osr == os_resultSuccess) {
        domain = u_observableDomain(observable);
        if (domain != NULL) {
            entry = c_iterResolve(_this->entries, compare_domain, domain);
            if (entry != NULL) {
                /* The following detach will wakeup any blocking wait call on this entry. */
                result = u_waitsetEntryDetach(entry, observable);
                if (result == U_RESULT_UNSUPPORTED) {
                    _this->detachCnt++;
                    /* removed last observable for this entry so can detach from domain. */
                    entry = c_iterTake(_this->entries, entry); /* use overwrite entry */
                    result = u_domainRemoveWaitset(domain, _this);
                    if (c_iterLength(_this->entries) == 1) {
                        _this->multi_mode = OS_FALSE;
                    } else {
                        _this->multi_mode = OS_TRUE;
                    }
                    while (_this->waitBusy) {
                        os_condWait(&_this->waitCv, &_this->mutex);
                    }

                    _this->detachCnt--;
                    /* Broadcast the detachCnt update. */
                    os_condBroadcast(&_this->waitCv);

                    os_mutexUnlock(&_this->mutex);
                    u_objectFree(entry);
                } else {
                    os_mutexUnlock(&_this->mutex);
                }
            } else {
                /* Check if the condition is already deleted */
                v_public ko;
                result = u_observableReadClaim(observable, &ko, C_MM_RESERVATION_NO_CHECK);
                if (result == U_RESULT_OK) {
                    u_observableRelease(observable, C_MM_RESERVATION_NO_CHECK);
                    result = U_RESULT_PRECONDITION_NOT_MET;
                    OS_REPORT(OS_ERROR, "u_waitSetDetach_s", result, "Condition is not attached to Waitset");
                }
                os_mutexUnlock(&_this->mutex);
            }
        } else {
            os_mutexUnlock(&_this->mutex);
            result = U_RESULT_INTERNAL_ERROR;
            OS_REPORT(OS_ERROR, "u_waitsetDetach_s", result,
                      "Failed to connect to domain.");
        }
    } else {
        result = U_RESULT_INTERNAL_ERROR;
        OS_REPORT(OS_ERROR, "u_waitSetDetach_s", result, "Could not lock the waitset.");
    }
    return result;
}
Пример #16
0
u_result
u_waitsetAttach(
    const u_waitset _this,
    const u_observable observable,
    void *context)
{
    u_waitsetEntry entry;
    u_domain domain;
    u_result result;
    c_ulong length;
    u_bool changed = FALSE;
    os_result osr;

    assert(_this != NULL);
    assert(observable != NULL);

    osr = os_mutexLock_s(&_this->mutex);
    if (osr == os_resultSuccess) {
        length = c_iterLength(_this->entries);
        domain = u_observableDomain(observable);
        if (domain != NULL) {
            entry = c_iterResolve(_this->entries, compare_domain, domain);
        } else {
            entry = NULL;
        }
        if ((entry == NULL)&&(domain != NULL)) {
            result = u_domainAddWaitset(domain, _this);
            if (result == U_RESULT_OK) {
                entry = u_waitsetEntryNew(_this, domain, _this->eventMask);
                if (entry != NULL) {
                    _this->entries = c_iterInsert(_this->entries, entry);
                    changed = TRUE;
                }
            } else {
                result = U_RESULT_INTERNAL_ERROR;
                OS_REPORT(OS_ERROR, "u_waitSetAttach", result, "Failed to add waitset to domain.");
            }
        }
        if (entry != NULL) {
            result = u_waitsetEntryAttach(entry, observable, context);
        } else {
            result = U_RESULT_INTERNAL_ERROR;
            OS_REPORT(OS_ERROR, "u_waitSetAttach", result, "Failed to connect to domain.");
        }
        if (changed == TRUE) {
            if (length == 0) {
                /* Wakeup waitset because its no longer in zero domain mode */
                _this->multi_mode = OS_FALSE;
                os_condSignal(&_this->cv);
                result = U_RESULT_OK;
            } else if (length == 1) {
                _this->multi_mode = OS_TRUE;
                c_iterWalk(_this->entries, set_multi_mode, (c_voidp)&_this->multi_mode);
            }
        }
        os_mutexUnlock(&_this->mutex);
    } else {
        result = U_RESULT_INTERNAL_ERROR;
        OS_REPORT(OS_ERROR, "u_waitSetAttach", result, "Could not lock the waitset.");
    }
    return result;
}