AURobotServers
4
|
#include <usockclient.h>
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 |
Socket client class.
USockClient::USockClient | ( | ) |
Constructor
References connected, connectionGotLost, host, pollTimeoutMs, port, ptLock, readCnt, receiving, recvThreadRunning, sending, sock, and stop.
|
virtual |
Destructor
References connected, and doDisconnect().
bool USockClient::blockSend | ( | const char * | buffer, |
int | length | ||
) |
Send this buffer of data
References connected, doDisconnect(), MAX_SC_INFO_SIZE, ptLock, receiving, scDebug, scWarning, sending, sInfo(), sock, and transmissionTraffic().
Referenced by isConnected().
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().
|
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().
|
inline |
Set socket port number
References host.
|
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().
|
inline |
Is connected to server
References blockSend(), connected, getDataFromLine(), handleConnection(), pollTimeout(), pollTimeoutMs, processMessage(), sInfo(), and transmissionTraffic().
|
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().
|
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().
|
inline |
Set socket port number
References host, and MAX_HOST_LENGTH.
|
inline |
Set socket port number
References port.
|
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().
|
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 | ) |
Connect to host
References connected, doDisconnect(), host, MAX_HOST_LENGTH, MAX_SC_INFO_SIZE, port, recvPollStatus, recvThreadRunning, runSockClient(), scError, scInfo, scWarning, sInfo(), sock, stop, stopNow, thClient, transmissionTraffic(), and Wait().
|
private |
Buffer fused by recv(...) call for new partial message
Referenced by getDataFromLine().
|
private |
Connected is true when connected
Referenced by blockSend(), closeConnection(), getDataFromLine(), handleConnection(), isConnected(), tryConnect(), USockClient(), and ~USockClient().
|
private |
Detection of lost connection
Referenced by getDataFromLine(), and USockClient().
|
protected |
Name of host to connect to
Referenced by getHost(), setHost(), tryConnect(), and USockClient().
|
protected |
Poll read timeout value. At poll timeout the pollTimeout() is called. value is in milli seconds
Referenced by isConnected(), and USockClient().
|
protected |
Port used when connecting to host
Referenced by getPort(), setPort(), tryConnect(), and USockClient().
|
private |
Mutex lock
Referenced by blockSend(), and USockClient().
|
protected |
Number of reads (with >0 bytes returned).
Referenced by USockClient().
|
private |
True as long as there is unfetched data
Referenced by blockSend(), getDataFromLine(), handleConnection(), and USockClient().
|
private |
Poll status used when polling for available data
Referenced by getDataFromLine(), and tryConnect().
|
private |
Listening is true when read thread is running - listening to the socket
Referenced by doDisconnect(), handleConnection(), tryConnect(), and USockClient().
|
private |
True during a send
Referenced by blockSend(), getDataFromLine(), handleConnection(), and USockClient().
|
private |
Socket
Referenced by blockSend(), closeConnection(), getDataFromLine(), handleConnection(), tryConnect(), and USockClient().
|
private |
Flag to stop receiving thread.
Referenced by doDisconnect(), handleConnection(), tryConnect(), and USockClient().
|
private |
Another stop flag that can stop an connection attempt - I think.
Referenced by tryConnect().
|
private |
Handle to thread listening to messages
Referenced by doDisconnect(), and tryConnect().