pelican/server/src/ServiceDataBuffer.cpp
/**
 * @details
 * Gets a writable data object of the given size and returns it.
 * This object is locked, and on unlocking will become the current service data.
 *
 * @param[in] size The size of the writable data to return.
 */
@details
Gets a writable data object of the given size and returns it.
This object is locked, and on unlocking will become the current service data.

@param[in] size The size of the writable data to return.
@details Gets a writable data object of the given size and returns it . This object is locked and on unlocking will become the current service data . @param [ in ] size The size of the writable data to return .
WritableData ServiceDataBuffer::getWritable(size_t size)
{
    if (!_newData)
    {
        QMutexLocker lock(&_mutex);
        for (int i = 0; i < _expiredData.size(); ++i)
        {
            LockableServiceData* lockableData = _expiredData[i];
            if (lockableData->maxSize() >= size)
            {
                _data.remove(lockableData->id());
                _expiredData.removeAt(i);
                lockableData->setSize(size);
                return lockableData;
            }
        }
        if (size <= _space && size <= _maxChunkSize)
        {
            void* memory = calloc(size, sizeof(char));
            if (memory)
            {
                _space -= size;
                _newData = new LockableServiceData(_type, memory, size);
                connect(_newData, SIGNAL(unlockedWrite()), SLOT(activateData()));
                connect(_newData, SIGNAL(unlocked()), SLOT(deactivateData()));
                return WritableData(_newData);
            }
        }
    }
    return WritableData(0);
}
WritableData ServiceDataBuffer :: getWritable ( size_t size ) { if ( ! _newData ) { QMutexLocker lock ( & _mutex ) ; for ( int i = 0 ; i < _expiredData . size ( ) ; ++ i ) { LockableServiceData * lockableData = _expiredData [ i ] ; if ( lockableData -> maxSize ( ) >= size ) { _data . remove ( lockableData -> id ( ) ) ; _expiredData . removeAt ( i ) ; lockableData -> setSize ( size ) ; return lockableData ; } } if ( size <= _space && size <= _maxChunkSize ) { void * memory = calloc ( size , sizeof ( char ) ) ; if ( memory ) { _space -= size ; _newData = new LockableServiceData ( _type , memory , size ) ; connect ( _newData , SIGNAL ( unlockedWrite ( ) ) , SLOT ( activateData ( ) ) ) ; connect ( _newData , SIGNAL ( unlocked ( ) ) , SLOT ( deactivateData ( ) ) ) ; return WritableData ( _newData ) ; } } } return WritableData ( 0 ) ; }
@details
 Gets a writable data object of the given size and returns it.
@details Gets a writable data object of the given size and returns it .
// XXX find out what determines if _newData is allocated... // --> something to do with activation of the data. // (activateData() method...) // If the temporary lockable service data chunk isn't allocated. // XXX what is this check for? // Check if any of the expired data chunks can be reused. // We found one, so reuse it and remove it from the // expired data queue. // Create a new data object if we have enough space. // Released in destructor. // No free containers so we return an invalid // FIXME Clarify this return case. // It seems we get here if // 1) There is no memory left in the buffer. // 2) There is already an active LockableServiceData chunk. // NOTE: case (2) needs looking into more carefully.