MOOS

CMOOSCommServer Class Reference

#include <MOOSCommServer.h>

Inheritance diagram for CMOOSCommServer:

CMOOSCommObject List of all members.

Public Types

typedef std::list< XPCTcpSocket * > SOCKETLIST
typedef std::map< int, std::string > SOCKETFD_2_CLIENT_NAME_MAP
typedef std::list< std::string > STRING_LIST

Public Member Functions

bool GetClientNames (STRING_LIST &sList)
void SetOnRxCallBack (bool(*pfn)(const std::string &sClient, MOOSMSG_LIST &MsgListRx, MOOSMSG_LIST &MsgListTx, void *pParam), void *pParam)
void SetOnDisconnectCallBack (bool(*pfn)(std::string &sClient, void *pParam), void *pParam)
bool ListenLoop ()
bool ServerLoop ()
bool TimerLoop ()
bool Run (long lPort, const std::string &sCommunityName)
 CMOOSCommServer ()
 default constructor
virtual ~CMOOSCommServer ()
 default destructor

Protected Types

typedef pthread_t THREAD_ID

Protected Member Functions

int GetMaxSocketFD ()
virtual void DoBanner ()
std::string GetClientName (XPCTcpSocket *pSocket)
void PoisonClient (XPCTcpSocket *pSocket, char *sReason)
bool HandShake (XPCTcpSocket *pNewSocket)
bool IsUniqueName (std::string &sClientName)
virtual bool OnClientDisconnect ()
 called when a client disconnects or and error occurs
virtual bool OnAbsentClient (XPCTcpSocket *pClient)
 called when a client goes quiet...
virtual bool OnNewClient (XPCTcpSocket *pNewClient, char *sName)
virtual bool ProcessClient ()
bool StartThreads ()
 called from init to start teh listen and server threads up

Protected Attributes

CMOOSLock m_SocketListLock
int m_nTotalActions
 internal count of the number of calls processed
THREAD_ID m_nListenThreadID
 ID of Listen Thread.
THREAD_ID m_nServerThreadID
 ID of Server Thread.
THREAD_ID m_nTimerThreadID
 ID of timer Thread.
bool(* m_pfnRxCallBack )(const std::string &sClient, MOOSMSG_LIST &MsgListRx, MOOSMSG_LIST &MsgListTx, void *pCaller)
void * m_pRxCallBackParam
bool(* m_pfnDisconnectCallBack )(std::string &sClient, void *pParam)
void * m_pDisconnectCallBackParam
XPCTcpSocket * m_pListenSocket
XPCTcpSocket * m_pFocusSocket
SOCKETLIST m_ClientSocketList
SOCKETFD_2_CLIENT_NAME_MAP m_Socket2ClientMap
long m_lListenPort
 port listen socket is bound to
bool m_bQuit
 threads continue while this flag is false
int m_nMaxSocketFD
 largest FD of all connected sockets
std::string m_sCommunityName
 name of community being served

Detailed Description

This class is the MOOS Comms Server. It lies at the heart of the communications architecture and typically is of no interest to the component developer. It maintains a list of all the connected clients and their names. It simultaneously listens on all sockets for calling clients and then calls a user supplied call back to handle the request. This class is only used by the CMOOSDB application


Member Typedef Documentation

typedef pthread_t CMOOSCommServer::THREAD_ID [protected]
 

Win32 handle to Server thread

See also:
ServerLoop


Member Function Documentation

void CMOOSCommServer::DoBanner  )  [protected, virtual]
 

prints class information banner to stdout

string CMOOSCommServer::GetClientName XPCTcpSocket *  pSocket  )  [protected]
 

Get the name of the client on the remote end of pSocket

int CMOOSCommServer::GetMaxSocketFD  )  [protected]
 

figures out what the largest socket FD of all connected sockets. (needed by select)

bool CMOOSCommServer::HandShake XPCTcpSocket *  pNewSocket  )  [protected]
 

Perform handshaling with client just after a connection has been accepted

bool CMOOSCommServer::IsUniqueName std::string &  sClientName  )  [protected]
 

returns true if a server has no connection to the named client

Parameters:
sClientName reference to client name std::string

bool CMOOSCommServer::ListenLoop  ) 
 

This function is the listen loop called from one of the two server threads. It is responsible for accepting a coonection and creating a new client socket.

bool CMOOSCommServer::OnNewClient XPCTcpSocket *  pNewClient,
char *  sName
[protected, virtual]
 

Called when a new client connects. Performs handshaking and adds new socket to m_ClientSocketList

Parameters:
pNewClient pointer to teh new socket created in ListenLoop;
See also:
ListenLoop

void CMOOSCommServer::PoisonClient XPCTcpSocket *  pSocket,
char *  sReason
[protected]
 

Send a Poisoned mesasge to the client on the end of pSocket. This may cause teh client comms thrad to die

bool CMOOSCommServer::ProcessClient  )  [protected, virtual]
 

called from Server loop this function handles all the processing for the current client call. It inturn invokes the user supplied callback function

bool CMOOSCommServer::Run long  lPort,
const std::string &  sCommunityName
 

Initialise the server. This is a non blocking call and launches the MOOS Comms server threads.

Parameters:
lPort port number to listen on

bool CMOOSCommServer::ServerLoop  ) 
 

This function is the server loop called from one of the two server threads. It listens to all presently connected sockets and when a call is received invokes thse user supplied callback

void CMOOSCommServer::SetOnDisconnectCallBack bool(*)(std::string &sClient, void *pParam)  pfn,
void *  pParam
 

Set the disconnect message call back handler. The supplied call back must be of the form static bool MyCallBack(std::string & sClient,, void * pParam).

Parameters:
sClient contains the incoming messages.
TxLst passed to the handler as a recepticle for all the message that should be sent back to the client in response to teh incoming messages.
pParam user suplied parameter to be passed to callback function

void CMOOSCommServer::SetOnRxCallBack bool(*)(const std::string &sClient, MOOSMSG_LIST &MsgListRx, MOOSMSG_LIST &MsgListTx, void *pParam)  pfn,
void *  pParam
 

Set the recieve message call back handler. The callback will be called whenever a client sends one or more messages to teh server. The supplied call back must be of the form static bool MyCallBack(MOOSMSG_LIST & RxLst,MOOSMSG_LIST & TxLst, void * pParam).

Parameters:
sClient Name of client at the end of the socket sending this Pkt
RxLst contains the incoming messages.
TxLst passed to the handler as a recepticle for all the message that should be sent back to the client in response to teh incoming messages.
pParam user suplied parameter to be passed to callback function

bool CMOOSCommServer::TimerLoop  ) 
 

This function is the timer loop called from one of the three server threads. It makes sure all clients speak occasionally


Member Data Documentation

SOCKETLIST CMOOSCommServer::m_ClientSocketList [protected]
 

list of all currently connected sockets

void* CMOOSCommServer::m_pDisconnectCallBackParam [protected]
 

place holder for teh address of the object passed back to the user during a Disconnect callback

See also:
SetOnDisconnectCallBack

bool(* CMOOSCommServer::m_pfnDisconnectCallBack)(std::string &sClient, void *pParam) [protected]
 

user supplied OnDisconnect callback

See also:
SetOnDisconnectCallBack

bool(* CMOOSCommServer::m_pfnRxCallBack)(const std::string &sClient, MOOSMSG_LIST &MsgListRx, MOOSMSG_LIST &MsgListTx, void *pCaller) [protected]
 

user supplied OnRx callback

See also:
SetOnRxCallBack

XPCTcpSocket* CMOOSCommServer::m_pFocusSocket [protected]
 

pointer to the socket which server is currently processing call from

XPCTcpSocket* CMOOSCommServer::m_pListenSocket [protected]
 

Listen socket (bound to port address supplied in constructor)

void* CMOOSCommServer::m_pRxCallBackParam [protected]
 

place holder for teh address of the object passed back to the user during an Rx callback

See also:
SetOnRxCallBack

SOCKETFD_2_CLIENT_NAME_MAP CMOOSCommServer::m_Socket2ClientMap [protected]
 

map of socket file descriptors to the std::string name of the client process at teh other end

CMOOSLock CMOOSCommServer::m_SocketListLock [protected]
 

a simple mutex to guard access to m_ClientSocketList

See also:
m_ClientSocketList


The documentation for this class was generated from the following files:
Generated on Fri Sep 28 20:14:20 2007 for MOOSLIB by  doxygen 1.4.6