예제 #1
0
void *
Coll_List_popFront(
    Coll_List *_this)
{
    Coll_Iter *element_to_remove;
    void *object = NULL;

    assert(_this);

    element_to_remove = _this->_first_element;

    if (element_to_remove){
        object = Coll_Iter_getObject(element_to_remove);

        /*  detach element from linked list */
        _this->_first_element = Coll_Iter_getNext(element_to_remove);
        if (_this->_first_element){
          Coll_Iter_setPrev(_this->_first_element, NULL);
        } else {
          _this->_last_element = NULL;
        }
        _this->_nr_elements--;

        /*  delete the element */
        Coll_Iter_delete(element_to_remove);

    }
    return object;
}
예제 #2
0
Coll_Iter *
Coll_Set_find(
    Coll_Set *_this,
    void *object)
{
    Coll_Iter *iter;
    int ready ;

    DLRL_INFO_OBJECT(INF_ENTER);

    assert(_this);
    /* object may be null */

    iter = _this->_first_element;

    ready = (iter) ? 0 : 1;

    while (!ready){
        int isLess = _this->_isLess(object, Coll_Iter_getObject(iter));

        if ( !(isLess || _this->_isLess(Coll_Iter_getObject(iter), object)) ){
            /*  equal => ready */
            ready = 1;
        } else if (isLess && _this->_is_sorted){
            /*  smaller => object does not exist */
            iter = NULL;
            ready = 1;
        } else {
            /*  larger => continue search */
            iter = Coll_Iter_getNext(iter);
            if (!iter){
                ready = 1;
            }
        }
    }
    DLRL_INFO(INF_EXIT);
    return iter;
}
예제 #3
0
/* but sometimes you are just into italian food... */
void*
Coll_Set_remove(
    Coll_Set *_this,
    void *object)
{
    void* returnVal = NULL;
    Coll_Iter *iter;
    Coll_Iter *prev;
    Coll_Iter *next;

    DLRL_INFO_OBJECT(INF_ENTER);

    assert(_this);
    /* object may be null */

    iter = Coll_Set_find(_this, object);
    if (iter){
        returnVal = Coll_Iter_getObject(iter);
        prev = Coll_Iter_getPrev(iter);
        next = Coll_Iter_getNext(iter);

        /*  delink the found element from the set */
        if (prev){
            Coll_Iter_setNext(prev, next);
        }
        if (next){
            Coll_Iter_setPrev(next, prev);
        }

        /*  update set administration */
        if (iter == _this->_first_element){
            _this->_first_element = next;
        }
        if (iter == _this->_last_element){
            _this->_last_element = prev;
        }
        _this->_nr_elements--;

        /*  Free element */
        Coll_Iter_delete(iter);
    }
    DLRL_INFO(INF_EXIT);
    return returnVal;
}
void
DK_CacheAccessTypeRegistry_us_commitChanges(
    DK_CacheAccessTypeRegistry* _this,
    DLRL_Exception* exception,
    void* userData)
{
    DK_ObjectAdmin* object = NULL;
    Coll_Iter* iterator = NULL;
    DK_ObjectWriter* objWriter = NULL;

    DLRL_INFO_OBJECT(INF_ENTER);
    assert(_this);
    assert(exception);
    /* userData may be null */

    objWriter = DK_ObjectHomeAdmin_us_getObjectWriter(_this->home);
    iterator = Coll_Set_getFirstElement(&(_this->changedObjects));
    while(iterator)
    {
        object = (DK_ObjectAdmin*)Coll_Iter_getObject(iterator);
        assert(DK_ObjectAdmin_us_getWriteState(object) !=
            DK_OBJECT_STATE_OBJECT_NOT_MODIFIED);
        if(DK_ObjectAdmin_us_getWriteState(object) ==
            DK_OBJECT_STATE_OBJECT_DELETED)
        {
            DK_ObjectWriter_us_dispose(objWriter, exception, userData, object);
            DLRL_Exception_PROPAGATE(exception);
            Coll_Set_remove(&(_this->objects), object);
            /* release ref count from objects list */
            DK_Entity_ts_release((DK_Entity*)object);
        } else
        {
            DK_ObjectWriter_us_write(objWriter, exception, userData, object);
            DLRL_Exception_PROPAGATE(exception);
            assert(DK_ObjectAdmin_us_getWriteState(object) ==
                DK_OBJECT_STATE_OBJECT_NOT_MODIFIED);
        }
        iterator = Coll_Iter_getNext(iterator);
        Coll_Set_remove(&(_this->changedObjects), object);
    }
    DLRL_Exception_EXIT(exception);
    DLRL_INFO(INF_EXIT);
}
예제 #5
0
void *
Coll_List_getObject(
    Coll_List *_this,
    unsigned long index)
{
    void *retValue = NULL;
    Coll_Iter *element;
    unsigned long i = 0;

    assert(_this);

    element = _this->_first_element;

    while (element && (i < index) ){
        element = Coll_Iter_getNext(element);
        i++;
    }
    if (element){
        retValue = Coll_Iter_getObject(element);
    }
    return retValue;
}
/* requires lock on all homes in the CacheAccess */
void
DK_CacheAccessTypeRegistry_ts_destroy(
    DK_CacheAccessTypeRegistry* _this,
    void* userData)
{
    Coll_Iter* iterator = NULL;
    DK_ObjectAdmin* objectAdmin= NULL;
    DLRL_Exception exception;
    DK_ObjectWriter* objWriter = NULL;
    u_writer writer = NULL;

    DLRL_INFO_OBJECT(INF_ENTER);

    assert(_this);

    DK_CacheAccessTypeRegistry_lock(_this);

    /* clear unresolved list */
    DLRL_Exception_init(&exception);
    DK_UnresolvedObjectsUtility_us_clear(&(_this->unresolvedElements),userData);

    iterator = Coll_Set_getFirstElement(&(_this->changedObjects));
    while(iterator)
    {
        objectAdmin = (DK_ObjectAdmin*)Coll_Iter_getObject(iterator);
        iterator = Coll_Iter_getNext(iterator);
        Coll_Set_remove(&(_this->changedObjects), objectAdmin);
    }
    assert(_this->home);
    assert(DK_ObjectHomeAdmin_us_isAlive(_this->home));
    objWriter = DK_ObjectHomeAdmin_us_getObjectWriter(_this->home);
    assert(objWriter);
    assert(DK_ObjectWriter_us_isAlive(objWriter));
    writer = DK_ObjectWriter_us_getWriter(objWriter);
    assert(writer);
    iterator = Coll_Set_getFirstElement(&(_this->objects));
    while(iterator)
    {
        objectAdmin = (DK_ObjectAdmin*)Coll_Iter_getObject(iterator);
        iterator = Coll_Iter_getNext(iterator);
        Coll_Set_remove(&(_this->objects), objectAdmin);
        DK_DCPSUtility_us_unregisterObjectFromWriterInstance(
            &exception,
            objectAdmin,
            writer);
        if(exception.exceptionID != DLRL_NO_EXCEPTION)
        {
          DLRL_REPORT(REPORT_ERROR, "Exception %s occured when attempting to "
            "unregister an object from a writer instance\n%s",
            DLRL_Exception_exceptionIDToString(exception.exceptionID),
            exception.exceptionMessage);

            /* reset the exception, maybe it's used again later in this
             * deletion function. We dont propagate the exception here anyway,
             * so it can do no harm as we already logged the exception directly
             * above.
             */
            DLRL_Exception_init(&exception);
        }
        DK_ObjectAdmin_us_delete(objectAdmin, userData);
        DK_Entity_ts_release((DK_Entity*)objectAdmin);
    }
    iterator = Coll_Set_getFirstElement(&(_this->unregisteredObjects));
    while(iterator)
    {
        objectAdmin = (DK_ObjectAdmin*)Coll_Iter_getObject(iterator);
        iterator = Coll_Iter_getNext(iterator);
        Coll_Set_remove(&(_this->unregisteredObjects), objectAdmin);
        DK_ObjectAdmin_us_delete(objectAdmin, userData);
        DK_Entity_ts_release((DK_Entity*)objectAdmin);
    }
    DK_CacheAccessTypeRegistry_us_resetModificationInformation(_this, userData);
    DK_CacheAccessTypeRegistry_unlock(_this);
    if(_this->home)
    {
        DK_Entity_ts_release((DK_Entity*)_this->home);
        _this->home = NULL;
    }
    os_free(_this);

    DLRL_INFO(INF_EXIT);
}
예제 #7
0
long
Coll_Set_add(
    Coll_Set *_this,
    void *object)
{
    long retValue;
    Coll_Iter *new_element;

    DLRL_INFO_OBJECT(INF_ENTER);

    assert(_this);
    /* object may be null */

    if (!_this->_is_sorted && !Coll_Set_find(_this, object)){
        /*  set is unsorted and does not contain the to be added object => the object can be added as a unique object */
        retValue = Coll_Set_addUniqueObject(_this, object);
    } else {
        /*  set is sorted, add the object at the right place */
        new_element = Coll_Iter_new();
        if (!new_element){
            retValue = COLL_ERROR_ALLOC;
        } else {
            Coll_Iter_setObject(new_element, object);

            if ( (_this->_nr_elements == 0) || (_this->_isLess(object, Coll_Iter_getObject(_this->_first_element) ) ) ){
                /*  first object to insert */
                Coll_Iter_setNext(new_element, _this->_first_element);
                if (_this->_first_element){
                    Coll_Iter_setPrev(_this->_first_element, new_element);
                }
                _this->_first_element = new_element;

                /*  update set administration */
                _this->_nr_elements++;
            } else {
                int ready = 0;

                /*  insert object at the right place */
                Coll_Iter *iter = _this->_first_element;

                while (!ready) {
                    int isLess = _this->_isLess(object, Coll_Iter_getObject(iter));

                    if ( !(isLess || _this->_isLess(Coll_Iter_getObject(iter), object)) ) {
                        /*  equal => element already exists in set => delete iterator object again */
                        Coll_Iter_delete(new_element);
                        ready = 1;
                    } else if (isLess) {
                        /*  smaller => insert the new element here */
                        Coll_Iter_setNext(new_element, iter);
                        Coll_Iter_setPrev(new_element, Coll_Iter_getPrev(iter));
                        Coll_Iter_setNext(Coll_Iter_getPrev(iter), new_element);
                        Coll_Iter_setPrev(iter, new_element);

                        /*  update set administration */
                       _this->_nr_elements++;

                        ready = 1;
                    } else if (Coll_Iter_getNext(iter) == NULL){
                        /*  append new element to the end of the set */
                        Coll_Iter_setPrev(new_element, iter);
                        Coll_Iter_setNext(iter, new_element);

                        /*  update set administration */
                        _this->_last_element = new_element;
                        _this->_nr_elements++;

                        ready = 1;
                    } else {
                        /*  do nothing */
                    }
                    iter = Coll_Iter_getNext(iter);
                }
            }
            retValue = COLL_OK;
        }
    }
    DLRL_INFO(INF_EXIT);
    return retValue;
}
예제 #8
0
/*writes and removes elements contained within the elements set */
void
DK_CollectionWriter_us_writeCollectionElements(
    DK_CollectionWriter* _this,
    DLRL_Exception* exception,
    DK_Collection* collection,
    Coll_Set* elements,
    void (*action)( v_entity,
                    c_voidp),
    LOC_boolean destroyWrittenHolders,
    LOC_boolean unregisterHolders)
{
    DMM_DLRLMultiRelation* metaCollection = NULL;
    Coll_List* targetKeys = NULL;
    Coll_List* ownerKeys = NULL;
    DMM_Basis base;
    Coll_List* collectionOwnerFields = NULL;
    Coll_List* collectionTargetFields = NULL;
    DK_ObjectAdmin* collectionOwner = NULL;
    c_value* ownerKeyValues = NULL;
    Coll_Iter* iterator = NULL;
    DK_ObjectHolder* holder = NULL;
    v_message message = NULL;
    c_long offset = 0;
    void* dataSample = NULL;
    DK_ObjectAdmin* elementTarget = NULL;
    c_value* targetKeyValues = NULL;
    void* keyValue = NULL;
    DMM_DCPSField* collectionIndexField = NULL;
    DK_DCPSUtilityWriteMessageArg messageArg;/*  on stack def...     */
    u_result result;

    DLRL_INFO_OBJECT(INF_ENTER);
    assert(_this);
    assert(exception);
    assert(collection);
    assert(action);

    metaCollection = DK_Collection_us_getMetaRepresentative(collection);
    targetKeys = DMM_DLRLRelation_getTargetKeys((DMM_DLRLRelation*)metaCollection);
    ownerKeys = DMM_DLRLRelation_getOwnerKeys((DMM_DLRLRelation*)metaCollection);
    base = DMM_DLRLMultiRelation_getBasis(metaCollection);
    collectionOwnerFields = DMM_DLRLMultiRelation_getRelationTopicOwnerFields(metaCollection);
    collectionTargetFields = DMM_DLRLMultiRelation_getRelationTopicTargetFields(metaCollection);
    collectionOwner = DK_Collection_us_getOwner(collection);
    assert(collectionOwner);
    ownerKeyValues = DK_ObjectAdmin_us_getKeyValueArray(collectionOwner);/* may return NULL */

    iterator = Coll_Set_getFirstElement(elements);
    while(iterator)
    {
        holder = (DK_ObjectHolder*)Coll_Iter_getObject(iterator);
        message = DK_DCPSUtility_ts_createMessageForDataWriter(_this->writer, exception, &offset);
        DLRL_Exception_PROPAGATE(exception);
        dataSample = C_DISPLACE(message, offset);
        /* now we have a data sample in which we can copy the key values and then write it... */
        DK_DCPSUtility_us_copyFromSource(exception, ownerKeys, ownerKeyValues, collectionOwnerFields, dataSample);
        DLRL_Exception_PROPAGATE(exception);
        elementTarget = DK_ObjectHolder_us_getTarget(holder);
        assert(elementTarget);
        targetKeyValues = DK_ObjectAdmin_us_getKeyValueArray(elementTarget);
        DK_DCPSUtility_us_copyFromSource(exception, targetKeys, targetKeyValues, collectionTargetFields, dataSample);
        DLRL_Exception_PROPAGATE(exception);
        if(base == DMM_BASIS_STR_MAP)
        {
            keyValue = DK_ObjectHolder_us_getUserData(holder);/*used later on for freeing purposes!*/
            assert(keyValue);
            collectionIndexField = DMM_DLRLMultiRelation_getIndexField(metaCollection);/* may return NULL */
            DK_DCPSUtility_us_copyStringIntoDatabaseSample((LOC_string)keyValue, collectionIndexField, dataSample);
        } else if(base == DMM_BASIS_INT_MAP)
        {
            keyValue = DK_ObjectHolder_us_getUserData(holder);/*used later on for freeing purposes!*/
            assert(keyValue);
            collectionIndexField = DMM_DLRLMultiRelation_getIndexField(metaCollection);/* may return NULL */
            DK_DCPSUtility_us_copyIntegerIntoDatabaseSample((LOC_long*)keyValue, collectionIndexField, dataSample);
        }
#ifndef NDEBUG
         else
        {
            /* else do nothing at all */
            assert(base == DMM_BASIS_SET);
        }
#endif

        /* now write the message... */
        messageArg.message = message;
        messageArg.exception = exception;
        result = u_entityWriteAction((u_entity)_this->writer, action, (void*)&messageArg);
        DLRL_Exception_PROPAGATE_RESULT(exception, result, "An error occured while trying to write a message into the system.");
        DLRL_Exception_PROPAGATE(exception);/* propagate the exception wrapped in the messageArg struct... */
        iterator = Coll_Iter_getNext(iterator);
        Coll_Set_remove(elements, holder);
        if(unregisterHolders && elementTarget)
        {
#if 0
            if(DK_ObjectAdmin_us_getWriteState(elementTarget) == DK_OBJECT_STATE_OBJECT_DELETED)
            {
                DK_CacheAccessAdmin_us_decreaseInvalidLinks(elementTarget->access);
            }
#endif
            DK_ObjectAdmin_us_unregisterIsRelatedFrom(elementTarget, holder);
        }
        if(destroyWrittenHolders)
        {
            if(keyValue)
            {
                os_free(keyValue);
                DK_ObjectHolder_us_setUserData(holder, NULL);
                keyValue = NULL;/* must set to null to prevent mistakes in the next iteration */
            }
            DK_ObjectHolder_us_destroy(holder);
        }
        if(message)
        {
            result = u_entityAction((u_entity)_this->writer, DK_DCPSUtility_us_freeMessage, (void*)message);
            DLRL_Exception_PROPAGATE_RESULT(exception, result, "An error occured while trying to free a v_message object.");
            message = NULL;
        }
    }

    DLRL_Exception_EXIT(exception);
    DLRL_INFO(INF_EXIT);
}