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

#include <uclientport.h>

Inheritance diagram for UClientPort:
Inheritance graph

Public Member Functions

bool blockSend (const char *buffer, int length)
 
void closeConnection ()
 
int getDataFromLine (char *buffer, int bufferSize, int pollTimeoutMs)
 
const char * getHost ()
 
const char * getHostIP ()
 
int getPort ()
 
bool isConnected ()
 
bool isVerbose ()
 
bool sendMsg (const char *message)
 
bool sendWithLock (const char *message)
 
void setHost (const char *toHost)
 
void setPort (int toPort)
 
void setVerbose (bool value)
 
bool tryConnect ()
 
 UClientPort ()
 
virtual ~UClientPort ()
 
- Public Member Functions inherited from ULock
bool lock ()
 
void lockInit ()
 
void post ()
 
bool tryLock ()
 
bool tryWait ()
 
 ULock ()
 
void unlock ()
 
bool wait ()
 
 ~ULock ()
 

Public Attributes

int rxByteCnt
 
ULock tx
 

Protected Types

enum  { notLost, forReopen, rxError, txError }
 

Protected Member Functions

virtual void connectionChange (bool nowConnected)
 
virtual void sendNamespaceOpenTag ()
 

Protected Attributes

enum UClientPort:: { ... }  connectionLostReason
 
UTime connectTime
 
char host [MAX_HOST_LENGTH]
 
char hostIP [MAX_HOST_LENGTH]
 
int port
 
unsigned int readCnt
 
bool verboseMessages
 

Private Attributes

bool connected
 
struct pollfd recvPollStatus
 
int sock
 
char * sockbuffer
 socket read buffer More...
 
int sockbufferCnt
 socket read buffer size More...
 

Detailed Description

Longest tag send to client, i.e. from '<' to '>' (both included), but a longer buffer may be an advantage for skipping large binary blocks. Base class for a socket client

Author
Christian Andersen

Member Enumeration Documentation

anonymous enum
protected

connection closed reason

Enumerator
notLost 
forReopen 
rxError 
txError 

Constructor & Destructor Documentation

UClientPort::UClientPort ( )
UClientPort::~UClientPort ( )
virtual

Destructor

References closeConnection(), connected, and sockbuffer.

Member Function Documentation

bool UClientPort::blockSend ( const char *  buffer,
int  length 
)

Send data to the server Returns false if not send (or partially send). If an error occurs during transmission, the connection will be closed. The line is TX-locked during transmission. (to ensure that messages are not mixed from different sources) The call is blocked until data is send (no timeout).

References closeConnection(), connected, connectionLostReason, sock, and txError.

Referenced by UFuncTOF::callXMLRPC(), clientCmdLine(), isConnected(), UFuncTOF::runSetting(), sendMsg(), UClientFuncBase::sendMsg(), ULaserSim::sendToDevice(), ULms100::sendToDevice(), ULms500::sendToDevice(), sendWithLock(), and testSmlClient().

void UClientPort::closeConnection ( )
void UClientPort::connectionChange ( bool  nowConnected)
protectedvirtual

Called when connection is created or gets lost

Reimplemented in UResIf, UResLaserIf, UClientHandler, and UResCamIf.

References host, and port.

Referenced by closeConnection(), UClientHandler::connectionChange(), isConnected(), and tryConnect().

int UClientPort::getDataFromLine ( char *  buffer,
int  bufferSize,
int  pollTimeoutMs 
)

Get more data for line Gets at most buffer length of data. Returns number of bytes received. Returns 0 if timeout occured. Returns -1 if line got disconnected or other error situations.

References closeConnection(), connectionLostReason, getHost(), getPort(), readCnt, recvPollStatus, rxByteCnt, rxError, sock, verboseMessages, and Wait().

Referenced by closeConnection(), UClientPortSml::getMoreData(), isConnected(), ULms100::receiveData(), ULms500::receiveData(), UFuncTOF::runData(), and UFuncTOF::WaitForReply().

const char* UClientPort::getHost ( )
inline
const char* UClientPort::getHostIP ( )
inline

Get host IP adress (as string)

References hostIP.

Referenced by UFuncTOF::handleTOF(), UClientHandler::print(), and UClientHandler::snprint().

int UClientPort::getPort ( )
inline
bool UClientPort::isConnected ( )
inline
bool UClientPort::isVerbose ( )
inline

is verbose messages true - mostly for debug purpose

References verboseMessages.

bool UClientPort::sendMsg ( const char *  message)
void UClientPort::sendNamespaceOpenTag ( )
protectedvirtual

Virtual function that can be used to send an opening remark to the server

Reimplemented in UClientHandler.

Referenced by isConnected().

bool UClientPort::sendWithLock ( const char *  message)

Send a message to the server keeping the connection tx-locked during transmission

References blockSend(), ULock::lock(), and ULock::unlock().

Referenced by UFunctionIf::handleIf(), isConnected(), UResIf::methodCall(), UResCamIf::methodCall(), UClientPortSml::outputData(), UResIf::quitRemoteEnd(), and UResIf::replayToTime().

void UClientPort::setHost ( const char *  toHost)
inline
void UClientPort::setPort ( int  toPort)
inline
void UClientPort::setVerbose ( bool  value)
inline

Set verbose messages - mostly for debug purpose

References verboseMessages.

bool UClientPort::tryConnect ( )

Member Data Documentation

bool UClientPort::connected
private
enum { ... } UClientPort::connectionLostReason

connection closed reason

Referenced by blockSend(), closeConnection(), getDataFromLine(), tryConnect(), and UClientPort().

UTime UClientPort::connectTime
protected

Time of connection

Referenced by UClientHandler::threadRunLoop(), and tryConnect().

char UClientPort::host[MAX_HOST_LENGTH]
protected
char UClientPort::hostIP[MAX_HOST_LENGTH]
protected

Name of host to connect to

Referenced by getHostIP(), and tryConnect().

int UClientPort::port
protected
unsigned int UClientPort::readCnt
protected
struct pollfd UClientPort::recvPollStatus
private

Poll status used when polling for available data

Referenced by getDataFromLine(), and tryConnect().

int UClientPort::rxByteCnt

Number of bytes received drom port.

Referenced by getDataFromLine(), UResIf::interfaceTick(), UClientHandler::threadRunLoop(), and UClientPort().

int UClientPort::sock
private
char* UClientPort::sockbuffer
private

socket read buffer

debug logfile

Referenced by tryConnect(), UClientPort(), and ~UClientPort().

int UClientPort::sockbufferCnt
private

socket read buffer size

Referenced by tryConnect(), and UClientPort().

ULock UClientPort::tx

Mutex lock for transmission - should be used by clients where conflicts might occur to frame set of transmissions.

  • not used by this class!
bool UClientPort::verboseMessages
protected

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