MOOS 0.2375
|
#include <MOOSCommServer.h>
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, bool bDisableNameLookUp=false) |
void | SetQuiet (bool bQ) |
CMOOSCommServer () | |
default constructor | |
virtual | ~CMOOSCommServer () |
default destructor | |
Protected Member Functions | |
int | GetMaxSocketFD () |
virtual void | DoBanner () |
std::string | GetClientName (XPCTcpSocket *pSocket) |
void | PoisonClient (XPCTcpSocket *pSocket, const std::string &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 the listen and server threads up | |
Protected Attributes | |
CMOOSLock | m_SocketListLock |
int | m_nTotalActions |
internal count of the number of calls processed | |
CMOOSThread | m_ListenThread |
CMOOSThread | m_ServerThread |
CMOOSThread | m_TimerThread |
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 | |
bool | m_bDisableNameLookUp |
flag to say don't bother with name look up | |
std::string | m_sCommunityName |
name of community being served | |
bool | m_bQuiet |
how quiet are we |
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
Definition at line 68 of file MOOSCommServer.h.
typedef std::map<int,std::string > CMOOSCommServer::SOCKETFD_2_CLIENT_NAME_MAP |
Definition at line 72 of file MOOSCommServer.h.
typedef std::list<XPCTcpSocket*> CMOOSCommServer::SOCKETLIST |
Definition at line 71 of file MOOSCommServer.h.
typedef std::list<std::string > CMOOSCommServer::STRING_LIST |
Definition at line 73 of file MOOSCommServer.h.
CMOOSCommServer::CMOOSCommServer | ( | ) |
default constructor
Definition at line 107 of file MOOSCommServer.cpp.
CMOOSCommServer::~CMOOSCommServer | ( | ) | [virtual] |
default destructor
Definition at line 117 of file MOOSCommServer.cpp.
void CMOOSCommServer::DoBanner | ( | ) | [protected, virtual] |
prints class information banner to stdout
Definition at line 737 of file MOOSCommServer.cpp.
string CMOOSCommServer::GetClientName | ( | XPCTcpSocket * | pSocket | ) | [protected] |
Get the name of the client on the remote end of pSocket
Definition at line 719 of file MOOSCommServer.cpp.
bool CMOOSCommServer::GetClientNames | ( | STRING_LIST & | sList | ) |
Definition at line 770 of file MOOSCommServer.cpp.
int CMOOSCommServer::GetMaxSocketFD | ( | ) | [protected] |
figures out what the largest socket FD of all connected sockets. (needed by select)
Definition at line 753 of file MOOSCommServer.cpp.
bool CMOOSCommServer::HandShake | ( | XPCTcpSocket * | pNewSocket | ) | [protected] |
Perform handshaling with client just after a connection has been accepted
Definition at line 659 of file MOOSCommServer.cpp.
bool CMOOSCommServer::IsUniqueName | ( | std::string & | sClientName | ) | [protected] |
returns true if a server has no connection to the named client
sClientName | reference to client name std::string |
Definition at line 622 of file MOOSCommServer.cpp.
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.
Definition at line 236 of file MOOSCommServer.cpp.
bool CMOOSCommServer::OnAbsentClient | ( | XPCTcpSocket * | pClient | ) | [protected, virtual] |
called when a client goes quiet...
Definition at line 194 of file MOOSCommServer.cpp.
bool CMOOSCommServer::OnClientDisconnect | ( | ) | [protected, virtual] |
called when a client disconnects or and error occurs
Definition at line 555 of file MOOSCommServer.cpp.
bool CMOOSCommServer::OnNewClient | ( | XPCTcpSocket * | pNewClient, |
char * | sName | ||
) | [protected, virtual] |
Called when a new client connects. Performs handshaking and adds new socket to m_ClientSocketList
pNewClient | pointer to the new socket created in ListenLoop; |
Definition at line 516 of file MOOSCommServer.cpp.
void CMOOSCommServer::PoisonClient | ( | XPCTcpSocket * | pSocket, |
const std::string & | sReason | ||
) | [protected] |
Send a Poisoned mesasge to the client on the end of pSocket. This may cause the client comms thrad to die
Definition at line 712 of file MOOSCommServer.cpp.
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
Definition at line 447 of file MOOSCommServer.cpp.
bool CMOOSCommServer::Run | ( | long | lPort, |
const std::string & | sCommunityName, | ||
bool | bDisableNameLookUp = false |
||
) |
Initialise the server. This is a non blocking call and launches the MOOS Comms server threads.
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
Definition at line 329 of file MOOSCommServer.cpp.
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).
sClient | Name of client at the end of the socket sending this Pkt |
pParam | user suplied parameter to be passed to callback function |
Definition at line 206 of file MOOSCommClient.cpp.
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 the server. The supplied call back must be of the form static bool MyCallBack(MOOSMSG_LIST & RxLst,MOOSMSG_LIST & TxLst, void * pParam).
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 the incoming messages. |
pParam | user suplied parameter to be passed to callback function |
Definition at line 601 of file MOOSCommServer.cpp.
void CMOOSCommServer::SetQuiet | ( | bool | bQ | ) | [inline] |
used to control how verbose the server is. Setting to true turns off all Tracing
Definition at line 115 of file MOOSCommServer.h.
bool CMOOSCommServer::StartThreads | ( | ) | [protected] |
called from init to start the listen and server threads up
Definition at line 85 of file MOOSCommServer.cpp.
bool CMOOSCommServer::TimerLoop | ( | ) |
This function is the timer loop called from one of the three server threads. It makes sure all clients speak occasionally
Definition at line 143 of file MOOSCommServer.cpp.
bool CMOOSCommServer::m_bDisableNameLookUp [protected] |
flag to say don't bother with name look up
Definition at line 220 of file MOOSCommServer.h.
bool CMOOSCommServer::m_bQuiet [protected] |
how quiet are we
Definition at line 228 of file MOOSCommServer.h.
bool CMOOSCommServer::m_bQuit [protected] |
threads continue while this flag is false
Definition at line 211 of file MOOSCommServer.h.
SOCKETLIST CMOOSCommServer::m_ClientSocketList [protected] |
list of all currently connected sockets
Definition at line 192 of file MOOSCommServer.h.
CMOOSThread CMOOSCommServer::m_ListenThread [protected] |
a thread to listen for new connections
Definition at line 160 of file MOOSCommServer.h.
long CMOOSCommServer::m_lListenPort [protected] |
port listen socket is bound to
Definition at line 208 of file MOOSCommServer.h.
int CMOOSCommServer::m_nMaxSocketFD [protected] |
largest FD of all connected sockets
Definition at line 214 of file MOOSCommServer.h.
int CMOOSCommServer::m_nTotalActions [protected] |
internal count of the number of calls processed
Definition at line 151 of file MOOSCommServer.h.
void* CMOOSCommServer::m_pDisconnectCallBackParam [protected] |
place holder for the address of the object passed back to the user during a Disconnect callback
Definition at line 183 of file MOOSCommServer.h.
bool(* CMOOSCommServer::m_pfnDisconnectCallBack)(std::string &sClient, void *pParam) [protected] |
user supplied OnDisconnect callback
Definition at line 179 of file MOOSCommServer.h.
bool(* CMOOSCommServer::m_pfnRxCallBack)(const std::string &sClient, MOOSMSG_LIST &MsgListRx, MOOSMSG_LIST &MsgListTx, void *pCaller) [protected] |
user supplied OnRx callback
Definition at line 170 of file MOOSCommServer.h.
XPCTcpSocket* CMOOSCommServer::m_pFocusSocket [protected] |
pointer to the socket which server is currently processing call from
Definition at line 189 of file MOOSCommServer.h.
XPCTcpSocket* CMOOSCommServer::m_pListenSocket [protected] |
Listen socket (bound to port address supplied in constructor)
Definition at line 186 of file MOOSCommServer.h.
void* CMOOSCommServer::m_pRxCallBackParam [protected] |
place holder for the address of the object passed back to the user during an Rx callback
Definition at line 174 of file MOOSCommServer.h.
std::string CMOOSCommServer::m_sCommunityName [protected] |
name of community being served
Definition at line 223 of file MOOSCommServer.h.
CMOOSThread CMOOSCommServer::m_ServerThread [protected] |
a thread to handle existing connections
Definition at line 163 of file MOOSCommServer.h.
map of socket file descriptors to the std::string name of the client process at the other end
Definition at line 196 of file MOOSCommServer.h.
CMOOSLock CMOOSCommServer::m_SocketListLock [protected] |
a simple mutex to guard access to m_ClientSocketList
Definition at line 127 of file MOOSCommServer.h.
CMOOSThread CMOOSCommServer::m_TimerThread [protected] |
a thread to notice if clients appear to have fallen silent
Definition at line 166 of file MOOSCommServer.h.