MOOS 0.2375
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
CMOOSCommClient Class Reference

#include <MOOSCommClient.h>

Inheritance diagram for CMOOSCommClient:
Inheritance graph
[legend]
Collaboration diagram for CMOOSCommClient:
Collaboration graph
[legend]

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, const std::string &sVal, const std::string &sSrcAux, double dfTime=-1)
bool Notify (const std::string &sVar, double dfVal, double dfTime=-1)
bool Notify (const std::string &sVar, double dfVal, const std::string &sSrcAux, double dfTime=-1)
bool Notify (const std::string &sVar, void *pData, unsigned int nDataSize, double dfTime=-1)
bool Notify (const std::string &sVar, void *pData, unsigned int nDataSize, const std::string &sSrcAux, 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)
void SetOnMailCallBack (bool(*pfn)(void *pParamCaller), void *pCallerParam)
bool HasMailCallBack ()
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 ()
bool IsRegisteredFor (const std::string &sVariable)
std::set< std::string > GetRegistered ()
void SetQuiet (bool bQ)
void DoLocalTimeCorrection (bool b)
void SetVerboseDebug (bool bT)
bool SetCommsTick (int nCommsTick)

Static Public Member Functions

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

Protected Member Functions

bool ClearResources ()
void DoBanner ()
bool OnCloseConnection ()
bool HandShake ()
bool ConnectToServer ()
bool StartThreads ()
bool UpdateMOOSSkew (double dfRQTime, 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
XPCTcpSocketm_pSocket
std::string m_sDBHost
long m_lPort
bool m_bQuit
bool m_bMailPresent
CMOOSThread m_ClientThread
MOOSMSG_LIST m_OutBox
MOOSMSG_LIST m_InBox
void * m_pConnectCallBackParam
bool(* m_pfnConnectCallBack )(void *pConnectParam)
void * m_pDisconnectCallBackParam
bool(* m_pfnDisconnectCallBack )(void *pParam)
void * m_pMailCallBackParam
bool(* m_pfnMailCallBack )(void *pParam)
unsigned int m_nFundamentalFreq
std::set< std::string > m_Registered
std::set< std::string > m_Published
bool m_bQuiet
bool m_bVerboseDebug
bool m_bDoLocalTimeCorrection
std::auto_ptr
< MOOS::CMOOSSkewFilter
m_pSkewFilter
bool m_bClientLoopIsRunning

Detailed Description

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

Definition at line 71 of file MOOSCommClient.h.


Constructor & Destructor Documentation

CMOOSCommClient::CMOOSCommClient ( )

default constructor

Definition at line 87 of file MOOSCommClient.cpp.

CMOOSCommClient::~CMOOSCommClient ( ) [virtual]

default destructor

Definition at line 121 of file MOOSCommClient.cpp.


Member Function Documentation

bool CMOOSCommClient::ClearResources ( ) [protected]

Definition at line 995 of file MOOSCommClient.cpp.

bool CMOOSCommClient::ClientLoop ( )

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

Definition at line 213 of file MOOSCommClient.cpp.

bool CMOOSCommClient::Close ( bool  bNice = true)

make the client shut down

Definition at line 963 of file MOOSCommClient.cpp.

bool CMOOSCommClient::ConnectToServer ( ) [protected]

Connect to the server process using info supplied to Init

See also:
Init

Definition at line 406 of file MOOSCommClient.cpp.

void CMOOSCommClient::DoBanner ( ) [protected]

send library info to stdout

Definition at line 687 of file MOOSCommClient.cpp.

bool CMOOSCommClient::DoClientWork ( ) [virtual]

called by the above to do the client mail box shuffling

Definition at line 272 of file MOOSCommClient.cpp.

void CMOOSCommClient::DoLocalTimeCorrection ( bool  b) [inline]

used to control whether local clock skew (used by MOOSTime()) is se via the server at the other end of this connection

Definition at line 209 of file MOOSCommClient.h.

bool CMOOSCommClient::FakeSource ( bool  bFake)

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

Definition at line 989 of file MOOSCommClient.cpp.

bool CMOOSCommClient::Fetch ( MOOSMSG_LIST MsgList)

Called by a user of CMOOSCommClient to retrieve mail

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

this is called by a user of a CommClient object to retrieve mail

Definition at line 554 of file MOOSCommClient.cpp.

string CMOOSCommClient::GetDescription ( )

describe this client in a string

Definition at line 1023 of file MOOSCommClient.cpp.

string CMOOSCommClient::GetLocalIPAddress ( ) [static]

return a string of the host machines's IP adress

Definition at line 1029 of file MOOSCommClient.cpp.

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

return the list of messages names published

Definition at line 196 of file MOOSCommClient.h.

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

return the list of messages registered

Definition at line 202 of file MOOSCommClient.h.

bool CMOOSCommClient::HandShake ( ) [protected]

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

Definition at line 587 of file MOOSCommClient.cpp.

bool CMOOSCommClient::HasMailCallBack ( )

return true if a mail callback is installed

Definition at line 192 of file MOOSCommClient.cpp.

bool CMOOSCommClient::IsConnected ( )

returns true if this obecjt is connected to the server

Definition at line 645 of file MOOSCommClient.cpp.

bool CMOOSCommClient::IsRegisteredFor ( const std::string &  sVariable)

return true if we are registered for named variable

Definition at line 746 of file MOOSCommClient.cpp.

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

Definition at line 763 of file MOOSCommClient.cpp.

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

Definition at line 787 of file MOOSCommClient.cpp.

bool CMOOSCommClient::Notify ( const std::string &  sVar,
void *  pData,
unsigned int  nDataSize,
double  dfTime = -1 
)

notify the MOOS community that something has changed binary data. These are experimental - don't use them until I say so

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::Notify ( const std::string &  sVar,
void *  pData,
unsigned int  nDataSize,
const std::string &  sSrcAux,
double  dfTime = -1 
)
bool CMOOSCommClient::Notify ( const std::string &  sVar,
double  dfVal,
double  dfTime = -1 
)

notify the MOOS community that something has changed (double)

bool CMOOSCommClient::OnCloseConnection ( ) [protected]

called when connection to server is closed

Definition at line 650 of file MOOSCommClient.cpp.

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

Definition at line 865 of file MOOSCommClient.cpp.

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

a static helper function that lets a user browse a mail list as for PeekMail. true is returned if mail is found and it is not more that 5 seconds old

Definition at line 955 of file MOOSCommClient.cpp.

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

a static helper function that 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 imply transmission. However transmission will occur at the next available oppurtunity. In practice the apparent speed of message transmission will be very fast indeed. This model however prevents wayward user software bring down the MOOSComms by way of denial of service. (ie hogging the network)

Parameters:
Msgreference to CMOOSMsg which user wishes to send

this is called by user of a CommClient object to send a Msg to MOOS

Definition at line 503 of file MOOSCommClient.cpp.

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

Register for notification in changes of named variable

Parameters:
sVarname of variable of interest
dfIntervalminimum 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:
sServerName of machine on which server resides eg LOCALHOST or guru.mit.edu
lPortnumber of port on which server is listening for new connections eg 9000
sMyNamestd::string name by which this MOOS process will be known - eg "MotionController" or "DepthSensor"
nFundamentalFrequencythe basic tick frequency of the comms loop. Default value of 5 implies mail will be retrieved and sent from the server at 5Hz

Definition at line 126 of file MOOSCommClient.cpp.

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

Directly and asynchronously make a request to the server (use this very rarely if ever. It's not meant for public consumption)

Parameters:
sWhatstring specifying what request to make - ALL, DB_CLEAR, PROCESS_SUMMARY or VAR_SUMMARY
MsgListList of messages returned by server
dfTimeOutTimeOut
bContinuouslyClearBoxtrue if all other message returned with query are to be discarded.

Definition at line 830 of file MOOSCommClient.cpp.

bool CMOOSCommClient::SetCommsTick ( int  nCommsTick)

Definition at line 165 of file MOOSCommClient.cpp.

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:
pfnpointer to static function of type bool Fn(void * pParam)
pCallerParamparameter passed to callback function when invoked

Definition at line 199 of file MOOSCommClient.cpp.

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:
pfnpointer to static function of type bool Fn(void * pParam)
pCallerParamparameter passed to callback function when invoked
void CMOOSCommClient::SetOnMailCallBack ( bool(*)(void *pParamCaller)  pfn,
void *  pCallerParam 
)

set the user supplied OnMail callback. This usually will not be set. Users are expected to use FetchMail from their own thread and not use this call back. This function is experimental as of release 7.2 and coders are not encouraged to use it

Definition at line 186 of file MOOSCommClient.cpp.

void CMOOSCommClient::SetQuiet ( bool  bQ) [inline]

used to control how verbose the connection process is

Definition at line 205 of file MOOSCommClient.h.

void CMOOSCommClient::SetVerboseDebug ( bool  bT) [inline]

used to control debug printing

Definition at line 212 of file MOOSCommClient.h.

bool CMOOSCommClient::StartThreads ( ) [protected]

called internally to start IO management thread

See also:
ClientLoop

Definition at line 395 of file MOOSCommClient.cpp.

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

UnRegister for notification in changes of named variable

Parameters:
sVarname of variable of interest

Definition at line 704 of file MOOSCommClient.cpp.

bool CMOOSCommClient::UpdateMOOSSkew ( double  dfRQTime,
double  dfTXTime,
double  dfRXTime 
) [protected]

Definition at line 1043 of file MOOSCommClient.cpp.


Member Data Documentation

Tells us whether the ClientLoop is running.

Definition at line 339 of file MOOSCommClient.h.

true if we are connected to the server

Definition at line 228 of file MOOSCommClient.h.

controls whether skew is set

Definition at line 333 of file MOOSCommClient.h.

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

Definition at line 231 of file MOOSCommClient.h.

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

Definition at line 280 of file MOOSCommClient.h.

controls how verbose connectionn is

Definition at line 327 of file MOOSCommClient.h.

IO thread will continue so long as this flag is false

Definition at line 277 of file MOOSCommClient.h.

controls verbose debugging printing

Definition at line 330 of file MOOSCommClient.h.

Definition at line 285 of file MOOSCommClient.h.

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

See also:
Fetch

Definition at line 293 of file MOOSCommClient.h.

Mutex around incoming mail box

See also:
CMOOSLock

Definition at line 254 of file MOOSCommClient.h.

long CMOOSCommClient::m_lPort [protected]

port number on which server process is listening for new connections

See also:
Init

Definition at line 274 of file MOOSCommClient.h.

unsigned int CMOOSCommClient::m_nFundamentalFreq [protected]

funcdamental frequency with which comms with server occurs

See also:
Run

Definition at line 318 of file MOOSCommClient.h.

unsigned int CMOOSCommClient::m_nInPendingLimit [protected]

The number of unread incoming messages that can be tolerated

Definition at line 241 of file MOOSCommClient.h.

Definition at line 219 of file MOOSCommClient.h.

unsigned int CMOOSCommClient::m_nOutPendingLimit [protected]

The number of pending unsent messages that can be tolerated

Definition at line 238 of file MOOSCommClient.h.

List of messages that a pending to be sent

See also:
Post

Definition at line 289 of file MOOSCommClient.h.

Mutex around Outgoing mail box

See also:
CMOOSLock

Definition at line 250 of file MOOSCommClient.h.

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

Definition at line 296 of file MOOSCommClient.h.

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

Definition at line 303 of file MOOSCommClient.h.

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

the user supplied OnConnect callback

Definition at line 299 of file MOOSCommClient.h.

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

the user supplied OnDisConnect callback

Definition at line 306 of file MOOSCommClient.h.

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

the user supplied OnMailCallBack

Definition at line 312 of file MOOSCommClient.h.

parameter that user wants passed to mail callback

Definition at line 309 of file MOOSCommClient.h.

Skew filter keeps track of clock skew with server

Definition at line 336 of file MOOSCommClient.h.

pointer to socket connected to server

Definition at line 266 of file MOOSCommClient.h.

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

the set of messages names/keys that have been sent

Definition at line 324 of file MOOSCommClient.h.

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

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

Definition at line 321 of file MOOSCommClient.h.

std::string CMOOSCommClient::m_sDBHost [protected]

name of the host on which the server process lives

See also:
Init

Definition at line 270 of file MOOSCommClient.h.

std::string CMOOSCommClient::m_sMyName [protected]

name of MOOS process

See also:
Init

Definition at line 245 of file MOOSCommClient.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines