XCube Stream Reader SDK
Public Member Functions
CPacketBuffer Class Reference

Class of packet buffer. More...

#include <CPacketBuffer.h>

List of all members.

Public Member Functions

 CPacketBuffer ()
 Constructor.
virtual ~CPacketBuffer ()
 De-constructor.
bool initialize (size_t bufSz)
 Initialize the buffer and set it to a bufSz bytes.
bool isOkToWrite (size_t nByte, bool isBlock)
 Check whether packet buffer can be written in nByte data.
char * getWrPtr ()
 Get the current write pointer for the buffer.
void addBytesWritten (size_t nBytes)
 Add bytes written in the buffer.
void setEOF ()
 Set to indicate end of input stream us reached.
bool hasEOF ()
 Query whether the end of input stream is reached.
size_t getFreeBytes ()
 Query how many bytes available on this packet buffer.
size_t getValidBytes ()
 Query how many valid bytes are there on this packet buffer.
X3cPacketgetPacket ()
 Get a pointer to the first packet in the buffer.
char * getBytes (size_t nbytes)
 Return a pointer to a number of bytes in the buffer.
void freeBytes (char *ptr, size_t nBytes)
 Free the number of bytes in the buffer pointed to by ptr.
void reset ()
 Reset the packet buffer to empty and clean state.
void waitForRead ()
 Blocking call waiting for a read to happen.
void waitForWrite ()
 Blocking call waiting for a write to happen.

Detailed Description

Class of packet buffer.

The packet buffer class is designed to accommodate one reader and one writer process to insert chunks of chunkSz data to the buffer (when there is space for it) and read X3C packet size chunks of data out of the buffer when available


Constructor & Destructor Documentation

Constructor.

Creates a new instance of packet buffer, clean all data fields initialize unnamed semaphores

virtual CPacketBuffer::~CPacketBuffer ( ) [virtual]

De-constructor.

Detach all shared memory and destroy any unnamed semaphores


Member Function Documentation

void CPacketBuffer::addBytesWritten ( size_t  nBytes)

Add bytes written in the buffer.

when a write to the buffer has been done this function is called to update the valid bytes in the buffer

Parameters:
nBytes- Number of bytes actually written
void CPacketBuffer::freeBytes ( char *  ptr,
size_t  nBytes 
)

Free the number of bytes in the buffer pointed to by ptr.

Important: The free pointer in the buffer is moved to the last position of this packet, this means that all previous packets are freed to, it is the responsibility of the calling application to free bytes in the buffer up to the last item they want, no checks are done here.

Parameters:
ptr- pointer to start of array to free
nBytes- number of bytes in this segment
char* CPacketBuffer::getBytes ( size_t  nbytes)

Return a pointer to a number of bytes in the buffer.

Parameters:
nbytes- number of bytes requested in array (updates buffer state)
Returns:
- a pointer to a char[] of nByte size

Query how many bytes available on this packet buffer.

This is how many free bytes the buffer has, it is always used to judge whether a chunk of data is OK to be written into the buffer

Returns:
- number of empty byte locations in buffer

Get a pointer to the first packet in the buffer.

Returns:
- a pointer to the first X3C packet in the buffer null if not enough data

Query how many valid bytes are there on this packet buffer.

This is how many valid data bytes the buffer currently has

Returns:
- number of valid bytes in buffer

Get the current write pointer for the buffer.

Returns:
- first empty byte in the buffer

Query whether the end of input stream is reached.

If end of file is reached in the reader, return true

Returns:
- true if reader has reached end of stream
bool CPacketBuffer::initialize ( size_t  bufSz)

Initialize the buffer and set it to a bufSz bytes.

If buffer is already initialized the old allocation is deleted and all processes using the buffer will have undefined results if using old pointers.

Parameters:
bufSz- the requested size in bytes
Returns:
- true if successful
bool CPacketBuffer::isOkToWrite ( size_t  nByte,
bool  isBlock 
)

Check whether packet buffer can be written in nByte data.

Call to the buffer to see if there is enough space in it to write a chunk of data. This call can optionally block until such time that data is available

Parameters:
nBytes- the number of bytes requested to write
isBlock- set to true if caller wants to block this call
Returns:
- true if it is ok to write a chunk of data to buffer, or return false

Set to indicate end of input stream us reached.

The disk writer will call this if the file-reader has reached end of stream or an unrecoverable error condition


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Friends Defines