AURobotServers
4
|
#include <uclientport.h>
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... | |
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
UClientPort::UClientPort | ( | ) |
Constructor
References connected, connectionLostReason, host, MAX_HOST_LENGTH, notLost, port, readCnt, rxByteCnt, sock, sockbuffer, sockbufferCnt, and verboseMessages.
|
virtual |
Destructor
References closeConnection(), connected, and sockbuffer.
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 | ( | ) |
Do an hang-up if socket is valid and call the connectionChange function.
References connected, connectionChange(), connectionLostReason, getDataFromLine(), host, port, rxError, and sock.
Referenced by blockSend(), UClientHandler::closeConnection(), ULms100::closePort(), ULms500::closePort(), getDataFromLine(), UFuncTOF::handleTOF(), isConnected(), UFuncTOF::runData(), UFuncTOF::runSetting(), tryConnect(), and ~UClientPort().
|
protectedvirtual |
Called when connection is created or gets lost
Reimplemented in UResIf, UResLaserIf, UClientHandler, and UResCamIf.
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().
|
inline |
Get host name
References host.
Referenced by clientCmdLine(), getDataFromLine(), UClientPortSml::getSourceName(), UFunctionIf::handleIf(), UFuncTOF::handleTOF(), UResIf::interfaceTick(), UClientHandler::print(), UClientHandler::snprint(), and testSmlClient().
|
inline |
Get host IP adress (as string)
References hostIP.
Referenced by UFuncTOF::handleTOF(), UClientHandler::print(), and UClientHandler::snprint().
|
inline |
Get port number
References port.
Referenced by clientCmdLine(), getDataFromLine(), UFunctionIf::handleIf(), UFuncTOF::handleTOF(), UResIf::interfaceTick(), UClientHandler::print(), UClientHandler::snprint(), and testSmlClient().
|
inline |
Is client connected
References blockSend(), closeConnection(), connected, connectionChange(), getDataFromLine(), sendMsg(), sendNamespaceOpenTag(), sendWithLock(), and tryConnect().
Referenced by clientCmdLine(), ULaserSim::closePort(), ULaserSim::getNewestData(), UClientHandler::gotNewData(), UFunctionIf::handleIf(), UFuncTOF::handleTOF(), UResIf::interfaceTick(), ULaserSim::isPortOpen(), ULms100::isPortOpen(), ULms500::isPortOpen(), UClientPortSml::isSourceAvailable(), UClientHandler::openConnection(), ULaserSim::openPort(), UClientHandler::print(), UResIf::quitRemoteEnd(), ULaserSim::receiveData(), UResIf::replayToTime(), UFuncTOF::runData(), UFuncTOF::runSetting(), UClientHandler::snprint(), testSmlClient(), UClientHandler::threadRunLoop(), ULms100::~ULms100(), and ULms500::~ULms500().
|
inline |
is verbose messages true - mostly for debug purpose
References verboseMessages.
bool UClientPort::sendMsg | ( | const char * | message | ) |
Send a message to the server assuming that the connection is already tx-locked
References blockSend().
Referenced by ULaserSim::getNewestData(), UResIf::interfaceTick(), isConnected(), UResLaserIf::methodCall(), UClientHandler::sendNamespaceCloseTag(), UClientHandler::sendNamespaceOpenTag(), and UClientHandler::sendPing().
|
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().
|
inline |
Set host name
References host, and MAX_HOST_LENGTH.
Referenced by UFuncTOF::handleTOF(), ULms100::openPort(), ULms500::openPort(), and UClientHandler::setHost().
|
inline |
Set port number
References port.
Referenced by UFuncTOF::handleTOF(), ULms100::openPort(), ULms500::openPort(), and UClientHandler::setPort().
|
inline |
Set verbose messages - mostly for debug purpose
References verboseMessages.
bool UClientPort::tryConnect | ( | ) |
Try connect to this host-port combination. Returns true if connected. Host IP address will be in host string on successfull connect.
References closeConnection(), connected, connectionChange(), connectionLostReason, connectTime, forReopen, host, hostIP, MAX_HOST_LENGTH, UTime::now(), port, readCnt, recvPollStatus, sock, sockbuffer, sockbufferCnt, ULock::tryLock(), ULock::unlock(), verboseMessages, and Wait().
Referenced by UFuncTOF::handleTOF(), isConnected(), ULms100::openPort(), ULms500::openPort(), and UClientHandler::threadRunLoop().
|
private |
Connected is true when connected
Referenced by blockSend(), closeConnection(), UResIf::connectionHangUp(), isConnected(), UResCamIf::snprint(), UResLaserIf::snprint(), tryConnect(), UClientPort(), and ~UClientPort().
enum { ... } UClientPort::connectionLostReason |
connection closed reason
Referenced by blockSend(), closeConnection(), getDataFromLine(), tryConnect(), and UClientPort().
|
protected |
Time of connection
Referenced by UClientHandler::threadRunLoop(), and tryConnect().
|
protected |
Name of host to connect to
Referenced by closeConnection(), UClientHandler::connectionChange(), connectionChange(), getHost(), UClientHandler::getServerNamespaceName(), setHost(), UClientHandler::setHost(), tryConnect(), UClientPort(), UResIf::UResIf(), and UResLaserIf::UResLaserIf().
|
protected |
Name of host to connect to
Referenced by getHostIP(), and tryConnect().
|
protected |
Port used when connecting to host
Referenced by closeConnection(), UClientHandler::connectionChange(), connectionChange(), getPort(), UClientHandler::getServerNamespaceName(), setPort(), UResIf::setPort(), UClientHandler::setPort(), tryConnect(), UClientPort(), UResIf::UResIf(), and UResLaserIf::UResLaserIf().
|
protected |
Number of reads (polls).
Referenced by getDataFromLine(), UClientHandler::print(), UClientHandler::snprint(), UClientHandler::threadRunLoop(), tryConnect(), and UClientPort().
|
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().
|
private |
Socket
Referenced by blockSend(), closeConnection(), getDataFromLine(), tryConnect(), and UClientPort().
|
private |
|
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.
|
protected |
Print pore information when relevant
Referenced by UClientPortSml::doVerboseMessages(), getDataFromLine(), UClientHandler::handlePingReply(), isVerbose(), UClientHandler::setVerbose(), setVerbose(), UClientHandler::threadRunLoop(), tryConnect(), UClientPort(), and UResCamIf::UResCamIf().