15 #ifndef VISIONTRANSFER_DATABLOCKPROTOCOL_H 16 #define VISIONTRANSFER_DATABLOCKPROTOCOL_H 21 #include "visiontransfer/alignedallocator.h" 42 static const int MAX_TCP_BYTES_TRANSFER = 0xFFFF;
43 static const int MAX_UDP_RECEPTION = 0x4000;
44 static const int MAX_OUTSTANDING_BYTES = 2*MAX_TCP_BYTES_TRANSFER;
60 return protType == PROTOCOL_UDP ?
sizeof(
unsigned short) : 0;
95 void setTransferData(
unsigned char* data,
int size,
int validBytes = 0x7FFFFFFF);
177 static const int MIN_UDP_BYTES_TRANSFER = 512;
179 ProtocolType protType;
180 int maxUdpPacketSize;
186 unsigned char* rawData;
190 unsigned short transferSeqNum;
191 unsigned short overwrittenTransferData;
192 bool restoreTransferData;
195 std::vector<unsigned char, AlignedAllocator<unsigned char> > receiveBuffer;
197 unsigned short receiveSeqNum;
198 unsigned char unprocessedMsgPart[MAX_OUTSTANDING_BYTES];
199 int unprocessedMsgLength;
200 int receiveTotalSize;
204 const unsigned char* extractPayload(
const unsigned char* data,
int& length,
bool& error);
void setReceiveDataSize(int size)
Sets the total size of the data that shall be received.
const unsigned char * getTransferMessage(int &length)
Gets the next network message for the current transfer.
DataBlockProtocol(ProtocolType protType, int maxUdpPacketSize)
Creates a new instance.
A protocol for transmitting large blocks of data over a network.
int getProtocolOverhead() const
Returns the size of the overhead data that is required for transferring a single network message...
unsigned char * getReceivedData(int &length)
Returns the data that has been received for the current data block.
void resetTransfer()
Stops the current transfer.
unsigned char * getNextReceiveBuffer(int maxLength)
Gets a buffer for receiving the next network message.
int getMaxReceptionSize() const
Returns the maximum paload size that can be recedived.
void resetReception()
Resets the message reception.
bool transferComplete()
Returns true if the current transfer has been completed.
bool processReceivedMessage(int length)
Handles a received network message.
void setTransferData(unsigned char *data, int size, int validBytes=0x7FFFFFFF)
Sets a new chunk of data that should be transferred.
void startTransfer()
Starts the transfer of a new data block.
void finishReception()
Finishes reception of the current data block.
void setTransferValidBytes(int validBytes)
Updates the number of valid bytes in a partial transmission.