AURobotServers  4
Public Member Functions | Protected Attributes | Private Attributes | List of all members
USockClient Class Reference

#include <usockclient.h>

Inheritance diagram for USockClient:
Inheritance graph

Public Member Functions

bool blockSend (const char *buffer, int length)
 
void closeConnection ()
 
virtual void connectionLost ()
 
bool doDisconnect ()
 
bool getDataFromLine (int pollTimeoutMs)
 
char * getHost ()
 
int getPort ()
 
void handleConnection (bool terminateOnDisconnect=false)
 
bool isConnected ()
 
virtual void pollTimeout ()
 
virtual void processMessage (unsigned char *message, int length)
 
int setHost (const char *iHost)
 
int setPort (int iPort)
 
virtual void sInfo (const char *message, int type)
 
virtual void transmissionTraffic (bool traffic)
 
bool tryConnect (bool andStartReceiveThread=true)
 
 USockClient ()
 
virtual ~USockClient ()
 

Protected Attributes

char host [MAX_HOST_LENGTH]
 
int pollTimeoutMs
 
int port
 
unsigned int readCnt
 

Private Attributes

unsigned char buf [MAX_BUFFER_LENGTH_RX]
 
bool connected
 
bool connectionGotLost
 
pthread_mutex_t ptLock
 
bool receiving
 
struct pollfd recvPollStatus
 
bool recvThreadRunning
 
bool sending
 
int sock
 
bool stop
 
bool stopNow
 
pthread_t thClient
 

Detailed Description

Socket client class.

Todo:
deprecated – use UClientPort - (but pt used by USmrCl)
Author
(Jens) Christian Andersen,326/030,3548,

Constructor & Destructor Documentation

USockClient::USockClient ( )
USockClient::~USockClient ( )
virtual

Destructor

References connected, and doDisconnect().

Member Function Documentation

bool USockClient::blockSend ( const char *  buffer,
int  length 
)
void USockClient::closeConnection ( )

Shutdown socket connection, but leave read thread running (in a wait loop). Use doDisconnect() to also terminate thread.

References connected, connectionLost(), sock, and transmissionTraffic().

Referenced by doDisconnect(), getDataFromLine(), and handleConnection().

void USockClient::connectionLost ( )
virtual

Is calle when commection is lost, to enable of disable functions at higher levels.

References scInfo, and sInfo().

Referenced by closeConnection().

bool USockClient::doDisconnect ( )

Disconnect from server and stop read thread. Use closeConnection() to just close socket.

Disconnect from server

References closeConnection(), recvThreadRunning, scInfo, sInfo(), stop, and thClient.

Referenced by blockSend(), tryConnect(), and ~USockClient().

bool USockClient::getDataFromLine ( int  pollTimeoutMs)

Poll socket and read data is souch is available. Returns true if data is received.

References buf, closeConnection(), connected, connectionGotLost, MAX_BUFFER_LENGTH_RX, pollTimeout(), processMessage(), receiving, recvPollStatus, scWarning, sending, sInfo(), sock, transmissionTraffic(), and Wait().

Referenced by isConnected().

char* USockClient::getHost ( )
inline

Set socket port number

References host.

int USockClient::getPort ( )
inline

Set socket port number

References port.

void USockClient::handleConnection ( bool  terminateOnDisconnect = false)

Handle connection - i.e. send buffers, when something to send and display received messages.

References closeConnection(), connected, receiving, recvThreadRunning, scWarning, sending, sInfo(), sock, stop, transmissionTraffic(), and Wait().

Referenced by isConnected(), and runSockClient().

bool USockClient::isConnected ( )
inline
void USockClient::pollTimeout ( )
virtual

This poll idle function is called at poll timeout times (everty 'pollTimeout' ms), and can be used to send new commands to the socket, if this is not done by main thread (not both!).

Referenced by getDataFromLine(), and isConnected().

void USockClient::processMessage ( unsigned char *  message,
int  length 
)
virtual

Process message This routine should be overwritten by something more meaningfull than just printing to log widget.

Reimplemented in UImgClientTest.

References MAX_SC_INFO_SIZE, mini(), scDebug, and sInfo().

Referenced by getDataFromLine(), and isConnected().

int USockClient::setHost ( const char *  iHost)
inline

Set socket port number

References host, and MAX_HOST_LENGTH.

int USockClient::setPort ( int  iPort)
inline

Set socket port number

References port.

void USockClient::sInfo ( const char *  message,
int  type 
)
virtual

Called when something is to be displayed or logged. if not handled by virtual function, then messages are just printed to console.

Reimplemented in UImgClientTest.

Referenced by blockSend(), connectionLost(), doDisconnect(), getDataFromLine(), handleConnection(), isConnected(), processMessage(), and tryConnect().

void USockClient::transmissionTraffic ( bool  traffic)
virtual

Is called if transmission starts or ends. Corresponding to turn on or off transmission lamp. is called when receiving or transmission is started or stopped.

Referenced by blockSend(), closeConnection(), getDataFromLine(), handleConnection(), isConnected(), and tryConnect().

bool USockClient::tryConnect ( bool  andStartReceiveThread = true)

Member Data Documentation

unsigned char USockClient::buf[MAX_BUFFER_LENGTH_RX]
private

Buffer fused by recv(...) call for new partial message

Referenced by getDataFromLine().

bool USockClient::connected
private
bool USockClient::connectionGotLost
private

Detection of lost connection

Referenced by getDataFromLine(), and USockClient().

char USockClient::host[MAX_HOST_LENGTH]
protected

Name of host to connect to

Referenced by getHost(), setHost(), tryConnect(), and USockClient().

int USockClient::pollTimeoutMs
protected

Poll read timeout value. At poll timeout the pollTimeout() is called. value is in milli seconds

Referenced by isConnected(), and USockClient().

int USockClient::port
protected

Port used when connecting to host

Referenced by getPort(), setPort(), tryConnect(), and USockClient().

pthread_mutex_t USockClient::ptLock
private

Mutex lock

Referenced by blockSend(), and USockClient().

unsigned int USockClient::readCnt
protected

Number of reads (with >0 bytes returned).

Referenced by USockClient().

bool USockClient::receiving
private

True as long as there is unfetched data

Referenced by blockSend(), getDataFromLine(), handleConnection(), and USockClient().

struct pollfd USockClient::recvPollStatus
private

Poll status used when polling for available data

Referenced by getDataFromLine(), and tryConnect().

bool USockClient::recvThreadRunning
private

Listening is true when read thread is running - listening to the socket

Referenced by doDisconnect(), handleConnection(), tryConnect(), and USockClient().

bool USockClient::sending
private

True during a send

Referenced by blockSend(), getDataFromLine(), handleConnection(), and USockClient().

int USockClient::sock
private
bool USockClient::stop
private

Flag to stop receiving thread.

Referenced by doDisconnect(), handleConnection(), tryConnect(), and USockClient().

bool USockClient::stopNow
private

Another stop flag that can stop an connection attempt - I think.

Referenced by tryConnect().

pthread_t USockClient::thClient
private

Handle to thread listening to messages

Referenced by doDisconnect(), and tryConnect().


The documentation for this class was generated from the following files: