AURobotServers  4
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
UResRuleState Class Reference

#include <uresrulestate.h>

Inheritance diagram for UResRuleState:
Inheritance graph

Public Member Functions

bool addMathMethods ()
 
bool addRule (UMisRule *plan)
 
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...
 
int getIterationCnt ()
 
int getRulesCnt ()
 
bool getStateStr (const char *pre, char *buff, const int buffCnt)
 
bool isActive (const char *planName)
 Is this (top-level) plan active or not Tests the state flag, and return true if not inactive. More...
 
bool isStepping ()
 
bool isStopped ()
 
virtual bool methodCallV (const char *name, const char *paramOrder, UVariable *params[], UDataBase **returnStruct=NULL, int *returnStructCnt=NULL)
 
virtual const char * print (const char *preString, char *buff, int buffCnt)
 
bool removeRule (const char *name)
 
void run ()
 
void sendToClientAsHelp (const int client, const char *helpTxt)
 
bool seqIterateStep ()
 
void setPrintClientNumber (int client)
 
virtual bool setResource (UResBase *resource, bool remove)
 
void setSteps (int value)
 
bool startStopRule (const char *planName, bool start)
 Start or stop a plan. Rule is set active or inactive acording to 'start' value. If stopping a plan that is started, then the post part of the plan is executed before inactivation If the plan is a rule (has if="" part) then the plan is started with automatic repeat. More...
 
 UResRuleState ()
 
virtual ~UResRuleState ()
 
- Public Member Functions inherited from UResVarPool
int addMethod (const char *formalName, const char *paramTypes, const char *comment)
 
int addMethodV (const char *formalName, const char *paramTypes, const char *comment)
 
UVarPooladdStruct (const char *name, const char *comment, bool copy=false)
 
UVariableaddVar (const char *name, const double initialValue, const char *type, const char *comment)
 
UVariableaddVar (const char *name, const char *initialValue, const char *type, const char *comment)
 
UVariableaddVarA (const char *name, const char *initialValue, 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)
 
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)
 
bool callVS (const char *function, const char *stringParam)
 
int callVSCD (const char *function, const char *strPar, UDataBase *data, int cooSys)
 
void createBaseVar ()
 
virtual bool createVarSpace (const int varCnt, const int structCnt, const int methCnt, const char *note, bool copy=false)
 
bool getGlobalString (const char *name, const char **value)
 
bool getGlobalValue (const char *name, double *value)
 
bool getGlobalValue (const char *name, const char **value)
 
bool getGlobalValue (const char *name, bool *value)
 
bool getGlobalValue (const char *name, UTime *value)
 
bool getLocalValue (const char *name, double *value)
 get a value in this variable tree More...
 
bool getLocalValue (const char *name, bool *value)
 
bool getLocalValue (const char *name, UTime *value)
 
double getLocalValue (int idx)
 
UPosition getLocalValue3D (int idx)
 
UPosRot getLocalValue6D (int idx)
 
bool getLocalValueBool (int idx)
 
int getLocalValueInt (int idx)
 
UTime getLocalValueTime (int idx)
 
const char * getLogFileName ()
 
const char * getVarDescription (int idx)
 
UVarCalcgetVarPool ()
 
virtual bool gotAllResources (char *missingThese, int missingTheseCnt)
 
bool isLogFileOpen ()
 
bool isLogFileOpen (const char *structName)
 
bool isVarPoolUpdated (int lastCnt, int *newCnt)
 
void logFileClose ()
 
bool logFileOpen ()
 
void logFileStart (const char *structName, bool open)
 
virtual bool methodCall (const char *name, const char *paramOrder, char **strings, const double *doubles, double *value, UDataBase **returnStruct=NULL, int *returnStructCnt=NULL)
 
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 (int idx, double value, const int element)
 
bool setLocalVar (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 setLocalVar3D (int idx, UPosition *value)
 
bool setLocalVar6D (int idx, UPosRot *value)
 
bool setLocalVarAdd (int idx, double value, const int element)
 
bool setLocalVarPose (int idx, UPose *value)
 
void setVarPool (UVarCalc *sharedVarPool)
 
int updateQTvars (int structIdx)
 
 UResVarPool ()
 
virtual ~UResVarPool ()
 
- Public Member Functions inherited from UResBase
void createReplayVar (UVarPool *pool)
 
virtual void createResources ()
 
UCmdExegetCorePointer ()
 
char * getLogFileName (char *fn, const int fnCnt)
 
int getResFuncIdx ()
 
const char * getResID ()
 
int getResVersion ()
 
bool isA (const char *idStr)
 
bool isAlsoA (const char *id)
 
virtual void print (const char *preString)
 
virtual void saveSettings ()
 
void setCorePointer (UCmdExe *serverCore)
 
void setResFuncIdx (int idx)
 
virtual void setResID (const char *id, const int version)
 
virtual void updateReplayStatus ()
 
 UResBase ()
 
virtual ~UResBase ()
 
- Public Member Functions inherited from UReplay
void addChild (UReplay *child)
 
virtual bool decodeReplayLine (char *)
 
char * getLogFileName (char *fn, const int fnCnt)
 
char * getReplayFileName (char *fn, const int fnCnt)
 
int getReplayLogLine ()
 
bool isReplay ()
 
bool isReplayFileOpen ()
 
void removeChild (UReplay *child)
 
virtual void replayAdvanceTime (UTime untilTime)
 
void replaySetBaseFileName (const char *name, const char *preName="")
 
void replaySetFileName (const char *name)
 
virtual bool replayStep ()
 
int replayStep (int steps)
 
virtual bool replayToTime (UTime untilTime)
 
void setParent (UReplay *parent)
 
bool setReplay (bool value)
 
 UReplay ()
 
virtual ~UReplay ()
 
- 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 UVarMethodImplement
virtual ~UVarMethodImplement ()
 
- Public Member Functions inherited from ULogFile
void closeLog ()
 
void doFlush ()
 
FILE * getF ()
 
const char * getLogFileName ()
 
const char * getLogName ()
 
bool isLogOpen ()
 
bool isOpen ()
 
void logLock ()
 
bool logRename (const char *name)
 
void logUnlock ()
 
bool openLog ()
 
bool openLog (bool doOpen)
 
bool openLog (const char *resName)
 
void setLogFlush (bool doFlush)
 
void setLogName (const char *resName, const char *ext="log")
 
void setLogNameNumber (int number)
 add a number to the logfile name, That is if the logName is 'svs' and number is 2 (and logPath is '/rhome/demo'), then logfilename is set to '/rhome/demo/svs_2.log'. The purpose is to have an alternative, if the file renaming fails (if the file system is locked or something). More...
 
void setLogTime (UTime timestamp)
 
void toLog (const char *logString)
 
void toLog (const char *s1, const char *s2)
 
void toLog (const int num, const char *s1, const char *s2)
 
void toLog (const char *s1, const int num, const char *s2)
 
void toLog (const char *s1, const int n1, const int n2, const char *s2)
 
void toLog (const char *s1, const int num, const char *s2, const char *s3)
 
void toLog (const char *s1, const int n1, const int n2, const char *s2, const char *s3)
 
 ULogFile ()
 
void useLogTime (bool value)
 
 ~ULogFile ()
 

Protected Member Functions

void createBaseVar ()
 
bool start ()
 
virtual void stop (bool andWait)
 
- Protected Member Functions inherited from UResVarPool
void setDescription (const char *note, bool copy=false)
 
- Protected Member Functions inherited from UResBase
UResBasegetStaticResource (const char *resName, bool mayCreate, bool staticOnly=true)
 get a pointer to a static resource. More...
 
- Protected 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 ()
 
- Protected Member Functions inherited from ULogFile
void closeLog ()
 
void doFlush ()
 
FILE * getF ()
 
const char * getLogFileName ()
 
const char * getLogName ()
 
bool isLogOpen ()
 
bool isOpen ()
 
void logLock ()
 
bool logRename (const char *name)
 
void logUnlock ()
 
bool openLog ()
 
bool openLog (bool doOpen)
 
bool openLog (const char *resName)
 
void setLogFlush (bool doFlush)
 
void setLogName (const char *resName, const char *ext="log")
 
void setLogNameNumber (int number)
 add a number to the logfile name, That is if the logName is 'svs' and number is 2 (and logPath is '/rhome/demo'), then logfilename is set to '/rhome/demo/svs_2.log'. The purpose is to have an alternative, if the file renaming fails (if the file system is locked or something). More...
 
void setLogTime (UTime timestamp)
 
void toLog (const char *logString)
 
void toLog (const char *s1, const char *s2)
 
void toLog (const int num, const char *s1, const char *s2)
 
void toLog (const char *s1, const int num, const char *s2)
 
void toLog (const char *s1, const int n1, const int n2, const char *s2)
 
void toLog (const char *s1, const int num, const char *s2, const char *s3)
 
void toLog (const char *s1, const int n1, const int n2, const char *s2, const char *s3)
 
 ULogFile ()
 
void useLogTime (bool value)
 
 ~ULogFile ()
 

Protected Attributes

UTime loopStartTime
 
int printClientNumber
 
UMisRule rootRule
 
bool running
 
UMisSeqRoot state
 
int stepsRemaining
 
bool terminate
 
pthread_t thSeq
 
UVariablevarIterations
 
UVariablevarMissionTime
 
UVariablevarSampleTime
 
UVariablevarStartTime
 
UVariablevarStepsLeft
 
- Protected Attributes inherited from UResBase
int resFuncIdx
 
char resID [MAX_RESOURCE_ID_LENGTH]
 
char resIsAlso [MAX_RESOURCE_ISALSO_LENGTH]
 
int resVersion
 
- Protected Attributes inherited from UReplay
bool replay
 
FILE * replayFile
 
char replayFileName [REPLAY_FILE_NAME_LENGTH]
 replay filename More...
 
char replayLine [MAX_LOG_LINE_LENGTH]
 
int replayLogLine
 
UReplayreplayParent
 
UTime replayTimeNext
 
- Protected Attributes inherited from ULogFile
int failCnt
 
FILE * logFile
 
ULock logFileLock
 
char logFileName [MAX_FILENAME_SIZE]
 
bool logFlush
 
char logName [MAX_FILENAME_SIZE]
 
UTime logTime
 
bool logTimeUse
 

Additional Inherited Members

- Static Public Member Functions inherited from UResVarPool
static const char * getResClassID ()
 
- Public Attributes inherited from UReplay
bool replayTimeAdvancePending
 
UTime replayTimeNow
 
- Static Protected Attributes inherited from UReplay
static const int MAX_LOG_LINE_LENGTH = 10000
 
static const int REPLAY_FILE_NAME_LENGTH = 264
 max length of replay filename More...
 

Detailed Description

This is the shared resource class. It must enherit from the resource base class (or one of its decendent) as shown.

Author
Christian Andersen

Constructor & Destructor Documentation

UResRuleState::UResRuleState ( )
inline
UResRuleState::~UResRuleState ( )
virtual

Destructor

Member Function Documentation

bool UResRuleState::addMathMethods ( )

Add the standard math methods - if they are not there already - and set the implementation object to this resource.

Returns
true if the methods are added or existed already

References UVarPool::addMethodV(), UVarPool::addStructLocal(), UVarPool::addVar(), UVarPool::getRootVarPool(), and UVarPool::getStruct().

bool UResRuleState::addRule ( UMisRule plan)

Add this plan as a plan that is ready to be executed If a plan is set already, this plan is terminated and removed.

Parameters
planis a pointer to the plan to be set.

References UMisRule::getName(), and UMisRuleState::toLog().

Referenced by UFuncRule::editRule(), and UFuncRule::loadRuleFile().

void UResRuleState::createBaseVar ( )
protected

Create the smrif related variables

References UVarPool::addMethodV(), and UResVarPool::addVar().

UMisRuleState * UResRuleState::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 UMisRuleState::getCaller().

Referenced by UFuncRule::unloadRule().

int UResRuleState::getIterationCnt ( )
inline
int UResRuleState::getRulesCnt ( )

Get number of plans loaded for execution

Referenced by UFuncRule::runStep().

bool UResRuleState::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

Referenced by UFuncRule::listState(), and UFuncRule::sendStateMessage().

bool UResRuleState::isActive ( const char *  planName)

Is this (top-level) plan active or not Tests the state flag, and return true if not inactive.

Parameters
planNamename of one of the sub-plans
Returns
true if plan exist and state is not inactive

Referenced by UFuncRule::listAllMissions().

bool UResRuleState::isStepping ( )

Is the sequencer in stepping mode.

Returns
true if not in continuous mode
bool UResRuleState::isStopped ( )

Is the sequencer in stepping mode and all steps finished (paused)

Returns
true if no steps left (and execution not resumed)

Referenced by UFuncRule::handleRuleSet().

bool UResRuleState::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 UPose::clear(), UVariable::copy(), U2Dlined::distanceSigned(), UTime::getDecSec(), UVariable::getDouble(), UVariable::getElementCnt(), UPose::getMapToPosePose(), UVariable::getPose(), UPose::getPoseToMapPose(), UVariable::getValued(), UPose::h, UVariable::isDouble(), UVariable::isString(), limitToPi(), maxd(), mind(), UTime::now(), UVariable::pose, UPose::set(), UVariable::setName(), U2Dlined::setPH(), UVariable::setPose(), U2Dlined::setPV(), UVariable::setType(), UVariable::setValue(), UVariable::setValued(), sqr(), UPose::x, and UPose::y.

const char * UResRuleState::print ( const char *  preString,
char *  buff,
int  buffCnt 
)
virtual

print status to a string buffer

Reimplemented from UResVarPool.

bool UResRuleState::removeRule ( const char *  name)

Remove the plan with this name and delete all sub state structures and variables

Parameters
nameof the plan to be removed
Returns
true if plan is found (and removed)

References UMisRuleState::toLog().

Referenced by UFuncRule::editRule(), and UFuncRule::unloadRule().

void UResRuleState::run ( )

Sequencer run loop - must be public, as it is called from external C-function

References UServerPush::addPushCommand(), UServerInMsg::setMessage(), UServerPush::setUpdated(), and Wait().

Referenced by startMisSeq().

void UResRuleState::sendToClientAsHelp ( const int  client,
const char *  helpTxt 
)

Send this sequencer text to this client

Parameters
clientis the socket connected client (or fake client)
helpTxtis the text to be send.

References UCmdExe::sendMsg().

bool UResRuleState::seqIterateStep ( )

Make one sequencer iteration - usually called after a sequencer time event

References UMisRuleState::toLog().

Referenced by UFuncRule::handleRuleSet().

void UResRuleState::setPrintClientNumber ( int  client)
inline

Set reply client number. This is used when the sequencer has a message to the used, e.g. a print or a syntax error.

Parameters
clientthe client number - index to the clients socket connection.

Referenced by UFuncRule::handleRuleSet().

bool UResRuleState::setResource ( UResBase resource,
bool  remove 
)
virtual

Called by the server core, when a new resource is available (or is removed), local pointers to the resource should be updated as appropriate.

Reimplemented from UResVarPool.

References UResVarPool::getResClassID(), UResBase::isA(), UResVarPool::setResource(), and UServerPush::setResource().

void UResRuleState::setSteps ( int  value)

Set number of iteration steps to run

Referenced by UFuncRule::runStep().

bool UResRuleState::start ( )
protected

Start sequencer run loop

References startMisSeq().

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

Start or stop a plan. Rule is set active or inactive acording to 'start' value. If stopping a plan that is started, then the post part of the plan is executed before inactivation If the plan is a rule (has if="" part) then the plan is started with automatic repeat.

Referenced by UFuncRule::startStopRule().

void UResRuleState::stop ( bool  andWait)
protectedvirtual

Stop sequencer run loop

Reimplemented from UResBase.

References Wait().

Member Data Documentation

UTime UResRuleState::loopStartTime
protected

Starttime of last loop

int UResRuleState::printClientNumber
protected

client number of the connection who should get then print calls.

UMisRule UResRuleState::rootRule
protected

The (empty) root plan, that just allows loaded subplans to be run

bool UResRuleState::running
protected

Is the thread running

UMisSeqRoot UResRuleState::state
protected

line parsed currently

int UResRuleState::stepsRemaining
protected

Number of steps to be executed -1 is continue, 0 is no steps

bool UResRuleState::terminate
protected

terminate control loop. Should be false at all times, except at shutdown.

pthread_t UResRuleState::thSeq
protected

Thread handle for loop-thread

UVariable* UResRuleState::varIterations
protected

index to sequence iteration counter

UVariable* UResRuleState::varMissionTime
protected

index to time into mission

UVariable* UResRuleState::varSampleTime
protected

index to sample time for sequencer

UVariable* UResRuleState::varStartTime
protected

index to mission start time

UVariable* UResRuleState::varStepsLeft
protected

if stepping, this is the number of steps remaining


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