MOOS

CMOOSCommClient Class Reference

#include <MOOSCommClient.h>

Inheritance diagram for CMOOSCommClient:

CMOOSCommObject List of all members.

Public Member Functions

 CMOOSCommClient ()
 default constructor
virtual ~CMOOSCommClient ()
 default destructor
bool Notify (const std::string &sVar, const std::string &sVal, double dfTime=-1)
bool Notify (const std::string &sVar, double dfVal, double dfTime=-1)
bool Register (const std::string &sVar, double dfInterval)
bool UnRegister (const std::string &sVar)
bool IsConnected ()
bool Fetch (MOOSMSG_LIST &MsgList)
bool Post (CMOOSMsg &Msg)
bool ClientLoop ()
virtual bool DoClientWork ()
bool Run (const char *sServer, long lPort, const char *sMyName, unsigned int nFundamentalFreq=5)
void SetOnConnectCallBack (bool(*pfn)(void *pParamCaller), void *pCallerParam)
void SetOnDisconnectCallBack (bool(*pfn)(void *pParamCaller), void *pCallerParam)
bool ServerRequest (const std::string &sWhat, MOOSMSG_LIST &MsgList, double dfTimeOut=2.0, bool bContinuouslyClearBox=true)
bool Peek (MOOSMSG_LIST &List, int nIDRequired, bool bClearBox=true)
std::string GetDescription ()
bool FakeSource (bool bFake)
bool Close (bool bNice=true)
std::set< std::string > GetPublished ()
std::set< std::string > GetRegistered ()

Static Public Member Functions

static bool PeekMail (MOOSMSG_LIST &Mail, const std::string &sKey, CMOOSMsg &Msg, bool bErase=false, bool bFindYoungest=false)
static std::string GetLocalIPAddress ()

Protected Types

typedef pthread_t THREAD_ID

Protected Member Functions

bool ClearResources ()
void DoBanner ()
bool OnCloseConnection ()
bool HandShake ()
bool ConnectToServer ()
bool StartThreads ()
bool UpdateMOOSSkew (double dfTxTime, double dfRxTime)

Protected Attributes

int m_nNextMsgID
bool m_bConnected
bool m_bFakeSource
unsigned int m_nOutPendingLimit
unsigned int m_nInPendingLimit
std::string m_sMyName
CMOOSLock m_OutLock
CMOOSLock m_InLock
XPCTcpSocket * m_pSocket
std::string m_sDBHost
long m_lPort
bool m_bQuit
bool m_bMailPresent
THREAD_ID m_nClientThreadID
MOOSMSG_LIST m_OutBox
MOOSMSG_LIST m_InBox
void * m_pConnectCallBackParam
bool(* m_pfnConnectCallBack )(void *pConnectParam)
void * m_pDisconnectCallBackParam
bool(* m_pfnDisconnectCallBack )(void *pParam)
unsigned int m_nFundamentalFreq
std::set< std::string > m_Registered
std::set< std::string > m_Published

Detailed Description

This class is the most important component of MOOS as seen from the eyes of a component developer


Member Typedef Documentation

typedef pthread_t CMOOSCommClient::THREAD_ID [protected]
 

ID of IO thread


Member Function Documentation

bool CMOOSCommClient::ClientLoop  ) 
 

internal method which runs in a seperate thread and manges the input and output of messages from thser server. DO NOT CALL THIS METHOD.

bool CMOOSCommClient::Close bool  bNice = true  ) 
 

make the client shut down

bool CMOOSCommClient::ConnectToServer  )  [protected]
 

Connect to the server process using info supplied to Init

See also:
Init

void CMOOSCommClient::DoBanner  )  [protected]
 

send library info to stdout

bool CMOOSCommClient::DoClientWork  )  [virtual]
 

called by the above to do the client mail box shuffling

bool CMOOSCommClient::FakeSource bool  bFake  ) 
 

call with "true" if you want thsi client to fake its own outgoing name. This is rarely used but very useful when it is

bool CMOOSCommClient::Fetch MOOSMSG_LIST &  MsgList  ) 
 

Called by a user of CMOOSCommClient to retrieve mail

Parameters:
MsgList a list of messages into which the newly received message will be placed
Returns:
true if there is new mail

string CMOOSCommClient::GetDescription  ) 
 

describe this client in a string

string CMOOSCommClient::GetLocalIPAddress  )  [static]
 

return a string of the host machines's IP adress

std::set<std::string> CMOOSCommClient::GetPublished  )  [inline]
 

return the list of messages names published

std::set<std::string> CMOOSCommClient::GetRegistered  )  [inline]
 

return the list of messages registered

bool CMOOSCommClient::HandShake  )  [protected]
 

performs a handshake with the server when a new connection is made. Within this function this class tells teh server its name

bool CMOOSCommClient::IsConnected  ) 
 

returns true if this obecjt is connected to the server

bool CMOOSCommClient::Notify const std::string &  sVar,
double  dfVal,
double  dfTime = -1
 

notify the MOOS community that something has changed (double)

bool CMOOSCommClient::Notify const std::string &  sVar,
const std::string &  sVal,
double  dfTime = -1
 

notify the MOOS community that something has changed (string)

bool CMOOSCommClient::OnCloseConnection  )  [protected]
 

called when connection to server is closed

bool CMOOSCommClient::Peek MOOSMSG_LIST &  List,
int  nIDRequired,
bool  bClearBox = true
 

Have a peek at mail box and remove a particular message, by default all other messages are removed. Note this is quite different from PeekMail

static bool CMOOSCommClient::PeekMail MOOSMSG_LIST &  Mail,
const std::string &  sKey,
CMOOSMsg Msg,
bool  bErase = false,
bool  bFindYoungest = false
[static]
 

a static helper function hat lets a user browse a mail list the message is removed if bremove is true

bool CMOOSCommClient::Post CMOOSMsg Msg  ) 
 

place a single message in the out box and return immediately. Completion of this method does not infer transmission. However transmission will occur at the next available oppurtunity. Inpractice the apparent speed of message transmission will be very fast indeed. This model howver prevents wayward user software bring down the MOOSComms by way of denial of service. (ie hogging the network)

Parameters:
Msg reference to CMOOSMsg which user whishes to send

bool CMOOSCommClient::Register const std::string &  sVar,
double  dfInterval
 

Register for notification in changes of named variable

Parameters:
sVar name of variable of interest
dfInterval minimum time between notifications

bool CMOOSCommClient::Run const char *  sServer,
long  lPort,
const char *  sMyName,
unsigned int  nFundamentalFreq = 5
 

Run the MOOSCommClient Object. This call is non blocking and begins managing process IO with the MOOSComms protocol

Parameters:
sServer Name of machine on which server resides eg LOCALHOST or guru.mit.edu
lPort number of port on which server is listening for new connections eg 9000
sMyName std::string name by which this MOOS process will be known - eg "MotionController" or "DepthSensor"
nFundamentalFrequency the basic tick frequency of the comms loop. Default value of 5 implies mail will be retrieved and sent from the server at 5Hz

bool CMOOSCommClient::ServerRequest const std::string &  sWhat,
MOOSMSG_LIST &  MsgList,
double  dfTimeOut = 2.0,
bool  bContinuouslyClearBox = true
 

Directly and asynhrounously make a request to the server (use this very rarely if ever. Its not meant for public consumption)

Parameters:
sWhat string specifying what request to make - ALL, DB_CLEAR, PROCESS_SUMMARY or VAR_SUMMARY
MsgList List of messages returned by server
dfTimeOut TimeOut
bContinuouslyClearBox true if all other message returned with query are to be discarded.

void CMOOSCommClient::SetOnConnectCallBack bool(*)(void *pParamCaller)  pfn,
void *  pCallerParam
 

set the user supplied OnConnect call back. This callback , when set, will be invoked when a connection to the server is made. It is a good plan to register for notification of variables in this callback

Parameters:
pfn pointer to static function of type bool Fn(void * pParam)
pCallerParam parameter passed to callback function when invoked

void CMOOSCommClient::SetOnDisconnectCallBack bool(*)(void *pParamCaller)  pfn,
void *  pCallerParam
 

set the user supplied OnConnect call back. This callback , when set, will be invoked when a connection to the server is lost.

Parameters:
pfn pointer to static function of type bool Fn(void * pParam)
pCallerParam parameter passed to callback function when invoked

bool CMOOSCommClient::StartThreads  )  [protected]
 

called internally to start IO management thread

See also:
ClientLoop

bool CMOOSCommClient::UnRegister const std::string &  sVar  ) 
 

UnRegister for notification in changes of named variable

Parameters:
sVar name of variable of interest


Member Data Documentation

bool CMOOSCommClient::m_bConnected [protected]
 

true if we are connected to the server

bool CMOOSCommClient::m_bFakeSource [protected]
 

true if we want to be able to fake sources of messages (used by playback)

bool CMOOSCommClient::m_bMailPresent [protected]
 

true if mail present (saves using a semaphore to open an empty box)

bool CMOOSCommClient::m_bQuit [protected]
 

IO thread will continue so long as this flag is false

MOOSMSG_LIST CMOOSCommClient::m_InBox [protected]
 

List of message that have been received and are ready for reading by user

See also:
Fetch

CMOOSLock CMOOSCommClient::m_InLock [protected]
 

Mutex around incoming mail box

See also:
CMOOSLock

long CMOOSCommClient::m_lPort [protected]
 

port number on which server process is listening for new connections

See also:
Init

unsigned int CMOOSCommClient::m_nFundamentalFreq [protected]
 

funcdamental frequency with which comms with server occurs

See also:
Run

unsigned int CMOOSCommClient::m_nInPendingLimit [protected]
 

The number of unread incoming messages that can be tolerated

unsigned int CMOOSCommClient::m_nOutPendingLimit [protected]
 

The number of pending unsent messages that can be tolerated

MOOSMSG_LIST CMOOSCommClient::m_OutBox [protected]
 

List of messages that a pending to be sent

See also:
Post

CMOOSLock CMOOSCommClient::m_OutLock [protected]
 

Mutex around Outgoing mail box

See also:
CMOOSLock

void* CMOOSCommClient::m_pConnectCallBackParam [protected]
 

parameter that user wants passed to him/her with connect callback

void* CMOOSCommClient::m_pDisconnectCallBackParam [protected]
 

parameter that user wants passed to him/her with disconnect callback

bool(* CMOOSCommClient::m_pfnConnectCallBack)(void *pConnectParam) [protected]
 

the user supplied OnConnect callback

bool(* CMOOSCommClient::m_pfnDisconnectCallBack)(void *pParam) [protected]
 

the user supplied OnDisConnect callback

XPCTcpSocket* CMOOSCommClient::m_pSocket [protected]
 

pointer to socket connected to server

std::set<std::string> CMOOSCommClient::m_Published [protected]
 

the set of messages names/keys that have been sent

std::set<std::string> CMOOSCommClient::m_Registered [protected]
 

a set of strings of the resources (messages names/keys) that have been registered for

std::string CMOOSCommClient::m_sDBHost [protected]
 

name of teh host on which the server process lives

See also:
Init

std::string CMOOSCommClient::m_sMyName [protected]
 

name of MOOS process

See also:
Init


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