ArNetPacketReceiverTcp Class Reference

#include <ArNetPacketReceiverTcp.h>

List of all members.


Detailed Description

This class receives TCP packets from a socket, you need to have an open socket and give it to the socket with setSocket, then you need to set up a callback to process packets with setProcessPacketCB, finally call readData which will read in all the data and call the processPacketCB.


Public Member Functions

 ArNetPacketReceiverTcp ()
 Constructor.
ArFunctor1< ArNetPacket * > * getProcessPacketCB (void)
 Gets the callback used when a packet is received.
bool getQuiet (void)
 Gets whether we're quiet about errors or not.
ArSocketgetSocket (void)
 Gets the socket this receiver uses.
bool readData (void)
 Reads in all the data available calling the processPacketCB.
void setLoggingPrefix (const char *loggingPrefix)
 Sets the logging prefix.
void setProcessPacketCB (ArFunctor1< ArNetPacket * > *functor)
 Sets the callback for use when a packet is received.
void setQuiet (bool quiet)
 Sets whether we're quiet about errors or not.
void setSocket (ArSocket *socket)
 Sets the socket this receiver uses.
 ~ArNetPacketReceiverTcp ()
 Destructor.

Protected Types

enum  { TOTAL_PACKET_LENGTH = ArNetPacket::MAX_LENGTH+ArNetPacket::HEADER_LENGTH+ArNetPacket::FOOTER_LENGTH }
enum  Ret {
  RET_CONN_CLOSED, RET_GOT_PACKET, RET_BAD_PACKET, RET_FAILED_READ,
  RET_TIMED_OUT
}
 RET_BAD_PACKET
 RET_CONN_CLOSED
 RET_FAILED_READ
 RET_GOT_PACKET
 RET_TIMED_OUT
enum  State {
  STATE_SYNC1, STATE_SYNC2, STATE_LENGTH1, STATE_LENGTH2,
  STATE_ACQUIRE_DATA
}
 STATE_ACQUIRE_DATA
 STATE_LENGTH1
 STATE_LENGTH2
 STATE_SYNC1
 STATE_SYNC2
 TOTAL_PACKET_LENGTH = ArNetPacket::MAX_LENGTH+ArNetPacket::HEADER_LENGTH+ArNetPacket::FOOTER_LENGTH

Protected Member Functions

Ret readPacket (int msWait)
 Reads in a single packet, returns NULL if not one.

Protected Attributes

ArTime myLastPacket
std::string myLoggingPrefix
ArNetPacket myPacket
ArFunctor1< ArNetPacket * > * myProcessPacketCB
bool myQuiet
char myReadBuff [TOTAL_PACKET_LENGTH]
int myReadCommand
int myReadCount
int myReadLength
ArSocketmySocket
State myState
unsigned char mySync1
unsigned char mySync2


Member Enumeration Documentation

anonymous enum [protected]

Enumerator:
TOTAL_PACKET_LENGTH 

enum ArNetPacketReceiverTcp::Ret [protected]

Enumerator:
RET_CONN_CLOSED 
RET_GOT_PACKET 
RET_BAD_PACKET 
RET_FAILED_READ 
RET_TIMED_OUT 

enum ArNetPacketReceiverTcp::State [protected]

Enumerator:
STATE_SYNC1 
STATE_SYNC2 
STATE_LENGTH1 
STATE_LENGTH2 
STATE_ACQUIRE_DATA 


Constructor & Destructor Documentation

ArNetPacketReceiverTcp::ArNetPacketReceiverTcp (  ) 

Constructor.

ArNetPacketReceiverTcp::~ArNetPacketReceiverTcp (  ) 

Destructor.


Member Function Documentation

ArFunctor1< ArNetPacket * > * ArNetPacketReceiverTcp::getProcessPacketCB ( void   ) 

Gets the callback used when a packet is received.

Returns:
the callback used when a packet needs to be processed

bool ArNetPacketReceiverTcp::getQuiet ( void   )  [inline]

Gets whether we're quiet about errors or not.

ArSocket * ArNetPacketReceiverTcp::getSocket ( void   ) 

Gets the socket this receiver uses.

bool ArNetPacketReceiverTcp::readData ( void   ) 

Reads in all the data available calling the processPacketCB.

If an error occurs that is unrecoverable false will be returned which means that the socket owner who is calling this should close the socket and clean up.

Returns:
false on an error that should cause the socket to be closed, true with no errors

ArNetPacketReceiverTcp::Ret ArNetPacketReceiverTcp::readPacket ( int  msWait  )  [protected]

Reads in a single packet, returns NULL if not one.

void ArNetPacketReceiverTcp::setLoggingPrefix ( const char *  loggingPrefix  ) 

Sets the logging prefix.

void ArNetPacketReceiverTcp::setProcessPacketCB ( ArFunctor1< ArNetPacket * > *  functor  ) 

Sets the callback for use when a packet is received.

Parameters:
functor the callback to use when a packet needs to be processed

void ArNetPacketReceiverTcp::setQuiet ( bool  quiet  )  [inline]

Sets whether we're quiet about errors or not.

void ArNetPacketReceiverTcp::setSocket ( ArSocket socket  ) 

Sets the socket this receiver uses.

Parameters:
socket the socket to use for receiving data


Member Data Documentation

ArTime ArNetPacketReceiverTcp::myLastPacket [protected]

std::string ArNetPacketReceiverTcp::myLoggingPrefix [protected]

ArNetPacket ArNetPacketReceiverTcp::myPacket [protected]

ArFunctor1<ArNetPacket *>* ArNetPacketReceiverTcp::myProcessPacketCB [protected]

bool ArNetPacketReceiverTcp::myQuiet [protected]

char ArNetPacketReceiverTcp::myReadBuff[TOTAL_PACKET_LENGTH] [protected]

int ArNetPacketReceiverTcp::myReadCommand [protected]

int ArNetPacketReceiverTcp::myReadCount [protected]

int ArNetPacketReceiverTcp::myReadLength [protected]

ArSocket* ArNetPacketReceiverTcp::mySocket [protected]

State ArNetPacketReceiverTcp::myState [protected]

unsigned char ArNetPacketReceiverTcp::mySync1 [protected]

unsigned char ArNetPacketReceiverTcp::mySync2 [protected]


The documentation for this class was generated from the following files:
Generated on Fri Jul 31 12:37:29 2009 for ArNetworking by  doxygen 1.4.7