MOOS 0.2375
Public Member Functions | Protected Member Functions | Protected Attributes
CMOOSApp Class Reference

#include <MOOSApp.h>

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

List of all members.

Public Member Functions

 CMOOSApp ()
virtual ~CMOOSApp ()
bool Run (const char *sName, const char *sMissionFile, const char *sSubscribeName)
bool Run (const char *sName, const char *sMissionFile)
virtual bool OnConnectToServer ()
virtual bool OnDisconnectFromServer ()
bool RequestQuit ()
void OnDisconnectToServerPrivate ()
void OnConnectToServerPrivate ()
bool OnMailCallBack ()
bool UseMailCallBack ()

Protected Member Functions

virtual bool Iterate ()
virtual bool OnNewMail (MOOSMSG_LIST &NewMail)
virtual bool OnCommandMsg (CMOOSMsg Msg)
virtual std::string MakeStatusString ()
bool SetCommsFreq (unsigned int nFreq)
void SetAppFreq (double dfFreq)
double GetAppStartTime ()
bool DoRunWork ()
void SetAppError (bool bFlag, const std::string &sReason)
void SetServer (const char *sServerHost="LOCALHOST", long lPort=9000)
bool UseMOOSComms (bool bUse)
void SortMailByTime (bool bSort=true)
void SetQuitOnFailedIterate (bool bQuit)
bool MOOSDebugWrite (const std::string &sTxt)
void EnableCommandMessageFiltering (bool bEnable)
void EnableIterateWithoutComms (bool bEnable)
bool LookForAndHandleAppCommand (MOOSMSG_LIST &NewMail)
std::string GetAppName ()
std::string GetMissionFileName ()
bool AddMOOSVariable (std::string sName, std::string sSubscribeName, std::string sPublishName, double dfCommsTime)
bool SetMOOSVar (const CMOOSVariable &MOOSVar)
CMOOSVariableGetMOOSVar (std::string sName)
bool RegisterMOOSVariables ()
bool UpdateMOOSVariables (MOOSMSG_LIST &NewMail)
bool SetMOOSVar (const std::string &sName, const std::string &sVal, double dfTime)
bool SetMOOSVar (const std::string &sVarName, double dfVal, double dfTime)
bool PublishFreshMOOSVariables ()
bool IsSimulateMode ()
virtual bool OnStartUp ()
virtual bool ConfigureComms ()
double GetTimeSinceIterate ()
double GetLastIterateTime ()
int GetIterateCount ()
bool CanIterateWithoutComms ()
std::string GetCommandKey ()
bool IsDebug ()

Protected Attributes

CMOOSCommClient m_Comms
CProcessConfigReader m_MissionReader
MOOSVARMAP m_MOOSVars
bool m_bSimMode
long m_lServerPort
std::string m_sServerHost
std::string m_sServerPort
bool m_bServerSet
bool m_bUseMOOSComms
std::string m_sAppName
std::string m_sMOOSName
int m_nCommsFreq
double m_dfFreq
std::string m_sMissionFile
bool m_bCommandMessageFiltering
bool m_bQuitOnIterateFail
double m_dfAppStartTime
double m_dfLastRunTime
bool m_bSortMailByTime
std::string m_sAppError
bool m_bAppError
bool m_bDebug

Detailed Description

This is a class from which all MOOS component applications can be derived main() will typically end with a call to MOOSAppDerivedClass::Run(). It provides automatic connection to the MOOSDB, provides slots for Mail Processing and application work, callbacks for connection/disconnection to MOOSDB, Configuration file reading and dynamic (runtime) variables. Definately worth getting to know.

Definition at line 58 of file MOOSApp.h.


Constructor & Destructor Documentation

CMOOSApp::CMOOSApp ( )

Definition at line 109 of file MOOSApp.cpp.

CMOOSApp::~CMOOSApp ( ) [virtual]

Definition at line 133 of file MOOSApp.cpp.


Member Function Documentation

bool CMOOSApp::AddMOOSVariable ( std::string  sName,
std::string  sSubscribeName,
std::string  sPublishName,
double  dfCommsTime 
) [protected]

Add a dynamic (run time) variable

Parameters:
sNamename of the variable
sSubscribeNameif you call RegisterMOOSVariables() the variable will be updated with mail called <sSubscribeName> if and when you call UpdateMOOSVariables()
sPublishNameif you call PublishFreshMOOSVariables() (and you've written to the dynamic varible since the last call) the variable will be published under this name.
CommsTime- if sSubscribeName is not empty this is the minimum time between updates which you are interested in knowing about, so if CommsTime=0.1 then the maximum update rate you will see on the variable from the DB is 10HZ.

Definition at line 550 of file MOOSApp.cpp.

bool CMOOSApp::CanIterateWithoutComms ( ) [protected]

returns true if we can iterate without comms

Definition at line 687 of file MOOSApp.cpp.

bool CMOOSApp::ConfigureComms ( ) [protected, virtual]

start up the comms

Definition at line 461 of file MOOSApp.cpp.

bool CMOOSApp::DoRunWork ( ) [protected]

A function which Run eventually calls which itself calls on NewMail and Iterate

Definition at line 294 of file MOOSApp.cpp.

void CMOOSApp::EnableCommandMessageFiltering ( bool  bEnable) [protected]

enable/disable the behind the scenes search for command messages

Definition at line 764 of file MOOSApp.cpp.

void CMOOSApp::EnableIterateWithoutComms ( bool  bEnable) [protected]

Allow ::Iterate to be called without a connection to a DB

Definition at line 692 of file MOOSApp.cpp.

string CMOOSApp::GetAppName ( ) [protected]

return the application name

Definition at line 715 of file MOOSApp.cpp.

double CMOOSApp::GetAppStartTime ( ) [protected]

return the boot time of the App

Definition at line 522 of file MOOSApp.cpp.

std::string CMOOSApp::GetCommandKey ( ) [protected]

returns the string which constitutes a command string for this application. if CommandFiltering is enabled (see EnableCommandMessageFiltering() ) the application will filter incoming mail and Call OnCommandMsg() (which can be overiden) if a message with this command string as a name is received. Command strings look like APPNAME_CMD

Definition at line 741 of file MOOSApp.cpp.

int CMOOSApp::GetIterateCount ( ) [protected]

return number of times iterate has been called

Definition at line 517 of file MOOSApp.cpp.

double CMOOSApp::GetLastIterateTime ( ) [protected]

Return time at which the Run loop last ran (called Iterate) - this is a local time - you need to add GetMOOSSKew to produce a unified system time

Definition at line 704 of file MOOSApp.cpp.

std::string CMOOSApp::GetMissionFileName ( ) [protected]

return the application mission file name

Definition at line 710 of file MOOSApp.cpp.

CMOOSVariable * CMOOSApp::GetMOOSVar ( std::string  sName) [protected]

return a pointer to a named variable

Definition at line 727 of file MOOSApp.cpp.

double CMOOSApp::GetTimeSinceIterate ( ) [protected]

Time since last iterate was called

Definition at line 699 of file MOOSApp.cpp.

bool CMOOSApp::IsDebug ( ) [inline, protected]

Definition at line 312 of file MOOSApp.h.

bool CMOOSApp::IsSimulateMode ( ) [protected]

Returns true if Simulate = true is found in the mission/configuration file (a global flag) - the mission file is not re-read on each call

Definition at line 545 of file MOOSApp.cpp.

bool CMOOSApp::Iterate ( ) [protected, virtual]

called when the application should iterate. Overload this function in a derived class and within it write all the application specific code. It will be called at approximately nFreq = 1/AppTick Hz

Reimplemented in CB, CSimpleApp, CSimpleApp, CSimulator, CSimulator, CMessager, CMOOSLogger, CMOOSScheduler, CGPSInstrument, CMOOSActuation, CADVInstrument, CBatteryInstrument, CCompassInstrument, CDepthInstrument, CDVLInstrument, CINSInstrument, CMOOSJanitor, CLBLInstrument, CRelayBoard, CHelmApp, CMOOSNavigator, and CMVSim.

Definition at line 426 of file MOOSApp.cpp.

bool CMOOSApp::LookForAndHandleAppCommand ( MOOSMSG_LIST NewMail) [protected]

dispatching function for ::OnCommandMsg

Definition at line 748 of file MOOSApp.cpp.

std::string CMOOSApp::MakeStatusString ( ) [protected, virtual]

make a status string - overload this in a derived class if you want to modify or what the statuts string looks like

Reimplemented in CMOOSLogger.

Definition at line 780 of file MOOSApp.cpp.

bool CMOOSApp::MOOSDebugWrite ( const std::string &  sTxt) [protected]

Call this to write a debug string to the DB under the name "MOOS_DEBUG"

Definition at line 674 of file MOOSApp.cpp.

bool CMOOSApp::OnCommandMsg ( CMOOSMsg  Msg) [protected, virtual]

optionally (see ::EnableCommandMessageFiltering() ) called when a command message (<MOOSNAME>_CMD) is recieved by the application.

Parameters:
acopy of CmdMsg the message purporting to be a "command" - i.e. has the name <MOOSNAME>_CMD

Reimplemented in CMOOSLogger.

Definition at line 454 of file MOOSApp.cpp.

bool CMOOSApp::OnConnectToServer ( ) [virtual]

Called when the class has succesully connected to the server. Overload this function and place use it to register for notification when variables of interest change

Reimplemented in CSimpleApp, CSimpleApp, CSimulator, CSimulator, CMessager, CMOOSLogger, CMOOSScheduler, CGPSInstrument, CMOOSActuation, CADVInstrument, CBatteryInstrument, CCompassInstrument, CDepthInstrument, CDVLInstrument, CINSInstrument, CMOOSJanitor, CLBLInstrument, CRelayBoard, CMOOSRemote, CHelmApp, CMOOSNavigator, and CMVSim.

Definition at line 435 of file MOOSApp.cpp.

void CMOOSApp::OnConnectToServerPrivate ( )

Definition at line 811 of file MOOSApp.cpp.

bool CMOOSApp::OnDisconnectFromServer ( ) [virtual]

Called when the class has disconnects from the server. Put code you want to run when this happens in a virtual version of this method

Definition at line 442 of file MOOSApp.cpp.

void CMOOSApp::OnDisconnectToServerPrivate ( )

these two functions are used to handle private MOOSApp work that need to occur on behalf of derived classes at the same time as the overloaded OnConnectToServer and OnDisconnectFromServer methods are called. They are public to allow their invokation from a call back. They are not interesting to the casual user

Definition at line 805 of file MOOSApp.cpp.

bool CMOOSApp::OnMailCallBack ( )

this is a call back from MOOSComms and its use is specialised (not for general consumption)

Definition at line 449 of file MOOSApp.cpp.

bool CMOOSApp::OnNewMail ( MOOSMSG_LIST NewMail) [protected, virtual]

called when new mail has arrived. Overload this method in a derived class to process new mail. It will be called at approximately 1/CommsTick Hz. In this function you'll most likely interate over the collection of mail message received or call a m_Comms::PeekMail() to look for a specific named message.

Parameters:
NewMaila list of new mail messages

Reimplemented in CSimpleApp, CSimpleApp, CSimulator, CSimulator, CMessager, CMOOSLogger, CMOOSScheduler, CGPSInstrument, CMOOSActuation, CADVInstrument, CBatteryInstrument, CCompassInstrument, CDepthInstrument, CDVLInstrument, CINSInstrument, CMOOSJanitor, CLBLInstrument, CRelayBoard, CHelmApp, CMOOSNavigator, and CMVSim.

Definition at line 421 of file MOOSApp.cpp.

bool CMOOSApp::OnStartUp ( ) [protected, virtual]

called just before the main app loop is entered. Specific initialisation code can be written in an overloaded version of this function

over load this if you want to do something fancy at statup...

Reimplemented in CMOOSInstrument, CSimpleApp, CSimpleApp, CSimulator, CSimulator, CMOOSLogger, CMOOSScheduler, CGPSInstrument, CMOOSActuation, CADVInstrument, CBatteryInstrument, CCompassInstrument, CDepthInstrument, CDVLInstrument, CINSInstrument, CMOOSJanitor, CLBLInstrument, CRelayBoard, CMOOSRemote, CHelmApp, CMOOSNavigator, and CMVSim.

Definition at line 512 of file MOOSApp.cpp.

bool CMOOSApp::PublishFreshMOOSVariables ( ) [protected]

Send any variables (under their sPublishName see AddMOOSVariable) which been written too since the last call of PublishFreshMOOSVariables()

Definition at line 565 of file MOOSApp.cpp.

bool CMOOSApp::RegisterMOOSVariables ( ) [protected]

Register with the DB to be mailed about any changes to any dynamic variables which were created with non-empty sSubscribeName fields

Definition at line 650 of file MOOSApp.cpp.

bool CMOOSApp::RequestQuit ( )

requests the MOOSApp to quit (i.e return from Run)

Definition at line 288 of file MOOSApp.cpp.

bool CMOOSApp::Run ( const char *  sName,
const char *  sMissionFile 
)

let derivatives do stuff before execution

Reimplemented in CMOOSRemote.

Definition at line 147 of file MOOSApp.cpp.

bool CMOOSApp::Run ( const char *  sName,
const char *  sMissionFile,
const char *  sSubscribeName 
)

called to start the application

Parameters:
sNameThe name of this application (used to read configuration from a mission file and if sSubscribeName is NULL, to register with the MOOSDB)
thename of the mission file
thesubscribe name of the application. If NULL then sName

Definition at line 139 of file MOOSApp.cpp.

void CMOOSApp::SetAppError ( bool  bFlag,
const std::string &  sReason 
) [protected]

sets the error state of the app and a comment - this is published as a field in <PROCNAME>_STATUS

Definition at line 402 of file MOOSApp.cpp.

void CMOOSApp::SetAppFreq ( double  dfFreq) [protected]

Set the time between calls of ::Iterate (which is where you'll probably do Application work)- can be set using the AppTick flag in the config file

Definition at line 527 of file MOOSApp.cpp.

bool CMOOSApp::SetCommsFreq ( unsigned int  nFreq) [protected]

Set the time between calls into the DB - can be set using the CommsTick flag in the config file

Definition at line 535 of file MOOSApp.cpp.

bool CMOOSApp::SetMOOSVar ( const std::string &  sVarName,
double  dfVal,
double  dfTime 
) [protected]

Set value in a dynamic variable if the variable is of type string (type is set on first write )

bool CMOOSApp::SetMOOSVar ( const CMOOSVariable MOOSVar) [protected]

Sets the value of a previously added dynamic variable to the given CMOOSVariable.

Returns:
true if the variable's type and value were set, false otherwise.

Definition at line 616 of file MOOSApp.cpp.

bool CMOOSApp::SetMOOSVar ( const std::string &  sName,
const std::string &  sVal,
double  dfTime 
) [protected]

Set value in a dynamic variable if the variable is of type double (type is set on first write )

void CMOOSApp::SetQuitOnFailedIterate ( bool  bQuit) [inline, protected]

set to true to make the App sensitive (and quit) to Iterate() returning false

Definition at line 154 of file MOOSApp.h.

void CMOOSApp::SetServer ( const char *  sServerHost = "LOCALHOST",
long  lPort = 9000 
) [protected]

Called to set the MOOS server info used rarely usually this info will be picked up by the MOOSApp automatically when it ::Run is called specifying the configuration file (which contains the DB's coordinates)

Parameters:
sServerHostname of the machine hosting the MOOSDB application
lPortport nuymber that MOOSDB listens on

Definition at line 377 of file MOOSApp.cpp.

void CMOOSApp::SortMailByTime ( bool  bSort = true) [inline, protected]

call to say if you want mail to be delivered sorted by time

Definition at line 151 of file MOOSApp.h.

bool CMOOSApp::UpdateMOOSVariables ( MOOSMSG_LIST NewMail) [protected]

Pass mail (usually collected in OnNewMail) to the set of dynamic variables. If they are interested (mail name matches their subscribe name) they will update themselves automatically

Definition at line 628 of file MOOSApp.cpp.

bool CMOOSApp::UseMailCallBack ( )

Definition at line 410 of file MOOSApp.cpp.

bool CMOOSApp::UseMOOSComms ( bool  bUse) [protected]

By default MOOSDB comms are on - but you may want to use the structuire of MOOSApp as a standalone application - if so call this function with a false parameter

Definition at line 720 of file MOOSApp.cpp.


Member Data Documentation

flag specifying the error state of the App - set via SetAppError()

Definition at line 283 of file MOOSApp.h.

flag specifying whether command message fitlering is enabled

Definition at line 265 of file MOOSApp.h.

bool CMOOSApp::m_bDebug [protected]

Definition at line 310 of file MOOSApp.h.

flag to say whether or not App should quit after an Iterate returns false

Definition at line 268 of file MOOSApp.h.

true if the server has been set

Definition at line 244 of file MOOSApp.h.

flag saying whether MOOS is running with a simulator can be set by registering for SIMULATION_MODE variable

Definition at line 224 of file MOOSApp.h.

should mail be handed to the user sorted by increasing time

Definition at line 277 of file MOOSApp.h.

true if we want to use MOOS comms

Definition at line 247 of file MOOSApp.h.

The MOOSComms node. All communications happens by way of this object. You'll often do things like m_Comms.Notify("VARIABLE_X","STRING_DATA",dfTime) top send data

Definition at line 112 of file MOOSApp.h.

double CMOOSApp::m_dfAppStartTime [protected]

The start time of the application

Definition at line 270 of file MOOSApp.h.

double CMOOSApp::m_dfFreq [protected]

frequency at which this application will iterate

Definition at line 259 of file MOOSApp.h.

double CMOOSApp::m_dfLastRunTime [protected]

Time at which the Run loop last ran (called Iterate)

Definition at line 273 of file MOOSApp.h.

long CMOOSApp::m_lServerPort [protected]

Port on which server application listens for new connection

Definition at line 235 of file MOOSApp.h.

a very useful object that lets us retrieve configuration information from the mission file using calls like ::GetConfigurationParam()

Definition at line 124 of file MOOSApp.h.

a map of dynamic/run time moos variables that may be set by comms - avoid messy long if else if statements

Definition at line 216 of file MOOSApp.h.

int CMOOSApp::m_nCommsFreq [protected]

frequency at which server will be contacted

Definition at line 256 of file MOOSApp.h.

std::string CMOOSApp::m_sAppError [protected]

string that should be written to the status string if the App Error flag is true

Definition at line 280 of file MOOSApp.h.

std::string CMOOSApp::m_sAppName [protected]

name of this application

Definition at line 250 of file MOOSApp.h.

std::string CMOOSApp::m_sMissionFile [protected]

std::string name of mission file

Definition at line 262 of file MOOSApp.h.

std::string CMOOSApp::m_sMOOSName [protected]

subscribe name of application usually by default this will be m_sAppName

Definition at line 253 of file MOOSApp.h.

std::string CMOOSApp::m_sServerHost [protected]

name of machine on which MOOS Server resides

Definition at line 238 of file MOOSApp.h.

std::string CMOOSApp::m_sServerPort [protected]

std::string version of m_lServerPort

Definition at line 241 of file MOOSApp.h.


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