AURobotServers  4
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
UMisRuleState Class Reference

#include <uresrulestate.h>

Inheritance diagram for UMisRuleState:
Inheritance graph

Public Types

enum  BlockState { inactive, init, main, post }
 

Public Member Functions

bool addRule (UMisRule *plan, bool activate)
 
UMisRuleStategetCalled ()
 Get called plan state If this plan is waiting in a called plan, get the called plan state. More...
 
UMisRuleStategetCaller (const char *name)
 get the state structure of the first caller of the plan with this name. The caller makes the plan busy, so it is nice to know who is calling this plan. More...
 
UMisRulegetRule ()
 
bool getStateStr (const char *pre, char *buff, const int buffCnt)
 
int getSubRulesCnt ()
 
bool isActive (const char *planName)
 is the subplan with this name active More...
 
bool isActive ()
 
bool isLogOpen ()
 
virtual bool methodCall (const char *name, const char *paramOrder, char **strings, const double *doubles, double *value, UDataBase **returnStruct=NULL, int *returnStructCnt=NULL)
 
virtual bool methodCallV (const char *name, const char *paramOrder, UVariable *params[], UDataBase **returnStruct=NULL, int *returnStructCnt=NULL)
 
void remove ()
 
bool remove (const char *name)
 
bool setActive (bool doStart, bool onceOnly)
 
void setLogFile (ULogFile *logFile)
 
bool setParameters (double dpar[], int dparCnt)
 
bool setParameters (UVariable *params[], int paramsCnt)
 
bool setRule (UMisRule *plan, UMisRuleState *hasParent, ULogFile *logFile)
 
bool startStopRule (const char *planName, bool start)
 Start or stop one of the subplans for this mission Stating a started or stopping a stopped plan makes no change Stopping a started plan makes the plan execute any post-lines before inactivation Starting an rule sets also the auto-repeat flag. More...
 
bool step (int *breakLevels, const bool aLastCall)
 
void toLog (const char *logString)
 
 UMisRuleState ()
 
 ~UMisRuleState ()
 
- Public Member Functions inherited from UVarCalc
double evaluateD (const char *line, const char *start, const char **end, bool *evaluated, bool syntaxCheck)
 Get value for the variable or function call with this name Variables and functions in the local scope has first priority, then gradually one scope at a time until root scope. After that the math scope is tested. true if found. More...
 
bool evaluateParametersD (const char *sourceLine, const char **paramStart, double *paramValues, int *paramValuesCnt, char **paramStr, char *paramOrder, int maxParamCount, int maxParamStrCount, int maxParamStrLength)
 
bool evaluateParametersV (const char *sourceLine, const char **paramStart, char *paramOrder, UVariable *params[], int *paramsCnt, int maxParamsCnt)
 
bool evaluateToStringD (const char *sourceLine, const char *paramStart, const char **nextChar, char *dest, int destLength)
 
bool evaluateToStringV (const char *sourceLine, const char *paramStart, const char **nextChar, char *dest, int destLength)
 
double evaluateUnaryValD (const char *line, const char *start, const char **end, bool *evaluated, bool syntaxCheck)
 Evaluate an expression. More...
 
bool evaluateUnaryValV (const char *line, const char *start, const char **end, UVariable *value, bool syntaxCheck)
 
bool evaluateV (const char *line, const char *start, const char **end, UVariable *value, bool syntaxCheck)
 Evaluate an expression. More...
 
char * getErrorTxt ()
 
int getErrorTxtMaxCnt ()
 
bool getIdentifier (const char *id, int idCnt, const char *allowed, const char **oChar)
 
bool getValueAnyD (UVarPool *scope, const char *name, double *value, const char **params)
 Get value for the variable or function call with this name Variables and functions in the local scope has first priority, then gradually one scope at a time until root scope. After that the math scope is tested. true if found. More...
 
bool getValueAnyV (UVarPool *scope, const char *name, UVariable *value, const char **params)
 Get value for the variable or function call with this name Variables and functions in the local scope has first priority, then gradually one scope at a time until root scope. After that the math scope is tested. true if found. More...
 
bool getVariableAny (UVarPool *scope, const char *name, UVariable *value)
 Get the variable with this name in the specified scope (incl. math) Variables in the local scope has first priority, then gradually one scope at a time until root scope. After that the math scope is tested. true if found. More...
 
bool getVariableRefAny (UVarPool *scope, const char *name, UVariable **found, int *nameIndex)
 Get reference to variable with this name in the specified scope (incl. math) Variables in the local scope has first priority, then gradually one scope at a time until root scope. After that the math scope is tested. true if found. More...
 
bool isDefined (UVarPool *scope, const char *varName)
 Is this variable defined in the scope. The test is for variables and structures, and in the provided scope as well as any parent scope. further the math scope is tested too. More...
 
bool isRemark (const char *string)
 
bool setResource (UResBase *resource, bool remove)
 Called by server core when new resources are available. More...
 
 UVarCalc ()
 
virtual ~UVarCalc ()
 
- Public Member Functions inherited from UVarPool
int addMethod (UVarMethodImplement *implementor, const char *formalName, const char *paramTypes, const char *comment)
 
int addMethodV (UVarMethodImplement *implementor, const char *formalName, const char *paramTypes, const char *comment)
 
int addStruct (const char *name, UVarPool *varStruct)
 
int addStructLink (const char *name, UVarPool *toVarStruct)
 Add a link to another place in the var tree but do not change anything in the linked structure. More...
 
UVarPooladdStructLocal (const char *name, const char *note, bool copy)
 
UVariableaddVar (const char *name, const double initialValue, const char *type, const char *comment)
 
UVariableaddVar (const char *name, const double initialValue, UVariable::varType type, const char *comment, const char *attValue=NULL)
 
UVariableaddVar (const char *name, const UVariable *source, const char *comment)
 
UVariableaddVar (const char *name, const char *comment)
 
UVariableaddVarA (const char *name, const char *attValue, const char *type, const char *comment)
 
bool callGlobal (const char *name, const char *paramOrder, char **strings, const double *doubles, double *value, UDataBase **returnStruct, int *returnStructCnt)
 Call a method in the root var pool. It may be in this structure or in any sub-structure that the 'name' indicate. More...
 
bool callGlobalV (const char *name, const char *paramOrder, UVariable **params, UDataBase **returnStruct, int *returnStructCnt)
 Call a method from the root var pool scope It may be in the structure direct (no '.') or in any sub-structure that the 'name.subname' indicate. More...
 
bool callLocal (const char *name, const char *paramOrder, char **strings, const double *doubles, double *value, UDataBase **returnStruct, int *returnStructCnt)
 Call a method in this var pool. It may be in this structure or in any sub-structure that the 'name' indicate. More...
 
bool callLocalV (const char *name, const char *paramOrder, UVariable *params[], UDataBase **returnStruct, int *returnStructCnt)
 Call a method in this var pool (using UVariable parameters). It may be in this structure or in any sub-structure that the 'name' indicate. More...
 
bool callScope (const char *name, const char *paramOrder, char **strings, const double *doubles, double *value, UDataBase **returnStruct, int *returnStructCnt)
 Call a method in this scope, i.e. try if it fits a call in any of the parent var pools. It may be in the structure direct (no '.') or in any sub-structure that the 'name.subname' indicate. More...
 
bool callScopeV (const char *name, const char *paramOrder, UVariable **params, UDataBase **returnStruct, int *returnStructCnt)
 Call a method in this scope - using UVariable parameters, i.e. try if it fits a call in any of the parent var pools. It may be in the structure direct (no '.') or in any sub-structure that the 'name.subname' indicate. More...
 
bool createVarSpace (const int varCnt, const int structCnt, const int methCnt, const char *note, bool copy)
 
void deleteAll ()
 
void deleteMethod (const char *name, const char *paramStr)
 
void deleteMethods (UVarMethodImplement *owner)
 
void deleteStruct (const char *name)
 
const char * getDescription ()
 
const char * getFullPreName (char *name, const int MNL)
 
const char * getFullPreName ()
 
bool getGlobalString (const char *name, const char **value)
 
bool getGlobalValue (const char *name, double *value)
 
bool getGlobalValue (const char *name, bool *value)
 
bool getGlobalValue (const char *name, UTime *value)
 
UVariablegetGlobalVariable (const char *name, int *element=NULL)
 get pointer to variable object NB! the returned pointer may be ilegal if module that owns the variable is unloaded so it must be used only while executing one command in main server core thread, if needed in a thread - like the sequencer, then get the value only - getValue(). More...
 
UVarMethodgetLocalMethod (const char *name, const char *paramList)
 
UVarPoolgetLocalMethod (const char *name, const char *paramList, UVarMethod **method)
 
UVarMethodgetLocalMethod (const int index)
 
int getLocalMethodIdx (const char *name, const char *paramList)
 Get index of this method in this var pool. More...
 
double getLocalValue (int idx, int element=0)
 
bool getLocalValue (const char *name, double *value)
 
bool getLocalValue (const char *name, bool *value)
 
bool getLocalValue (const char *name, UTime *value)
 
UPosition getLocalValue3D (int idx)
 
UPosRot getLocalValue6D (int idx)
 
bool getLocalValueBool (int idx)
 
int getLocalValueInt (int idx)
 
UPose getLocalValuePose (int idx)
 
URotation getLocalValueRot (int idx)
 
UTime getLocalValueTime (int idx)
 
UVariablegetLocalVar (int index)
 
UVariablegetLocalVariable (const char *name, int *element)
 get pointer to variable object in this variable tree More...
 
int getLocalVarIndex (const char *name, int *element)
 
ULogFilegetLogVar ()
 
ULockgetLogVarLock ()
 
int getMethodCnt ()
 
int getMethodMax ()
 
UVarPoolgetParentVarPool ()
 
UVarPoolgetParentVarPoolScope ()
 
const char * getPreName ()
 
UVarPoolgetRootVarPool ()
 
bool getScopeValue (const char *name, double *value)
 
UVarPoolgetStruct (const char *name)
 
UVarPoolgetStruct (const int idx)
 
int getStructCnt ()
 
UVarPoolgetStructDeep (const char *fullName, char *varName, const int varNameCnt)
 
UVarPoolgetStructDeep (const char *fullName, const bool mayAdd, char *varName, const int varNameCnt)
 
int getStructIdx (const char *name)
 
int getStructMax ()
 
const char * getVarDescription (int idx)
 
int getVarMax ()
 
char * getVarName (int index)
 
UVariable ** getVars ()
 
int getVarsCnt ()
 
bool isLogfileOpen ()
 
bool isVarPoolVerbose ()
 
void listVars (const char *preStr, char *buff, const int buffCnt, bool andStructs)
 
void setDescription (const char *note, bool copy)
 
bool setGlobalVar (const char *name, const double value, bool mayAdd)
 Assigns a value to a variable. The variable may be a part of a structure. More...
 
bool setLocalVar (const int index, const double value, const int element)
 
bool setLocalVar (const int index, UVariable *value)
 
bool setLocalVar (const char *name, const double value, bool mayAdd, UVariable::varType vartyp, const char *attValue=NULL)
 Assigns a value to a variable. The variable may be a part of a structure. More...
 
bool setLocalVar (const char *name, const char *value, bool mayAdd, const char *vartyp, UTime *updTime=NULL, bool *added=NULL)
 Assigns a value to a variable. The variable may be a part of a structure. More...
 
bool setLocalVar3D (int idx, UPosition *value)
 
bool setLocalVar6D (int idx, UPosRot *value)
 
bool setLocalVarAdd (const int index, const double value, const int element)
 
bool setLocalVarPose (int idx, UPose *value)
 
bool setLocalVarRot (int idx, URotation *value)
 
void setLogfile (ULogFile *fileHandle, ULock *fileLock)
 
void setParentVarPool (UVarPool *parent)
 
void setParentVarPoolScope (UVarPool *parent)
 
bool setPreName (const char *name)
 
bool setScopeVar (const char *name, const double value, bool mayAdd)
 
bool setScopeVar (const char *name, const UVariable *source, bool mayAdd)
 
void setVerbose (bool value)
 
 UVarPool ()
 
virtual ~UVarPool ()
 
- Public Member Functions inherited from ULock
bool lock ()
 
void lockInit ()
 
void post ()
 
bool tryLock ()
 
bool tryWait ()
 
 ULock ()
 
void unlock ()
 
bool wait ()
 
 ~ULock ()
 
- Public Member Functions inherited from UServerPush
int addPushCommand (UServerInMsg *msg)
 
virtual void callGotNewDataWithObject ()
 
bool doPushCall (UServerPushElement *pe, const char *value)
 
void flushClientCmds (int clientIdx)
 
UServerPushImplementgetImplementor ()
 
int getPushCmdCnt (int *cmdCnt, int *callCnt)
 
UServerPushQueuegetPushQueue ()
 
bool gotCmdExe ()
 
void gotNewData (void *pData)
 
bool isUpdated (int lastCnt, int *newCnt)
 
bool needNewData ()
 
void print (const char *preString)
 
void print (const char *preString, char *buff, int buffCnt)
 
void servicePendingPushCmds ()
 
void setCmdExe (UServerPushImplement *executor)
 
void setImplementor (UServerPushImplement *executor)
 
bool setResource (UResBase *resource, bool remove)
 
bool setUpdated (const char *value)
 Add watch object if needed. An image or other object is updated. set object as updated, with an extra qualifier, that may be used as a parameter in a push call. this push list is then added to the to the push list examined by the server thread. when server thread reach this push list it will call to get a possible associated data structure by a call to needNewData() whish is expected to call gotNewData(void * data_structure) - but now in the server thread. More...
 
 UServerPush ()
 
virtual ~UServerPush ()
 
- Public Member Functions inherited from UVarMethodImplement
virtual ~UVarMethodImplement ()
 

Protected Member Functions

void advanceToCase ()
 
virtual void createBaseVar ()
 
bool createParameterVar (bool syntaxCheck)
 
virtual UMisRulegetSubRule (const char *name)
 
UMisRuleStategetSubRuleState (const char *name)
 
UMisItem::ResultValue initCall (bool inLine, bool extraPar, int extraParVal)
 
bool isInMain ()
 
void logActualCall (const int lineNumber, const char *funcName, const char *parOrder, char *sppar[], double dpar[])
 
void logActualCallV (const int lineNumber, const char *funcName, const char *parOrder, UVariable **params)
 
int methodWait (double secs, int repeat)
 Implement a wait control method when called first time (repeat == 0) the start time is stored. on subsequent calles (repeat > 0) then time passed is calculated in return value is set accordingly. More...
 
UMisItem::ResultValue runBreak (int *breakLevels)
 
UMisItem::ResultValue runCall (int *breakLevels, bool lastCall)
 Execute a call to a rule. More...
 
UMisItem::ResultValue runCase (int *breakLevels)
 
UMisItem::ResultValue runControl (int *breakLevels, bool lastCall)
 Execute a control call. More...
 
UMisItem::ResultValue runEnable (UMisEnable *eLine)
 
UMisItem::ResultValue runLine (bool lastCall, int *breakLevels)
 
UMisItem::ResultValue runLines (int *breakLevels, int maxStatements)
 
UMisItem::ResultValue runLoop (int *breakLevels, UMisLoop *lLine)
 
bool runMainLines (int *breakLevel, const bool lastCall)
 
bool runRuleCommands ()
 
UMisItem::ResultValue runSwitch (UMisItem *nextLine)
 
bool skipOneStatement (bool anIf)
 
- Protected Member Functions inherited from UVarCalc
virtual bool getLocalScopeVaiable (const char *name, double *value)
 
- Protected Member Functions inherited from UVarPool
bool createFunctionStack (const int maxCount)
 
bool createVarPoolStack (const int maxCount)
 
bool createVarStack (const int maxCount)
 
virtual bool evaluateSystemFunction (const char *name, const double pars[], int parsCnt, double *value, bool syntaxCheck)
 

Protected Attributes

bool automaticRestart
 
int automaticRestartCnt
 
BlockState blockState
 
UMisRuleStateerrBlock
 
int errCnt
 
int errLevel
 
UMisRuleStateinCall
 
bool inIf [inIfCntMax]
 
int inIfCnt
 
bool initialized
 is the rule initialized More...
 
ULogFilelogf
 
UMisRulemisRule
 
UMisRuleStateparent
 
int seqAgainCnt
 
UMisItemseqLine
 
UMisRuleStatesubRules [MAX_SUBPLANS]
 
int subRulesCnt
 
UVariable ** varParameters
 
UVariablevarWait
 
UTime waitStart
 
- Protected Attributes inherited from UVarCalc
char errorTxt [MAX_ERROR_SIZE]
 
- Protected Attributes inherited from UVarPool
const char * description
 
ULogFilelogVar
 
ULocklogVarLock
 
UVarPool ** varPools
 
bool * varPoolsLocal
 
bool verbose
 

Static Protected Attributes

static const int inIfCntMax = 10
 
static const int MAX_SUBPLANS = 100
 

Detailed Description

Class that holds the current execution state of a mission plan. The state has pointers to all sub-plans, that (if active) are to be executed at every new step. The state holds info of any calls to other plans, that are to be executed as part of the main part of the plan. The state also has a error report in 'errLevel' (0=OK, 1=warning (continues), 2=error (execution may be halted), and an error text in errorTxt. The class generates (or may generate) a number of local variables, and will be created on the global variable stack.

Member Enumeration Documentation

Enumerator
inactive 
init 
main 
post 

Constructor & Destructor Documentation

UMisRuleState::UMisRuleState ( )
UMisRuleState::~UMisRuleState ( )

Destructor

References subRules, subRulesCnt, and varParameters.

Member Function Documentation

bool UMisRuleState::addRule ( UMisRule plan,
bool  activate 
)

Add this plan line as new sub-plan to this sequencer state.

Parameters
planis a pointer to the plan to be added.
activate,iftrue the plan is set for automatic restart and active
Returns
true if the plan was added with no errors. else the errors are reported in errorTxt.

References UMisRule::isRule, UMisRule::isRun, logf, MAX_SUBPLANS, setActive(), setRule(), subRules, subRulesCnt, and UMisRuleState().

Referenced by getRule(), runLines(), and UResRuleState::UResRuleState().

void UMisRuleState::advanceToCase ( )
protected

Advance program counter to after the right case statement

References getRule(), UMisItem::isA(), UMisCase::isInList(), UMisItem::next, seqLine, and UMisRule::switchValue.

Referenced by isInMain(), and step().

void UMisRuleState::createBaseVar ( )
protectedvirtual
bool UMisRuleState::createParameterVar ( bool  syntaxCheck)
protected

Convert parameter line to variables.

Parameters
syntaxCheckwhen true no variables are created, just convert to names and values.
Returns
true if all values can be converted to double and all identifiers are valid.

References UVarPool::addVar(), UVarCalc::errorTxt, UVarCalc::evaluateV(), UVarCalc::getIdentifier(), USmlTagIn::getNextAttribute(), MAX_ERROR_SIZE, MAX_SML_NAME_LENGTH, MAX_VAR_NAME_SIZE, misRule, UMisRule::parameters, UMisRule::parametersCnt, USmlTagIn::setTag(), and varParameters.

Referenced by getCalled(), and setRule().

UMisRuleState* UMisRuleState::getCalled ( )
inline

Get called plan state If this plan is waiting in a called plan, get the called plan state.

Returns
state of the called, or NULL if not in a call.

References createBaseVar(), createParameterVar(), getSubRule(), getSubRuleState(), inCall, initCall(), runLine(), and runLines().

Referenced by UFuncRule::unloadRule().

UMisRuleState * UMisRuleState::getCaller ( const char *  name)

get the state structure of the first caller of the plan with this name. The caller makes the plan busy, so it is nice to know who is calling this plan.

Parameters
namethe name of the plan
Returns
a pointer to the state structure of the direct caller of the plan

References getCaller(), UMisRule::getName(), getRule(), inCall, subRules, and subRulesCnt.

Referenced by getCaller(), UResRuleState::getCaller(), UResRuleState::getIterationCnt(), and isActive().

UMisRule* UMisRuleState::getRule ( )
inline
bool UMisRuleState::getStateStr ( const char *  pre,
char *  buff,
const int  buffCnt 
)

Get a state string, with the state of all subplans.

Parameters
preis a prestring printed before all lines
buffis the character buffer where to put the data
buffCntis the length of the buff prameter
Returns
false if buffer overflows

References automaticRestartCnt, blockState, UMisRule::condition, errCnt, UMisRule::getFileName(), UMisLineItem::getLine(), UMisItem::getLineNumber(), ULogFile::getLogName(), UMisRule::getMainLines(), UMisRule::getName(), UVarPool::getPreName(), getRule(), getStateStr(), UVarPool::getStruct(), UVarPool::getStructCnt(), inactive, inCall, init, UVarPool::listVars(), logf, misRule, seqAgainCnt, seqLine, subRules, and subRulesCnt.

Referenced by getRule(), getStateStr(), and UResRuleState::UResRuleState().

UMisRule * UMisRuleState::getSubRule ( const char *  name)
protectedvirtual

Get related plan, try: 1 daughter plans, 2 parent's daughter plans (sisters), 3-N grand-parent's daughters until no more parents

Parameters
namename of the plan
Returns
a pointer to the first found plan

Reimplemented in UMisSeqRoot.

References UMisRule::getName(), getRule(), getSubRule(), parent, subRules, and subRulesCnt.

Referenced by getCalled(), UMisSeqRoot::getMissions(), getSubRule(), UMisSeqRoot::getSubRule(), and initCall().

int UMisRuleState::getSubRulesCnt ( )
inline

get number of subplans

References subRulesCnt.

UMisRuleState * UMisRuleState::getSubRuleState ( const char *  name)
protected

Get related plan state, looking in this order: 1 daughter plans, 2 parent's daughter plans (sisters), 3-N grand-parent's daughters until no more parents

Parameters
namename of the plan
Returns
a pointer to the first found plan state

References UMisRule::getName(), getRule(), getSubRuleState(), parent, subRules, and subRulesCnt.

Referenced by getCalled(), getSubRuleState(), isActive(), runEnable(), and startStopRule().

UMisItem::ResultValue UMisRuleState::initCall ( bool  inLine,
bool  extraPar,
int  extraParVal 
)
protected

Prepare a plan (a call or an in-line block) for a step.

Parameters
inLineBlockthe call is an in-line block rather than a call to a plan
extraParset true if in a control call, then the repeat count is added
extraParValis the vale added if extra parameter is needed
Returns
RV_OK if call is an available call (e.g. sin(0.56)) or RV_OK_AGAIN if call is a plan and needs a step.

References UVarPool::callScopeV(), UVarCalc::errorTxt, UVarCalc::evaluateParametersV(), UMisLineItem::getLine(), UMisItem::getLineNumber(), UMisCall::getNameCopy(), UMisCall::getParameters(), getRule(), getSubRule(), UVariable::getValued(), inCall, logActualCallV(), logf, MAX_ERROR_SIZE, MAX_STRUCT_NAMES, MAX_VAR_NAME_SIZE, UMisRule::parametersCnt, roundi(), UMisItem::RV_EMPTY, UMisItem::RV_OK, UMisItem::RV_OK_AGAIN, UMisItem::RV_SYNTAX_ERROR, seqLine, setActive(), UMisRule::setBusyCnt(), setParameters(), setRule(), UVariable::setValued(), and UMisRuleState().

Referenced by getCalled(), runCall(), and runControl().

bool UMisRuleState::isActive ( const char *  planName)

is the subplan with this name active

Parameters
planNamename of subplan.
Returns
true if the plan exist and is not inactive

References getSubRuleState(), and isActive().

Referenced by isActive().

bool UMisRuleState::isActive ( )
inline

Is the state of this plan active

Returns
true if the state is not inactive

References blockState, getCaller(), and inactive.

Referenced by UResRuleState::getIterationCnt(), and setLogFile().

bool UMisRuleState::isInMain ( )
inlineprotected

Is the state main, that is sequencer is in a control-command

Returns
true if state is main

References advanceToCase(), blockState, logActualCall(), logActualCallV(), main, methodWait(), runBreak(), runCall(), runCase(), runControl(), runEnable(), runLoop(), runMainLines(), runRuleCommands(), runSwitch(), and skipOneStatement().

Referenced by runCall(), and runControl().

bool UMisRuleState::isLogOpen ( )

Is the logfile open.

Returns
false if the logfile pointer is not set and if the logfile is closed.

References ULogFile::isLogOpen(), and logf.

Referenced by setLogFile(), and toLog().

void UMisRuleState::logActualCall ( const int  lineNumber,
const char *  funcName,
const char *  parOrder,
char *  sppar[],
double  dpar[] 
)
protected

Log the actual call to a function with all parameters evaluated

Parameters
lineNumberis the line number from source
funcNameis the name of the function (before ())
parOrderis the parameter order (only s and d are valid)
spparis an array of string parameters
dparis an array of double parameters

References logf, and ULogFile::toLog().

Referenced by isInMain().

void UMisRuleState::logActualCallV ( const int  lineNumber,
const char *  funcName,
const char *  parOrder,
UVariable **  params 
)
protected

Log the actual call to a function with all parameters evaluated

Parameters
lineNumberis the line number from source
funcNameis the name of the function (before ())
parOrderis the parameter order (only s and d are valid)
paramsis the parameter array of UVariable values

References logf, and ULogFile::toLog().

Referenced by initCall(), isInMain(), and runRuleCommands().

bool UMisRuleState::methodCall ( const char *  name,
const char *  paramOrder,
char **  strings,
const double *  doubles,
double *  value,
UDataBase **  returnStruct = NULL,
int *  returnStructCnt = NULL 
)
virtual

A varPool method with this class as implementor is called.

Parameters
nameis the name of the called function
paramOrderis a string with one char for each parameter in the call - d is double, s is string, c is class object.
stringsis an array of string pointers for the string type parameters (may be NULL if not used)
doublesis an array with double typed parameters (may be NULL if not used)
valueis the (direct) result of the class, either a double value, or 0.0 for false 1.0 for true (2.0 for implicit stop if a controll call from mission sequencer).
returnStructis an array of class object pointers that can be used as parameters or return objects (may be NULL)
returnStructCntis the number of objects in the returnStruct buffer
Returns
true if the method is recognised (exists), when false is returned a invalid name or parameter list is detected.

Reimplemented from UVarMethodImplement.

References UMisRule::condition, UVarCalc::evaluateV(), UVariable::getBool(), UVariable::getValued(), UVariable::isDouble(), methodWait(), misRule, and roundi().

Referenced by getRule().

bool UMisRuleState::methodCallV ( const char *  name,
const char *  paramOrder,
UVariable params[],
UDataBase **  returnStruct = NULL,
int *  returnStructCnt = NULL 
)
virtual

A varPool method with this class as implementor is called.

Parameters
nameis the name of the called function
paramOrderis a string with one char for each parameter in the call - d is double, s is string, c is class object.
paramsis an array of variable pointers with the actual parameters, in the order specified by order
returnStructis an array of class object pointers that can return values or objects (may be NULL) if no result value is needed (a procedure call)
returnStructCntis the number of objects in the returnStruct buffer
Returns
true if the method is recognised (exists), when false is returned a invalid name or parameter list is detected.

Reimplemented from UVarMethodImplement.

References UVariable::copy(), UVarCalc::evaluateV(), UMisRule::getName(), UVariable::getValued(), UVariable::isDouble(), misRule, UVariable::setValued(), and UVariable::setValues().

Referenced by getRule(), and UResRuleState::UResRuleState().

int UMisRuleState::methodWait ( double  secs,
int  repeat 
)
protected

Implement a wait control method when called first time (repeat == 0) the start time is stored. on subsequent calles (repeat > 0) then time passed is calculated in return value is set accordingly.

Parameters
secs,thentime to wait (may change from call to call)
repeatcount - assumed to be incremented for each wait call
Returns
1 if time has not passed and 2 if the time has passed

References UTime::getTimePassed(), UTime::now(), UVariable::setValued(), varWait, and waitStart.

Referenced by isInMain(), and methodCall().

void UMisRuleState::remove ( )

Remove all state info and all state variables related to this mission state

References blockState, UVarPool::deleteStruct(), errBlock, errLevel, UMisRule::getName(), getRule(), inactive, inCall, misRule, remove(), seqAgainCnt, seqLine, UMisRule::setBusyCnt(), step(), subRules, and subRulesCnt.

Referenced by remove(), runCall(), and runControl().

bool UMisRuleState::remove ( const char *  name)

Remove this named subplan from the state structure (and all its sub-structures)

Parameters
nameis the plan name to be removed from the statate structure
Returns
true if plan is found and removed.

References UVarPool::deleteStruct(), UMisRule::getName(), getRule(), remove(), subRules, and subRulesCnt.

UMisItem::ResultValue UMisRuleState::runBreak ( int *  breakLevels)
protected

Execute a break This is done by finding the level of wich to break. If level is undefined, then default is 1 level, i.e. break current plock If level is a number, then this number determines the break level (0 is no break) if level is a plan (or block) identifier, then the levels to this block is used.

Parameters
breakLevelsis set after the call to the number of levels to break.
Returns
RV_OK if no syntax error is found.

References errCnt, UVarCalc::errorTxt, UMisItem::getLineNumber(), UMisRule::getName(), UMisBreak::getParam(), UMisBreak::getParamCopy(), UMisRule::isFull, UMisItem::isRem(), UMisRule::isSwitch, UMisRule::isTop, MAX_ERROR_SIZE, MAX_VAR_NAME_SIZE, misRule, parent, UMisItem::RV_OK, UMisItem::RV_SYNTAX_ERROR, and seqLine.

Referenced by isInMain(), and runLine().

UMisItem::ResultValue UMisRuleState::runCall ( int *  breakLevels,
bool  lastCall 
)
protected

Execute a call to a rule.

Parameters
breakLevelshould return the number of levels to break, and left unchanged if no break levels were executed.
lastCallif set to true, then a control statement is terminated and any post code run
Returns
RV_OK if completed or RV_AGAIN if stuck in a control statement, the control statement is the (or in) the statement in loopLine. May also return RV_SYNTAX_ERROR

References UVarPool::deleteStruct(), UMisRule::getName(), getRule(), inCall, initCall(), UMisItem::isA(), isInMain(), remove(), UMisItem::RV_OK, UMisItem::RV_OK_AGAIN, seqAgainCnt, seqLine, UMisRule::setBusyCnt(), and step().

Referenced by isInMain(), and runLine().

UMisItem::ResultValue UMisRuleState::runCase ( int *  breakLevels)
protected

A case statement is found terminating the statements in a case construction

Parameters
breakLevelsis set to 1 on exit
Returns
RV_OK

References UMisItem::RV_OK.

Referenced by isInMain(), and runLine().

UMisItem::ResultValue UMisRuleState::runControl ( int *  breakLevels,
bool  lastCall 
)
protected

Execute a control call.

Parameters
breakLevelshould return the number of levels to break, and left unchanged if no break levels were executed.
lastCallif set to true, then a control statement is terminated and any post code run
Returns
RV_OK if completed or RV_AGAIN if stuck in a control statement, the control statement is the (or in) the statement in loopLine. May also return RV_SYNTAX_ERROR

References UVarPool::deleteStruct(), errCnt, UMisControl::evaluateCondition(), UMisControl::getCondition(), UMisItem::getLineNumber(), UMisRule::getName(), getRule(), inCall, initCall(), UMisCall::isA(), isInMain(), logf, remove(), UMisItem::RV_FAILED, UMisItem::RV_OK, UMisItem::RV_OK_AGAIN, UMisItem::RV_OK_FALSE, seqAgainCnt, seqLine, UMisRule::setBusyCnt(), step(), and ULogFile::toLog().

Referenced by isInMain(), and runLine().

UMisItem::ResultValue UMisRuleState::runEnable ( UMisEnable eLine)
protected

Enable the plan state with this name, if it is within scope. Scope is current plans subplans and any direct parent's subplan.

Parameters
planNamethe name of the plan
valueis true when the plan should be enables and false if to be disabled.
Returns
true if a plan of that name is found

References UVarCalc::errorTxt, UVarCalc::evaluateToStringV(), UMisLineItem::getLine(), UMisEnable::getParam(), UMisEnable::getParamCopy(), getRule(), getSubRuleState(), UMisEnable::isEnable(), UMisRule::isRule, MAX_ERROR_SIZE, MAX_VAR_NAME_SIZE, UMisItem::RV_OK, UMisItem::RV_SYNTAX_ERROR, and setActive().

Referenced by isInMain(), and runLine().

UMisItem::ResultValue UMisRuleState::runLine ( bool  lastCall,
int *  breakLevels 
)
protected

Execute the line in seqLine.

Parameters
lastCallis used if the line is a control statement, where a last call must be executed when leaving the statement.
breakLevelsis the result of a break level
Returns
ar result value normally RV_OK_DONE or RV_OK_AGAIN if in a control statement

References blockState, UMisItem::execute(), UMisLineItem::getDataType(), UVarPool::getFullPreName(), UMisLineItem::getLine(), UMisItem::getLineNumber(), UMisItem::isA(), logf, UMisItem::next, runBreak(), runCall(), runCase(), runControl(), runEnable(), runLoop(), runSwitch(), seqLine, and ULogFile::toLog().

Referenced by getCalled(), runLines(), and runMainLines().

UMisItem::ResultValue UMisRuleState::runLines ( int *  breakLevels,
int  maxStatements 
)
protected

run lines starting at seqLine

Parameters
breakLevels[out] set to number of levels to break if a break statement is reached.
maxStatementsis -1 of no limit, else max number of statements, used by loops to allow just one statement.
Returns
RV_OK ot RV_AGAIN if no errors are found else RV_SYNTAX_ERROR and the errors are reported in errorTxt.

References addRule(), blockState, errCnt, errLevel, UVarCalc::errorTxt, UVarPool::getFullPreName(), UMisItem::getLineNumber(), inIf, inIfCnt, inIfCntMax, init, UMisItem::isA(), logf, UMisItem::next, runLine(), UMisItem::RV_IF_FALSE, UMisItem::RV_IF_TRUE, UMisItem::RV_OK, UMisItem::RV_OK_AGAIN, UMisItem::RV_SYNTAX_ERROR, seqAgainCnt, seqLine, skipOneStatement(), and ULogFile::toLog().

Referenced by getCalled(), runLoop(), runMainLines(), and step().

UMisItem::ResultValue UMisRuleState::runLoop ( int *  breakLevels,
UMisLoop lLine 
)
protected

Run this loop statement.

Parameters
lLineis the loop definition line
breakLevelsset to 1..N if a break line is found
Returns
RV_OK if completed or RV_AGAIN if stuck in a control statement, the control statement is the (or in) the statement in loopLine. May also return RV_SYNTAX_ERROR

References UMisLoop::evalCondition(), UMisItem::isA(), UMisLoop::loopLine, UMisItem::next, UMisLoop::runInitAssignment(), runLines(), UMisLoop::runLoopAssignment(), UMisItem::RV_OK, UMisItem::RV_OK_AGAIN, UMisItem::RV_SYNTAX_ERROR, seqAgainCnt, and seqLine.

Referenced by isInMain(), and runLine().

bool UMisRuleState::runMainLines ( int *  breakLevel,
const bool  lastCall 
)
protected

Run the main part of the plan starting at the line in seqLine.

Parameters
breakLevelshould return the number of levels to break, and left unchanged if no break levels were executed.
lastCallwhen true, the lines should be get the final call, as needed before the post lines.
Returns
true if no syntax error were detected (in main lines)

References blockState, getRule(), UMisItem::isA(), UMisRule::isFull, misRule, UMisRule::order, ULock::post(), runLine(), runLines(), UMisItem::RV_OK, UMisItem::RV_OK_AGAIN, UMisItem::RV_SYNTAX_ERROR, seqLine, step(), subRules, and subRulesCnt.

Referenced by isInMain(), and step().

bool UMisRuleState::runRuleCommands ( )
protected

Run main lines in a plan with just command parameters

Returns
true if all lines could be fitted as parameter to the call

References UVarPool::callScopeV(), UMisRule::destination, errCnt, UVarCalc::evaluateParametersV(), UMisLineItem::getLine(), UMisItem::getLineNumber(), UVarCalc::isRemark(), logActualCallV(), logf, misRule, UMisItem::next, seqLine, and ULogFile::toLog().

Referenced by isInMain(), and step().

UMisItem::ResultValue UMisRuleState::runSwitch ( UMisItem nextLine)
protected

Run a switch statement, evaluation the switch value and setting the value in the next block structure

References UVarCalc::errorTxt, UMisCaseSwitch::evaluateExpr(), UMisItem::getDataType(), UMisItem::isA(), UMisRule::isSwitch, MAX_ERROR_SIZE, UMisItem::next, UMisItem::RV_OK, UMisItem::RV_SYNTAX_ERROR, seqLine, and UMisRule::switchValue.

Referenced by isInMain(), and runLine().

bool UMisRuleState::setActive ( bool  doStart,
bool  onceOnly 
)

Activate or inactivate this plan. if set active (doStart=true) and is active already, then state is not changed if doStart=false and is active, then run post conde and set to inactive

Parameters
doStartsets the state to init if true, else set the state to inavtive.
onceOnlyactivate the plan once only, i.e. no automatic repeat.
Returns
true

References automaticRestart, automaticRestartCnt, blockState, inactive, init, main, and step().

Referenced by addRule(), getRule(), initCall(), runEnable(), and startStopRule().

void UMisRuleState::setLogFile ( ULogFile logFile)
inline

Set logfile

References isActive(), isLogOpen(), logf, startStopRule(), and toLog().

bool UMisRuleState::setParameters ( double  dpar[],
int  dparCnt 
)

Set the value of the actual parameters.

Parameters
dparis an array of doubles with the new value for the parameters
dparCntis the number of valid parameters.
Returns
true if all parameters were set.

References errCnt, UMisRule::getName(), misRule, UMisRule::parametersCnt, UVariable::setValued(), and varParameters.

Referenced by getRule(), and initCall().

bool UMisRuleState::setParameters ( UVariable params[],
int  paramsCnt 
)

Set the value of the actual parameters.

Parameters
paramsis an array of UVariable with the new value for the parameters
paramsCntis the number of valid parameters.
Returns
true if all parameters were set.

References errCnt, UMisRule::getName(), misRule, UMisRule::parametersCnt, UVariable::setValue(), and varParameters.

bool UMisRuleState::setRule ( UMisRule plan,
UMisRuleState hasParent,
ULogFile logFile 
)

Set this plan state to the plan described in this plan structure.

Parameters
planplan to prepare state for.
hasParentis the pointer to the parent plan - or NULL if this is the root plan.
logFileis a pointer to a logfile where sufficient information is to be saved to allow replay
Returns
true if successfull

References UVarPool::addStruct(), blockState, createParameterVar(), UVarPool::createVarSpace(), errLevel, UMisRule::getName(), UVarPool::getParentVarPool(), inactive, inCall, init, logf, misRule, UMisRule::parameters, parent, UVarPool::setParentVarPool(), and UVarPool::setPreName().

Referenced by addRule(), and initCall().

bool UMisRuleState::skipOneStatement ( bool  anIf)
protected

Skip a statement after an if or an else statement

Parameters
anIfis true if it was just after an 'if' statement
Returns
true if skipped as requested.

References errCnt, errLevel, UMisItem::getLineNumber(), UMisItem::isA(), logf, UMisItem::next, UMisItem::RV_SYNTAX_ERROR, seqLine, and ULogFile::toLog().

Referenced by isInMain(), and runLines().

bool UMisRuleState::startStopRule ( const char *  planName,
bool  start 
)

Start or stop one of the subplans for this mission Stating a started or stopping a stopped plan makes no change Stopping a started plan makes the plan execute any post-lines before inactivation Starting an rule sets also the auto-repeat flag.

Parameters
planNameis the plan name to be manipulated
startdetermines wheather the plan is to be activated or deactivated

References getRule(), getSubRuleState(), and setActive().

Referenced by UResRuleState::getIterationCnt(), and setLogFile().

bool UMisRuleState::step ( int *  breakLevels,
const bool  aLastCall 
)

Execute a step in this plan. This means allow all active subplans to step first, then make a step of the main function of this plan.

Parameters
breakLevelsthe levels og plans that are to be removed, i.e. if breakLevels returns 1 when this level is completed, that is all postLines are executed and all postLines of subRules are executed too.
aLastCallwhen true, this is the last call to this plan, and the plan should do a last call and run the post-lines.
Returns
true if the step did not meet an execution error

References absf(), advanceToCase(), automaticRestart, automaticRestartCnt, blockState, UMisRule::condition, UMisRule::destination, errCnt, UVarCalc::errorTxt, UVarCalc::evaluateV(), UMisRule::getIniLines(), UMisItem::getLineNumber(), UMisRule::getMainLines(), UMisRule::getPostLines(), UVariable::getValued(), inactive, init, initialized, UMisRule::isFull, UMisRule::isSwitch, logf, main, misRule, ULock::post(), runLines(), runMainLines(), runRuleCommands(), UMisItem::RV_SYNTAX_ERROR, seqAgainCnt, seqLine, and ULogFile::toLog().

Referenced by UMisSeqRoot::getMissions(), remove(), runCall(), runControl(), runMainLines(), setActive(), and UMisSeqRoot::step().

void UMisRuleState::toLog ( const char *  logString)

Send a string to the logfile This function can tolerate that the logfile pointer is not set and the logfile is not open.

References isLogOpen(), logf, and ULogFile::toLog().

Referenced by UResRuleState::addRule(), UResRuleState::removeRule(), UResRuleState::seqIterateStep(), and setLogFile().

Member Data Documentation

bool UMisRuleState::automaticRestart
protected

Set to automatic restart. Automatic restart is enabled as a separate thing to do 'all the time' This will reset the state to 'init' after the 'post' is finished, otherwise the state will change to 'inactive' after 'post' is finished

Referenced by setActive(), step(), and UMisRuleState().

int UMisRuleState::automaticRestartCnt
protected

Cycle counter for this automatic restart plan

Referenced by getStateStr(), setActive(), step(), and UMisRuleState().

BlockState UMisRuleState::blockState
protected
UMisRuleState* UMisRuleState::errBlock
protected

The block where an error is reported - NULL if no error

Referenced by remove(), and UMisRuleState().

int UMisRuleState::errCnt
protected

Error count, to suppress excessive printout and log

Referenced by getStateStr(), runBreak(), runControl(), runLines(), runRuleCommands(), setParameters(), skipOneStatement(), step(), and UMisRuleState().

int UMisRuleState::errLevel
protected

the error level - 0 is no error, 1 is warning, 2 is error

Referenced by remove(), runLines(), setRule(), skipOneStatement(), and UMisRuleState().

UMisRuleState* UMisRuleState::inCall
protected

When next line is in a (nested) call, then the called function is block in its own right and the state of this block is at the end of this pointer. Ef not in a call, then this pointer is NULL

Referenced by getCalled(), getCaller(), getStateStr(), initCall(), remove(), runCall(), runControl(), setRule(), and UMisRuleState().

bool UMisRuleState::inIf[inIfCntMax]
protected

Result of last if evaluation

Referenced by runLines().

int UMisRuleState::inIfCnt
protected

nesting level of if statements

Referenced by runLines(), and UMisRuleState().

const int UMisRuleState::inIfCntMax = 10
staticprotected

Maximum number of nested if statements

Referenced by runLines().

bool UMisRuleState::initialized
protected

is the rule initialized

Referenced by step(), and UMisRuleState().

ULogFile* UMisRuleState::logf
protected
const int UMisRuleState::MAX_SUBPLANS = 100
staticprotected

max number of subplans allown in any plan

Referenced by addRule().

UMisRule* UMisRuleState::misRule
protected
UMisRuleState* UMisRuleState::parent
protected

parent block that called this plan

Referenced by getSubRule(), getSubRuleState(), runBreak(), setRule(), and UMisRuleState().

int UMisRuleState::seqAgainCnt
protected

Counter of the number of times a process line is called

Referenced by getStateStr(), remove(), runCall(), runControl(), runLines(), runLoop(), step(), and UMisRuleState().

UMisItem* UMisRuleState::seqLine
protected
UMisRuleState* UMisRuleState::subRules[MAX_SUBPLANS]
protected
int UMisRuleState::subRulesCnt
protected
UVariable** UMisRuleState::varParameters
protected

index to parameter variables - the count is in misRule->parametersCnt

Referenced by createParameterVar(), setParameters(), UMisRuleState(), and ~UMisRuleState().

UVariable* UMisRuleState::varWait
protected

Index to remaining wait time

Referenced by createBaseVar(), and methodWait().

UTime UMisRuleState::waitStart
protected

start time for wait method

Referenced by methodWait().


The documentation for this class was generated from the following files: