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

#include <userverport.h>

Inheritance diagram for UServerPort:
Inheritance graph

Public Member Functions

void connectionLost (int client)
 
int getActiveClientCnt ()
 
bool getAllowConnections ()
 
UServerClientgetClient (const int i)
 
int getClientCnt ()
 
char * getHostName (char *nameBuffer, const int nameBufferCnt)
 
int getLastClient ()
 
int getLastClientSerial ()
 
int getPort ()
 
UServerInQueuegetRxQueue ()
 
const char * getServerNamespace ()
 
const char * getServerNamespaceAttribute ()
 
virtual void gotNewClient (UServerClient *cnn)
 
bool isOpen4Connections ()
 
bool isServerNamespaceUse ()
 
virtual void messageReceived ()
 
void print (const char *preStr)
 
bool runServerThread ()
 
double serverAliveLast ()
 
void serverIsAlive ()
 
void setAllowConnections (bool value)
 
void setPort (const int toPort)
 
bool setResource (UResBase *resource, bool remove)
 
void setServerNamespace (const char *name)
 
void setServerNamespaceAttribute (const char *attStr)
 
void setServerNamespaceUse (bool value)
 
void setVerbose (bool value)
 
bool start ()
 
bool stop (bool andWait)
 
 UServerPort ()
 
virtual ~UServerPort ()
 

Public Attributes

UVariablevarAlivePunkTime
 

Protected Member Functions

int getFreeClientHandle ()
 
bool serviceClients (int msTimeout)
 
void updateVars ()
 

Protected Attributes

bool allowConnections
 
bool open4Connections
 
UResLink resLink
 

Private Attributes

UServerClientclient [MAX_SOCKET_CLIENTS_SERVED]
 
int clientCnt
 
int clientCntActive
 
UCmdExeeventServer
 
int lastClientNumber
 
int lastClientSerial
 
int recvLoops
 
bool running
 
UServerInQueue rxQueue
 
UTime serverAlive
 
char serverNamespace [MAX_SML_NAME_LENGTH]
 
char serverNamespaceAttribute [MAX_NAMESPACE_ATTRIBUTE_LENGTH]
 
bool serverNamespaceUse
 
bool terminate
 
pthread_t thServ
 
UResVarPoolvarPool
 
bool verboseMessages
 

Detailed Description

Class used by a socket server to control and accept connections to one port number. The port number are determined during initialization.

Author
Christian Andersen

Constructor & Destructor Documentation

UServerPort::UServerPort ( )
UServerPort::~UServerPort ( )
virtual

Destructor

References client, and clientCnt.

Member Function Documentation

void UServerPort::connectionLost ( int  client)

Should be called whenever a client is disconnected - to allow cleanup of obligations for this client

Referenced by getLastClient().

int UServerPort::getActiveClientCnt ( )

Get number of active clients

References client, and clientCnt.

Referenced by UCmdExe::handleServerCommand(), print(), runServerThread(), setVerbose(), and UCmdExe::updateLocalVar().

bool UServerPort::getAllowConnections ( )
inline

Get the allow connections flag if false, then server do not allow (new) connections

Parameters
valueset to true, if to allow connections

References allowConnections.

UServerClient * UServerPort::getClient ( const int  i)
int UServerPort::getClientCnt ( )
inline

Return number of initialized clients. The clients may be active or inactive (closed)

References clientCnt, getClient(), gotNewClient(), and messageReceived().

Referenced by UCmdExe::handleServerCommand(), and UCmdExe::sendMsgAll().

int UServerPort::getFreeClientHandle ( )
protected
char * UServerPort::getHostName ( char *  nameBuffer,
const int  nameBufferCnt 
)

Get hostname - just a wrap of the normal 'gethostname' call. Returns a pointer to the provided string.

Referenced by setPort(), and UCmdExe::sysServerHelp().

int UServerPort::getLastClient ( )
inline

Get client number of latest clinet connected - mostly for debug

References client, connectionLost(), and lastClientNumber.

Referenced by UCmdExe::updateLocalVar().

int UServerPort::getLastClientSerial ( )
inline

Get last used client serial number

References getFreeClientHandle(), lastClientSerial, serviceClients(), and updateVars().

Referenced by UCmdExe::updateLocalVar().

int UServerPort::getPort ( )
inline
UServerInQueue* UServerPort::getRxQueue ( )
inline
const char* UServerPort::getServerNamespace ( )
inline

Get a pointer to the namespace element name.

References serverNamespace.

Referenced by UCmdExe::closeClient(), gotNewClient(), and UCmdExe::handleServerCommand().

const char* UServerPort::getServerNamespaceAttribute ( )
inline

Get a pointer to the namespace attribite string.

References serverNamespaceAttribute.

Referenced by gotNewClient().

void UServerPort::gotNewClient ( UServerClient cnn)
virtual

This function is called, when a new client is connected

Reimplemented in URawServerPort.

References UServerClient::blockSend(), UServerClient::getClientName(), getServerNamespace(), getServerNamespaceAttribute(), and serverNamespaceUse.

Referenced by getClientCnt(), and runServerThread().

bool UServerPort::isOpen4Connections ( )
inline

Is server open for connections - i.e. port number is valid

References open4Connections.

Referenced by UCmdExe::handleServerCommand(), and UCmdExe::updateLocalVar().

bool UServerPort::isServerNamespaceUse ( )
inline

Is the use flag for opening namespace message to new clients set.

References serverNamespaceUse.

void UServerPort::messageReceived ( )
virtual

Function to trigger events, when new data is available. Should be overwritten by decendent classes.

References UServerPushImplement::event(), eventServer, UMsgQueue::getElements(), UMsgQueue::getUsedMsgCnt(), rxQueue, serverPort, and verboseMessages.

Referenced by getClientCnt(), and serviceClients().

void UServerPort::print ( const char *  preStr)
bool UServerPort::runServerThread ( )

The thread that handles all port tasks. Runs until stop-flag is set, or if port can not be bound. Should not be called!, call start() to create the thread calling this function.

References allowConnections, client, getActiveClientCnt(), getFreeClientHandle(), gotNewClient(), UServerClient::initConnection(), open4Connections, running, rxQueue, serverAlive, serverPort, serviceClients(), terminate, updateVars(), verboseMessages, and Wait().

Referenced by runServerPort(), and setVerbose().

double UServerPort::serverAliveLast ( )

Get time passed since the server was last reported alive.

Returns
time in seconds since that server thread last set the alive timestamp.

References UTime::getTimePassed(), and serverAlive.

Referenced by UCmdExe::handleAlive(), and serverIsAlive().

void UServerPort::serverIsAlive ( )
inline

Alive call from server thread

References UTime::now(), serverAlive, and serverAliveLast().

Referenced by UCmdExe::run().

bool UServerPort::serviceClients ( int  msTimeout)
protected
void UServerPort::setAllowConnections ( bool  value)
inline

Set the allow connections flag Existing connections are not closed

Parameters
valueset to true, if to allow new connections

References allowConnections.

Referenced by UCmdExe::run(), runCameraServerComponent(), and runLaserServerComponent().

void UServerPort::setPort ( const int  toPort)
inline
bool UServerPort::setResource ( UResBase resource,
bool  remove 
)
void UServerPort::setServerNamespace ( const char *  name)
inline

Set name of namespace, that will be used as the opening element on start of communication with a new client.

References MAX_SML_NAME_LENGTH, and serverNamespace.

Referenced by runCameraServerComponent(), runLaserServerComponent(), runServer(), testServerGen(), and testServerPort().

void UServerPort::setServerNamespaceAttribute ( const char *  attStr)
inline

Set attribute part of communication namestae element.

References MAX_NAMESPACE_ATTRIBUTE_LENGTH, serverNamespaceAttribute, and setResource().

Referenced by runCameraServerComponent(), runLaserServerComponent(), runServer(), and testServerPort().

void UServerPort::setServerNamespaceUse ( bool  value)
inline

Set use flag for opening namespace message to new clients.

References serverNamespaceUse.

void UServerPort::setVerbose ( bool  value)
inline
bool UServerPort::start ( )

Start server port reveive loop. This loop will not start if port number is less than 1000. One loop handles all clients and adds messages to the command queue. An error is printed on console if port is not opened.

References running, runServerPort(), terminate, and thServ.

Referenced by getRxQueue(), runCameraServerComponent(), runLaserServerComponent(), runServer(), testServerGen(), and testServerPort().

bool UServerPort::stop ( bool  andWait)

Stops the socket server and terminates all connection and terminates the thread. If andWait, then stop will wait until thread is terminated before return, otherwise function returns immidiately

References client, clientCnt, running, serverNamespace, terminate, and thServ.

Referenced by getRxQueue(), UCmdExe::stop(), and testServerPort().

void UServerPort::updateVars ( )
protected

Member Data Documentation

bool UServerPort::allowConnections
protected

Should server allow connections, if not, then close server port - until changed.

Referenced by getAllowConnections(), runServerThread(), and setAllowConnections().

UServerClient* UServerPort::client[MAX_SOCKET_CLIENTS_SERVED]
private
int UServerPort::clientCnt
private
int UServerPort::clientCntActive
private

Number of active clients

Referenced by serviceClients(), updateVars(), and UServerPort().

UCmdExe* UServerPort::eventServer
private

Server that should be notified of events

Referenced by messageReceived(), setResource(), and UServerPort().

int UServerPort::lastClientNumber
private

client number to be used used for the last connection (-1 = no clients yet)

Referenced by getFreeClientHandle(), getLastClient(), and UServerPort().

int UServerPort::lastClientSerial
private

last client serial number used

Referenced by getFreeClientHandle(), and getLastClientSerial().

bool UServerPort::open4Connections
protected

Is the selected port valid, i.e. open for connections

Referenced by isOpen4Connections(), runServerThread(), updateVars(), and UServerPort().

int UServerPort::recvLoops
private

Statistics - receive loops

Referenced by print(), serviceClients(), and UServerPort().

UResLink UServerPort::resLink
protected

Pointer to ressources that nee immidiate data

Referenced by getFreeClientHandle(), and setResource().

bool UServerPort::running
private

Running is true when accepting-calls thread is running

Referenced by print(), runServerThread(), start(), stop(), and UServerPort().

UServerInQueue UServerPort::rxQueue
private

Queue for received messages from all clients

Referenced by getRxQueue(), messageReceived(), print(), and runServerThread().

UTime UServerPort::serverAlive
private

The last time the server thread was reported alive

Referenced by runServerThread(), serverAliveLast(), serverIsAlive(), and UServerPort().

char UServerPort::serverNamespace[MAX_SML_NAME_LENGTH]
private

Namespace to tell clients

Referenced by getServerNamespace(), serviceClients(), setServerNamespace(), stop(), and UServerPort().

char UServerPort::serverNamespaceAttribute[MAX_NAMESPACE_ATTRIBUTE_LENGTH]
private

Server namespace attributes. This string must be coded to follow XML standard, and is send after the namespace and before the close '>' character

Referenced by getServerNamespaceAttribute(), setServerNamespaceAttribute(), and UServerPort().

bool UServerPort::serverNamespaceUse
private

Sent namespace as opening message to the new client

Referenced by gotNewClient(), isServerNamespaceUse(), setServerNamespaceUse(), and UServerPort().

bool UServerPort::terminate
private

Flag to stop active connections and stop accepting connections.

Referenced by runServerThread(), start(), stop(), and UServerPort().

pthread_t UServerPort::thServ
private

Handle to accept thread

Referenced by start(), and stop().

UVariable* UServerPort::varAlivePunkTime

Should clients be punk'ed with alive messages to see if they are alive

Referenced by serviceClients(), UCmdExe::setServer(), and UServerPort().

UResVarPool* UServerPort::varPool
private

Pointer to core var pool

Referenced by updateVars(), and UServerPort().

bool UServerPort::verboseMessages
private

Print more to info connection / console

Referenced by messageReceived(), print(), runServerThread(), serviceClients(), setVerbose(), and UServerPort().


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