XCube Stream Reader SDK
|
Class of packet buffer. More...
#include <CPacketBuffer.h>
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. | |
X3cPacket * | getPacket () |
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. |
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.
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
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
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.
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.
nbytes | - number of bytes requested in array (updates buffer state) |
size_t CPacketBuffer::getFreeBytes | ( | ) |
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
Get a pointer to the first packet in the buffer.
size_t CPacketBuffer::getValidBytes | ( | ) |
Query how many valid bytes are there on this packet buffer.
This is how many valid data bytes the buffer currently has
char* CPacketBuffer::getWrPtr | ( | ) |
Get the current write pointer for the buffer.
bool CPacketBuffer::hasEOF | ( | ) |
Query whether the end of input stream is reached.
If end of file is reached in the reader, return true
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.
bufSz | - the requested size in bytes |
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
nBytes | - the number of bytes requested to write |
isBlock | - set to true if caller wants to block this call |
void CPacketBuffer::setEOF | ( | ) |
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