ApparatusFramework::RingBuffer Class Reference
[Device Services]

#include <DeviceServices/Win32/current/include/SerialPort.h>

List of all members.

Public Member Functions

 RingBuffer ()
 ~RingBuffer ()
BOOL setSize (WORD size)
BOOL push (BYTE data)
BOOL pop (BYTE &data)
BOOL push (BYTE *data, WORD len)
BOOL pop (BYTE *data, WORD len)
void flush ()
WORD spaceFree ()
WORD spaceUsed ()

Detailed Description

The class RingBuffer is such a lean implementation of a ring buffer. The buffer size is specified at creation time and cannot be changed afterwards. With push and pop methods the user can fill data in and take data from the ring buffer. Every access to the buffer is synchronized. The only other feature the buffer provides is information about the number of elements currently in the buffer.

Definition at line 86 of file SerialPort.h.


Constructor & Destructor Documentation

ApparatusFramework::RingBuffer::RingBuffer (  ) 

Constructors, destructors The constructor initializes all members of the class to zero values and sets up the semaphore used for the synchronization mechanism. Afterwards the size of the buffer is zero and push and pop actions will always fail because of 'not enough space' or 'not enough data' conditions. To use the buffer the user has to set a size different from 0 with the method setSize().

ApparatusFramework::RingBuffer::~RingBuffer (  ) 

The destructor deallocates the buffer memory, which has been allocated by the setSize() method.


Member Function Documentation

void ApparatusFramework::RingBuffer::flush (  ) 

Flush empty the ring buffer.

Referenced by ApparatusFramework::SerialPort::flush().

BOOL ApparatusFramework::RingBuffer::pop ( BYTE *  data,
WORD  len 
)

Pop takes a given number of bytes from the buffer.

Parameters:
data Address where the first byte has to be written to.
len Number of bytes to be taken from the ring buffer.
Returns:
Returns FALSE if there is not enough data in the ring buffer.
BOOL ApparatusFramework::RingBuffer::pop ( BYTE &  data  ) 

Pop takes one byte from the buffer.

Parameters:
data The byte to be taken from the ring buffer.
Returns:
Returns FALSE if the buffer is empty.
BOOL ApparatusFramework::RingBuffer::push ( BYTE *  data,
WORD  len 
)

Push fills a given number of bytes into the buffer.

Parameters:
data Address of the first byte.
len Number of bytes to be filled into the ring buffer.
Returns:
Returns FALSE if there is not enough data in the ring buffer.
BOOL ApparatusFramework::RingBuffer::push ( BYTE  data  ) 

Buffer manipulation Push fills one byte into the buffer.

Parameters:
data The byte to be filled into the ring buffer.
Returns:
Returns FALSE if there is not enough space in the ring buffer left.
BOOL ApparatusFramework::RingBuffer::setSize ( WORD  size  ) 

Initialization The method changes the size of the ring buffer. It is only allowed to change the size if there is no data in the buffer. With this condition we are certain that a change of size does not result in a loss of data. This method has to be called at least once after the class is created because the initial size of the buffer is 0.

Parameters:
size Size of the ring buffer. This is the number of bytes the setSize() method allocates
Returns:
Returns FALSE if there is some data in the buffer or if the allocation of the buffer memory fails.
WORD ApparatusFramework::RingBuffer::spaceFree (  ) 

Buffer status Returns the number of bytes free in the ring buffer.

Returns:
Number of bytes free in the ring buffer.
WORD ApparatusFramework::RingBuffer::spaceUsed (  ) 

Returns the number of bytes occupied in the ring buffer.

Returns:
Number of bytes occupied in the ring buffer.
© 2004-2010 bbv Software Services AG / Apparatus Services