AURobotServers  4
Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes | List of all members
UCmdExe Class Reference

#include <ucmdexe.h>

Inheritance diagram for UCmdExe:
Inheritance graph

Public Member Functions

bool addFunction (UFunctionBase *function)
 
bool addNewRessources (UFunctionBase *function)
 
bool addResource (UResBase *res, UFunctionBase *owner)
 
void closeClient (int clientIdx)
 
void createBaseVar ()
 
bool deleteFunction (UFunctionBase *function)
 
bool doBashCmd (UServerInMsg *msg, const char *cmdStr)
 execute a command line command and return reply as help text. More...
 
bool executeFunction (int functionIndex, UServerInMsg *msg, void *extra, bool aPush)
 
bool executePushFunction (int functionIndex, UServerInMsg *msg, void *extra)
 
bool executeScriptFile (const char *cfn, bool andWait, int forClient)
 
int findFunctionIndex (UFunctionBase *function)
 
int findFunctionOwner (const char *tagName)
 
int getFuncCnt ()
 
double getLoad ()
 
void * getLoadedModuleRef (int functionIndex)
 
virtual bool getStaticHelpList (char *list, const int listCnt)
 
UResBasegetStaticResource (const char *resName, bool mayCreate, bool staticOnly=true)
 get a pointer to a static resource. More...
 
bool handleAlive (UServerInMsg *msg)
 handles a command starting with the keyword 'alive'. More...
 
bool handleMessagesThreadStart ()
 
bool handleOneMessageFromQueue ()
 
bool handleOneServerPushMessage ()
 
bool handleShellCmd (UServerInMsg *msg)
 handles a command starting with the keyword 'do'. More...
 
bool isClientAlive (int clientIdx, double holdOffTime)
 
bool isModuleStatic (int moduleIndex)
 Test if the module with this index is loaded as static. More...
 
bool isResourceOwner (const char *ressID, UFunctionBase *owner)
 
bool isRxQueueEmpty ()
 
bool isRxQueueFull ()
 
bool isStopping ()
 
void killServer (UServerInMsg *msg)
 
UFunctionBaseloadFunctionModule (const char *moduleFileName, char *buff, int buffCnt, const char *aliasName)
 
virtual bool loadStaticModule (const char *moduleName, const char *aliasName, char *why, const int whyCnt)
 
virtual bool methodCall (const char *name, const char *paramOrder, char **strings, const double *doubles, double *value, UDataBase **returnStruct=NULL, int *returnStructCnt=NULL)
 
bool postCommand (int client, const char *command)
 
void print (const char *preStr)
 
void printRess (const char *preStr)
 
void run ()
 
void runIdle ()
 
bool sendDebug (UServerInMsg *msg, const char *debugText)
 
bool sendError (UServerInMsg *msg, const char *errorText)
 
bool sendHelp (UServerInMsg *msg, const char *infoText)
 
bool sendHelpDone (UServerInMsg *msg)
 Send a help close tag The help close tag </help> if followed by a full tag with the message 'msg' tag name and the text "info=done". More...
 
bool sendHelpStart (UServerInMsg *msg, const char *infoText)
 Send the open help tag Send open tag with one 'info' attribute with the provided string as value. Must be finished with a call to sendHelpDone(msg). More...
 
bool sendInfo (UServerInMsg *msg, const char *infoText)
 
bool sendMsg (int clientIdx, const char *message, int size)
 
bool sendMsg (UServerInMsg *msg, const char *message, int size)
 
bool sendMsg (int clientIdx, const char *message)
 
bool sendMsg (UServerInMsg *msg, const char *message)
 
bool sendMsgAll (const char *message, bool lockedUser)
 
bool sendText (UServerInMsg *msg, const char *text)
 
bool sendWarning (UServerInMsg *msg, const char *warningText)
 
void setName (const char *serverName)
 
void setServer (UServerPort *socketServer)
 
void setVerbose (bool value)
 
void stop (bool andWait)
 
 UCmdExe ()
 
void UCmdExeInit ()
 
bool unloadAllModules ()
 
bool unloadFunctionModule (const char *value)
 
void updateLocalVar ()
 
virtual ~UCmdExe ()
 
- 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 const char * print (const char *preString, char *buff, int buffCnt)
 
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)
 
virtual bool setResource (UResBase *resource, bool remove)
 
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 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 bool methodCallV (const char *name, const char *paramOrder, UVariable *params[], UDataBase **returnStruct, int *returnStructCnt)
 
virtual ~UVarMethodImplement ()
 
- Public Member Functions inherited from UServerPushImplement
bool addPushWatch (UServerPush *obj)
 Add an server push object to watch list. This is called by a combined resource-push object when the object is updated and thus a push command may need triggering. More...
 
void event ()
 
int getFunctionOwner (UServerInMsg *msg)
 
 UServerPushImplement ()
 
virtual ~UServerPushImplement ()
 

Static Public Member Functions

static const char * getResClassID ()
 
- Static Public Member Functions inherited from UResVarPool
static const char * getResClassID ()
 

Protected Member Functions

void closeLogServer ()
 
virtual const char * commandList ()
 
bool handleQuit (UServerInMsg *msg)
 
bool handleServerCommand (UServerInMsg *msg)
 
bool handleServerPushCommand (UServerInMsg *msg)
 
virtual const char * name ()
 
void resourcesUpdate (int funcIdx)
 
void resourcesUpdated ()
 
bool sysModuleCmd (UServerInMsg *msg)
 
bool sysServerHelp (UServerInMsg *msg)
 
bool systemFunction (UServerInMsg *msg)
 
bool unloadThisModule (int funcIdx)
 
- 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...
 

Private Attributes

bool callNotice
 should calls to plug-in functions be echo'ed to console (with time info) More...
 
char currentMessage [MMS]
 
UFunctionBasefunc [MAX_FUNCTION_COUNT]
 
int funcCnt
 
int idleLoopCnt
 
UTime idleStart
 start time for idle More...
 
double idleTime
 seconds in idle state More...
 
bool isIdle
 flag is true, when main thread is idle More...
 
ULogFile logServer
 
UServerPushQueue push
 
UResPoolresPool
 
UServerPortserver
 
const char * servName
 
bool stopping
 
pthread_t threadHandle
 
bool threadRunning
 
bool threadStop
 
UVariablevarAlivePunkTime
 time to wait before punking silent clients More...
 
UVariablevarAllowConnection
 pointer to allowConnection plag More...
 
UVariablevarClients
 number of active clients More...
 
UVariablevarIdle
 estimated load of server main thread More...
 
UVariablevarLastClient
 number of last client connected More...
 
UVariablevarLastClientSerial
 number of clients ever connected in this session More...
 
UVariablevarOpen4connections
 is server open for connections More...
 
UVariablevarPort
 port number for server More...
 
UVariablevarQTvarUpdate
 time between update tests to QT gui More...
 
UVariablevarTime
 pointer to allowConnection plag More...
 
bool verboseMessages
 
double wakeupSec
 time to wait before main thread i woken (to test for e.g. timed events) More...
 
double wLoad
 

Static Private Attributes

static const int MMS = MAX_MESSAGE_LENGTH_TO_CAM
 

Additional Inherited Members

- Public Attributes inherited from UReplay
bool replayTimeAdvancePending
 
UTime replayTimeNow
 
- 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 UServerPushImplement
sem_t actionFlag
 flag to be posted, when an event has happend More...
 
UServerPushpushWatch [MAX_PUSH_WATCH_CNT]
 
int pushWatchCnt
 
ULock pushWatchLock
 
- 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

Reads receive queue and asks loaded functions to handle command.

Author
Christian Andersen

Constructor & Destructor Documentation

UCmdExe::UCmdExe ( )
inline
UCmdExe::~UCmdExe ( )
virtual

Destructor

References ULogFile::closeLog(), logServer, resPool, server, and stop().

Referenced by UCmdExe().

Member Function Documentation

bool UCmdExe::addFunction ( UFunctionBase function)
bool UCmdExe::addNewRessources ( UFunctionBase function)

Add any new ressources this function has to offer

References addResource(), findFunctionIndex(), UResPool::getResCnt(), UResPool::getResource(), isAlphaNum(), resourcesUpdated(), and resPool.

Referenced by addFunction(), and getResClassID().

bool UCmdExe::addResource ( UResBase res,
UFunctionBase owner 
)

Add one resource into the resource structure with this owner module.

Parameters
resresource that should be added into resource pool
ownerthe owner module that just created the resource true if added (false if no more space).

References UResPool::addResource(), UResBase::createResources(), findFunctionIndex(), UResBase::getResID(), UFunctionBase::name(), resourcesUpdated(), resPool, UResBase::setCorePointer(), and UResBase::setResFuncIdx().

Referenced by addNewRessources(), UFunctionBase::addResource(), and getResClassID().

void UCmdExe::closeClient ( int  clientIdx)
void UCmdExe::closeLogServer ( )
protected

Close log for all server commands

References ULogFile::closeLog(), and logServer.

Referenced by getLoad().

const char * UCmdExe::commandList ( )
protectedvirtual

a stringlist of tag-names handled by system. e.g. "sys sysHigh system" that will handle all tags of this type.

Referenced by findFunctionOwner(), getLoad(), sysModuleCmd(), and sysServerHelp().

void UCmdExe::createBaseVar ( )
bool UCmdExe::deleteFunction ( UFunctionBase function)

Remove function from server function list. (This does not delete the function object). Returns true if function is found.

References func, funcCnt, UResPool::getResCnt(), UResBase::getResID(), UResPool::getResource(), UResPool::removeResourceFunc(), UFunctionBase::resourceUpdated(), resPool, server, UFunctionBase::setResource(), UResBase::setResource(), and UServerPort::setResource().

Referenced by getResClassID(), and unloadThisModule().

bool UCmdExe::doBashCmd ( UServerInMsg msg,
const char *  cmdStr 
)

execute a command line command and return reply as help text.

Parameters
msgThe source command
cmdStrthe command that should be send to the system The function uses popen to start the commands and continues to read from the stream until it terminates.
Returns
the value that the bash command returns (-2) if pipe can not be opened.

References sendHelpDone(), sendHelpStart(), and sendText().

Referenced by getLoad(), and handleShellCmd().

bool UCmdExe::executeFunction ( int  functionIndex,
UServerInMsg msg,
void *  extra,
bool  aPush 
)

Execute one of the functions with this command message. The 'extra' parameter is intended for event triggered push-commands, where the object triggering the event can be transferred as the extra parameter.

Parameters
functionIndexthe index returned by findFunctionOwner(tagName)
msgThe XMK reading structure with the command.
extramay be a pointer to a relevant object (laserscan, imega or other object usable by the function)
aPushset to true if this is a push command (to allow better logging etc) true if the functione were successfully executed.

References bool2str(), callNotice, UServerInMsg::client, func, UServerPort::getClient(), ULogFile::getF(), UTime::getMicrosec(), UMsgQueue::getNextOut(), UServerPort::getRxQueue(), UTime::getSec(), USmlTagIn::getTagName(), UTime::getTimePassed(), UMsgQueue::getUsedMsgCnt(), UServerClient::isActive(), UFunctionBase::isMine(), ULogFile::isOpen(), UServerClient::lock(), logServer, MAX_FUNCTION_COUNT, UServerInMsg::message, UFunctionBase::newCommand(), UTime::now(), server, systemFunction(), UServerInMsg::tag, and UServerClient::unlock().

Referenced by executePushFunction(), handleOneMessageFromQueue(), isStopping(), and UPush::pushEvent().

bool UCmdExe::executePushFunction ( int  functionIndex,
UServerInMsg msg,
void *  extra 
)
virtual

Ececute a push function, and lock for dynamic load/unload of function during operation.

Parameters
functionIndexthe index returned by findFunctionOwner(tagName)
msgThe XMK reading structure with the command.
extramay be a pointer to a relevant object (laserscan, imega or other object usable by the function)
Returns
true if the function were executed successfully - ie image found and processed - this is used to count good commands.

Reimplemented from UServerPushImplement.

References executeFunction(), ULock::lock(), and ULock::unlock().

Referenced by isStopping().

bool UCmdExe::executeScriptFile ( const char *  cfn,
bool  andWait,
int  forClient 
)

Execute a scriptfile of commands. The filename 'cfn' is assumed to be on the dataPath, unless the initial character of the name is '.' or '/'. Each command is put on the RX-queue if the queue is empty. If the queue is not empty the sequence is stalled until the queue is empty. If andWait is false, the commands are put on queue until no more commands or the queue is full. The command reply is returned to the client 'forClient'. If client is -1, then output to console (and push commands are not valid). true if all commands are put on queue.

References isRxQueueEmpty(), isRxQueueFull(), UResBase::line, postCommand(), sendMsg(), verboseMessages, and Wait().

Referenced by getFuncCnt(), handleServerCommand(), runCameraServerComponent(), runLaserServerComponent(), and runServer().

int UCmdExe::findFunctionIndex ( UFunctionBase function)

Find the index of this function - start from the latest (highest number) to allocate new resources to the most likely owner. Returns -1 if no index were found, otherwise an index from 0 to MAX_FUNCTION_COUNT

References func, and funcCnt.

Referenced by addNewRessources(), addResource(), and isStopping().

int UCmdExe::findFunctionOwner ( const char *  tagName)
virtual

Find function owner (index into list) for this tag name (command keyword) Returns MAX_FUNCTION_COUNT if it is a system function keyword. Returns -1 if keyword is not found.

Reimplemented from UServerPushImplement.

References commandList(), func, funcCnt, inThisStringList(), and MAX_FUNCTION_COUNT.

Referenced by addFunction(), and isStopping().

int UCmdExe::getFuncCnt ( )
inline
double UCmdExe::getLoad ( )
inline
void * UCmdExe::getLoadedModuleRef ( int  functionIndex)

Get handle to loaded module (for further symbol references

References func, funcCnt, and UFunctionBase::getLoadedModuleRef().

Referenced by isStopping(), unloadFunctionModule(), and unloadThisModule().

static const char* UCmdExe::getResClassID ( )
inlinestatic
bool UCmdExe::getStaticHelpList ( char *  list,
const int  listCnt 
)
virtual

Get help text for available static modules

Reimplemented in UServerStatic, UServerStatic, UServerStatic, UServerStatic, UServerStatic, UServerStatic, and UServerStatic.

Referenced by getFuncCnt(), UServerStatic::getStaticHelpList(), and sysModuleCmd().

UResBase * UCmdExe::getStaticResource ( const char *  resName,
bool  mayCreate,
bool  staticOnly = true 
)
virtual

get a pointer to a static resource.

Parameters
resNameThe name of the resource to be acquired.
mayCreateif set to true, then the resource will be created if it do not exist.
staticOnlyget only if a static resource (default). Getting non-static resources may be dangerous of not within same plugin, if not compiled against the same source (headerfilles).
Returns
NULL if not found, else a bointer to an existing type

Reimplemented from UServerPushImplement.

References UResBase::getResFuncIdx(), UResPool::getResource(), isModuleStatic(), loadStaticModule(), and resPool.

Referenced by getLoad(), UResBase::getStaticResource(), UFunctionBase::getStaticResource(), run(), and MainWindow::updateImg().

bool UCmdExe::handleAlive ( UServerInMsg msg)

handles a command starting with the keyword 'alive'.

Parameters
msgThe source command
Returns
true if successfull

References USmlTagIn::getAttValue(), USmlTagIn::getTagName(), sendHelpDone(), sendHelpStart(), sendMsg(), sendText(), server, UServerPort::serverAliveLast(), and UServerInMsg::tag.

Referenced by getLoad(), and systemFunction().

bool UCmdExe::handleMessagesThreadStart ( )
bool UCmdExe::handleOneMessageFromQueue ( )
bool UCmdExe::handleOneServerPushMessage ( )
bool UCmdExe::handleQuit ( UServerInMsg msg)
protected

handle the quit command - from any client

Parameters
msgis the reference to the client that send the command, and possibly expects a reply
Returns
true

References USmlTagIn::getAttValue(), killServer(), sendHelpDone(), sendHelpStart(), sendText(), servName, and UServerInMsg::tag.

Referenced by getLoad(), and systemFunction().

bool UCmdExe::handleServerCommand ( UServerInMsg msg)
protected

System wide command

References appName, bool2str(), callNotice, UServerInMsg::client, ULogFile::closeLog(), dataPath, executeScriptFile(), UServerPort::getActiveClientCnt(), USmlTagIn::getAttValue(), UServerPort::getClient(), UServerPort::getClientCnt(), UServerClient::getClientName(), UTime::GetDateString(), ULogFile::getF(), getLoad(), ULogFile::getLogFileName(), UServerClient::getLogFilename(), UServerClient::getLogReply(), UServerClient::getLogTimestamp(), UTime::getMicrosec(), UServerClient::getNamespaceTag(), USmlTagIn::getNextAttribute(), UMsgQueue::getNextOut(), UServerPort::getPort(), UServerPort::getRxQueue(), UTime::getSec(), UServerPort::getServerNamespace(), USmlTagIn::getTagName(), UTime::getTimeAsString(), UMsgQueue::getUsedMsgCnt(), imagePath, UServerClient::isActive(), UServerClient::isLogOpen(), ULogFile::isOpen(), UServerPort::isOpen4Connections(), killServer(), UServerInQueue::list(), UServerClient::logClose(), UServerClient::logOpen(), logServer, MAX_PATH_LENGTH, MAX_SML_NAME_LENGTH, name(), UTime::Now(), ULogFile::openLog(), UReplay::replayAdvanceTime(), replayPath, UReplay::replayTimeNow, sendHelp(), sendHelpDone(), sendHelpStart(), sendInfo(), sendMsg(), sendText(), sendWarning(), server, serverPort, servName, ULogFile::setLogName(), UServerClient::setLogReply(), UServerClient::setLogTimestamp(), UServerPort::setPort(), UTime::setTimeTod(), UServerPort::setVerbose(), str2bool(), str2bool2(), UServerInMsg::tag, verboseMessages, and Wait().

Referenced by getLoad(), and systemFunction().

bool UCmdExe::handleServerPushCommand ( UServerInMsg msg)
protected
bool UCmdExe::handleShellCmd ( UServerInMsg msg)

handles a command starting with the keyword 'do'.

Parameters
msgThe source command
Returns
true if successfull

References doBashCmd(), USmlTagIn::getAttValue(), USmlTagIn::getNext(), USmlTagIn::reset(), sendHelpDone(), sendHelpStart(), sendText(), UServerInMsg::tag, and xml2str().

Referenced by getLoad(), and systemFunction().

bool UCmdExe::isClientAlive ( int  clientIdx,
double  holdOffTime 
)
virtual

Test to see if client is alive

Parameters
clientIdxis client number (between 0 and 19)
holdOffTimeis hold off time after connection.
Returns
true if client is active and has been active for at least the hold off time.

Reimplemented from UServerPushImplement.

References UServerClient::connectTime, UServerPort::getClient(), UTime::getTimePassed(), UServerClient::isActive(), and server.

Referenced by handleOneServerPushMessage(), UFunctionBase::isClientAlive(), isStopping(), and UPush::pushEvent().

bool UCmdExe::isModuleStatic ( int  moduleIndex)

Test if the module with this index is loaded as static.

Returns
true if module exist and is static, else false.

References func, funcCnt, and UFunctionBase::isStatic().

Referenced by getLoad(), and getStaticResource().

bool UCmdExe::isResourceOwner ( const char *  ressID,
UFunctionBase owner 
)

Is this function owner of this resource

References func, UResBase::getResFuncIdx(), UResPool::getResource(), and resPool.

Referenced by getFuncCnt().

bool UCmdExe::isRxQueueEmpty ( )

true if commandqueue is empty

References UServerPort::getRxQueue(), UMsgQueue::isEmpty(), and server.

Referenced by executeScriptFile(), and getFuncCnt().

bool UCmdExe::isRxQueueFull ( )

Is receive queue full, i.e. no more space to pose commands. true if queue is full.

References UServerPort::getRxQueue(), UMsgQueue::isFull(), and server.

Referenced by executeScriptFile(), and getFuncCnt().

bool UCmdExe::isStopping ( )
inline

Is the server in the process of stopping all threads

Returns
true if stopping

References executeFunction(), executePushFunction(), findFunctionIndex(), findFunctionOwner(), getLoadedModuleRef(), isClientAlive(), and stopping.

Referenced by shutDownHandler().

void UCmdExe::killServer ( UServerInMsg msg)

Send a kill signal to server process.

Parameters
msgoptional reference to the client that ordered the kill

References UServerInMsg::client, ULogFile::getF(), UTime::getMicrosec(), UTime::getSec(), ULogFile::isOpen(), logServer, UTime::now(), and sendInfo().

Referenced by getLoad(), handleQuit(), and handleServerCommand().

UFunctionBase * UCmdExe::loadFunctionModule ( const char *  moduleFileName,
char *  buff,
int  buffCnt,
const char *  aliasName 
)

Load a plugin module with this qualified filename. Filename is typically of the form './name.so.0'. Returns pointer to created function if loaded. Returns NULL if load failed. The loaded module is added to the function list. The function try to load the module static first, if this fails the module name is assumed to be a filename and attempts to load it as a plugin. The returned handle can be used to make some static initialization if needed. A number of error messages may be send to 'stderr' and stored in 'buff' if the load fails.

[aliasName] is an alias name for modules that may be loaded more than once, i.e. interface module

References addFunction(), func, UTime::now(), UFunctionBase::setAliasName(), UFunctionBase::setLoadedModuleRef(), and UFunctionBase::setLoadTime().

Referenced by getFuncCnt(), and sysModuleCmd().

bool UCmdExe::loadStaticModule ( const char *  moduleName,
const char *  aliasName,
char *  why,
const int  whyCnt 
)
virtual

Create a function at a higher level, this is intended to be static available modules in specific servers. The moduleName is a keyword to one of the available static modules. If no such module exist a NULL pointer is returned. If the module exist, it should be created and added to the function list. A pointer to the created function should be returned, to allow further processing.

Parameters
[in]*moduleNamename of module, euther a filename or a name of a stativ module
[in]*aliasNamea specific (pre-) name to be used for command, resource and logfile.
Returns
true on succes, returns false if unknown module, 'why' is not modified (used if failed for a fatal reason)

Reimplemented in UServerStatic, UServerStatic, UServerStatic, UServerStatic, UServerStatic, UServerStatic, and UServerStatic.

References addFunction(), UResPoseHist::getMapPoseID(), UResPoseHist::getOdoPoseID(), UResPoseHist::getUtmPoseID(), and UFunctionPoseHist::setAliasName().

Referenced by getFuncCnt(), getStaticResource(), UServerStatic::loadStaticModule(), and sysModuleCmd().

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

Function to implement a var-pool method call. The function with 'name' and pameters in the order 'paramOrder' is to be called. The actual parameters are in 'strings' and 'doubles'. A double sized result may be returned in 'value'. May return struct values in the 'returnStruct' pointer list (when the pointer list is not NULL), and in this case the 'returnStructCnt' is set to the maximum number of pointers available and should be modified to the number of valid pointers returned. Should return true if function was handled. (otherwise an invalid function specification is assumed).

Reimplemented from UResVarPool.

References postCommand(), and roundi().

Referenced by getFuncCnt().

const char * UCmdExe::name ( )
protectedvirtual

Name and version of the command executor

References servName.

Referenced by getFuncCnt(), getLoad(), handleServerCommand(), and sysModuleCmd().

bool UCmdExe::postCommand ( int  client,
const char *  command 
)
void UCmdExe::print ( const char *  preStr)
virtual
void UCmdExe::printRess ( const char *  preStr)
inline

Print resource status to console

References UResPool::print(), resPool, and setServer().

void UCmdExe::resourcesUpdate ( int  funcIdx)
protected
void UCmdExe::resourcesUpdated ( )
protected

One or more resources are added or deleted - inform all other functions.

References funcCnt, UResPool::getResCnt(), UResPool::getResource(), resourcesUpdate(), resPool, server, UResBase::setResource(), and UServerPort::setResource().

Referenced by addNewRessources(), addResource(), and getLoad().

void UCmdExe::run ( )
void UCmdExe::runIdle ( )

wakes message thread regularly, when no activity Claculates load percentage

References UServerPushImplement::event(), threadStop, Wait(), and wakeupSec.

Referenced by callRunIdle(), and setVerbose().

bool UCmdExe::sendDebug ( UServerInMsg msg,
const char *  debugText 
)

Send a debug message to the client of with the tag type of the command, with a marking as a debug message and the provided warning text. the test will be put in double quotes, s� (almost) all characters are legal.

References UServerInMsg::client, USmlTagIn::getTagName(), sendMsg(), str2xml(), and UServerInMsg::tag.

Referenced by UFunctionBase::sendDebug(), and setVerbose().

bool UCmdExe::sendError ( UServerInMsg msg,
const char *  errorText 
)

Send an error to the client of with the tag type of the command, with a marking as an error and the provided error text. the text will be put in double quotes, and encoded with escape sequence as needed, s� (almost) all characters are legal.

References UServerInMsg::client, USmlTagIn::getTagName(), sendMsg(), str2xml(), and UServerInMsg::tag.

Referenced by UFunctionBase::sendError(), and setVerbose().

bool UCmdExe::sendHelp ( UServerInMsg msg,
const char *  infoText 
)

Send a info message to the client of with tag type help. The test will be put in double quotes and converted to XML-text.

References UServerInMsg::client, sendMsg(), and str2xml().

Referenced by handleServerCommand(), UFunctionBase::sendHelp(), and setVerbose().

bool UCmdExe::sendHelpDone ( UServerInMsg msg)

Send a help close tag The help close tag </help> if followed by a full tag with the message 'msg' tag name and the text "info=done".

References UServerInMsg::client, sendInfo(), and sendMsg().

Referenced by doBashCmd(), handleAlive(), handleQuit(), handleServerCommand(), handleShellCmd(), UFunctionBase::sendHelpDone(), setVerbose(), and sysModuleCmd().

bool UCmdExe::sendHelpStart ( UServerInMsg msg,
const char *  infoText 
)

Send the open help tag Send open tag with one 'info' attribute with the provided string as value. Must be finished with a call to sendHelpDone(msg).

Parameters
msgThe message with the client information.
infoTextThe string value to put into the info attribute.
Returns
true if send.

References UServerInMsg::client, sendMsg(), and str2xml().

Referenced by doBashCmd(), handleAlive(), handleQuit(), handleServerCommand(), handleShellCmd(), UFunctionBase::sendHelpStart(), and setVerbose().

bool UCmdExe::sendInfo ( UServerInMsg msg,
const char *  infoText 
)

Send a info message to the client of with the tag type of the command, with a marking as an info message and the provided text. the test will be put in double quotes, and converted to XML-text (i.e. using > for '>').

References UServerInMsg::client, USmlTagIn::getTagName(), sendMsg(), str2xml(), and UServerInMsg::tag.

Referenced by handleServerCommand(), handleServerPushCommand(), killServer(), sendHelpDone(), UFunctionBase::sendInfo(), setVerbose(), sysModuleCmd(), and sysServerHelp().

bool UCmdExe::sendMsg ( int  clientIdx,
const char *  message,
int  size 
)

Send a message to a client or to console with fized length - message may include a zero character. Returns true if send. NB! this call is depricated, as it do not allow lock of client connection during af lengthy transmission!! Use sendMsg(UServerInMsg * msg, const char * message, int size) instead.

Todo:
make this function private

References UServerClient::blockSend(), UQevent::consoleReply(), UServerPort::getClient(), UServerClient::isActive(), mini(), qevent, server, and xml2str().

Referenced by executeScriptFile(), getResClassID(), handleAlive(), handleServerCommand(), handleServerPushCommand(), sendDebug(), sendError(), sendHelp(), sendHelpDone(), sendHelpStart(), sendInfo(), sendMsg(), UFunctionBase::sendMsg(), UFunctionBase::sendMsgInt(), USmlTag::sendProbPoly(), sendText(), UResRuleState::sendToClientAsHelp(), sendWarning(), sysModuleCmd(), and sysServerHelp().

bool UCmdExe::sendMsg ( UServerInMsg msg,
const char *  message,
int  size 
)

Send a message to a client or to console with fized length - message may include a zero character. Returns true if send.

Todo:
Should allow connection lock during lengthy connections, but this is not implemented yet.

References UServerInMsg::client, and sendMsg().

bool UCmdExe::sendMsg ( int  clientIdx,
const char *  message 
)

Send zero terminated string. Returns true if send. NB! this call is depricated, as it do not allow lock of client connection during af lengthy transmission!! Use sendMsg(UServerInMsg * msg, const char * message.

Todo:
make this function private

References sendMsg().

bool UCmdExe::sendMsg ( UServerInMsg msg,
const char *  message 
)

Send a message to a client or to console with fixed length - message may include a zero character. Returns true if send.

Todo:
Should allow connection lock during lengthy connections, but this is not implemented yet.

References sendMsg().

bool UCmdExe::sendMsgAll ( const char *  message,
bool  lockedUser 
)

Send a message to all active clients. The connection is locked during the transmission, except for the user 'lockedUser', as it is assumed that the connection to this user is locked already (if called as part of a user request). If this function is not called as a direct reply to a user (client) request the 'lockedUsed' should be set to -1. Returns true if at least one client got the message.

References UServerClient::blockSend(), UServerPort::getClient(), UServerPort::getClientCnt(), UServerClient::isActive(), UServerClient::lock(), server, and UServerClient::unlock().

Referenced by getResClassID().

bool UCmdExe::sendText ( UServerInMsg msg,
const char *  text 
)

Send text string, and ensure that special protected XML characters are converted to an escape sequence, e.g. '<' = <. true if send.

References sendMsg(), and str2xmlMin().

Referenced by doBashCmd(), getFuncCnt(), handleAlive(), handleQuit(), handleServerCommand(), handleServerPushCommand(), handleShellCmd(), UFunctionBase::sendText(), sysModuleCmd(), and sysServerHelp().

bool UCmdExe::sendWarning ( UServerInMsg msg,
const char *  warningText 
)

Send a warning to the client of with the tag type of the command, with a marking as a warning and the provided warning text. the text will be put in double quotes, and encoded with escape sequence as needed, s� (almost) all characters are legal.

References UServerInMsg::client, USmlTagIn::getTagName(), sendMsg(), str2xml(), and UServerInMsg::tag.

Referenced by handleOneMessageFromQueue(), handleServerCommand(), handleServerPushCommand(), UFunctionBase::sendWarning(), setVerbose(), and sysModuleCmd().

void UCmdExe::setName ( const char *  serverName)

Fixed varsion number for this resource type. Should follow release version, i.e. version 1.28 gives number 128. Should be incremented only when there is change to this class definition, i.e new or changed functions or variables. Set the name of the server

References servName.

Referenced by getResClassID(), runCameraServerComponent(), runLaserServerComponent(), runServer(), and testServerGen().

void UCmdExe::setServer ( UServerPort socketServer)
void UCmdExe::setVerbose ( bool  value)
inline
void UCmdExe::stop ( bool  andWait)
virtual

Stop message handling thread, and wait for termination if the 'andWait' flag is true

Reimplemented from UResBase.

References UMsgQueue::clear(), UServerPort::getRxQueue(), server, UServerPort::stop(), stopping, threadHandle, threadRunning, threadStop, unloadAllModules(), and Wait().

Referenced by setVerbose(), shutDownHandler(), testServerGen(), and ~UCmdExe().

bool UCmdExe::sysModuleCmd ( UServerInMsg msg)
protected
bool UCmdExe::sysServerHelp ( UServerInMsg msg)
protected
bool UCmdExe::systemFunction ( UServerInMsg msg)
protected
void UCmdExe::UCmdExeInit ( )
bool UCmdExe::unloadAllModules ( )

Unload all modules - static as well as loaded - make an empty server

References funcCnt, resPool, UResPool::saveSettings(), UResPool::stop(), and unloadThisModule().

Referenced by getFuncCnt(), and stop().

bool UCmdExe::unloadFunctionModule ( const char *  value)

Unload a loadable module with this name. The name should be unique among loaded modules, and must at least hold three character. Module may be identified by an integer value (from function list) or the first part of the module name (at least 3 characters). If more modeles match the name, then the last module with a match is unloaded. Returns true if a module is unloaded, or false if no loaded module matches the name. Static modules should not be unloaded (but may be overloaded).

References func, funcCnt, UFunctionBase::getAliasName(), UFunctionBase::getLoadedFileName(), getLoadedModuleRef(), UFunctionBase::name(), and unloadThisModule().

Referenced by getFuncCnt(), and sysModuleCmd().

bool UCmdExe::unloadThisModule ( int  funcIdx)
protected

Unload the module with this index number and any ressources owned by this module. The index may be a static (compiled in) module or a loaded module. Returns true if the module is removed.

References deleteFunction(), func, funcCnt, UFunctionBase::getLoadedFileName(), getLoadedModuleRef(), and UFunctionBase::name().

Referenced by getLoad(), unloadAllModules(), and unloadFunctionModule().

void UCmdExe::updateLocalVar ( )

Member Data Documentation

bool UCmdExe::callNotice
private

should calls to plug-in functions be echo'ed to console (with time info)

Referenced by executeFunction(), handleServerCommand(), and UCmdExeInit().

char UCmdExe::currentMessage[MMS]
private

Currentlt handling this message

Referenced by handleOneMessageFromQueue(), and print().

UFunctionBase* UCmdExe::func[MAX_FUNCTION_COUNT]
private
int UCmdExe::funcCnt
private
int UCmdExe::idleLoopCnt
private

Command idle loop count

Referenced by print(), and UCmdExeInit().

UTime UCmdExe::idleStart
private

start time for idle

Referenced by run().

double UCmdExe::idleTime
private

seconds in idle state

Referenced by run().

bool UCmdExe::isIdle
private

flag is true, when main thread is idle

ULogFile UCmdExe::logServer
private
const int UCmdExe::MMS = MAX_MESSAGE_LENGTH_TO_CAM
staticprivate

Max length of current handled message (saved part) (size 1000)

Referenced by handleOneMessageFromQueue().

UServerPushQueue UCmdExe::push
private

Server push queue

Referenced by handleOneServerPushMessage(), handleServerPushCommand(), and print().

UResPool* UCmdExe::resPool
private
UServerPort* UCmdExe::server
private
const char* UCmdExe::servName
private
bool UCmdExe::stopping
private

stopping ther server

Referenced by isStopping(), stop(), and UCmdExeInit().

pthread_t UCmdExe::threadHandle
private

Thread handle for command read thrad.

Referenced by handleMessagesThreadStart(), and stop().

bool UCmdExe::threadRunning
private

Thread running flag

Referenced by handleMessagesThreadStart(), run(), stop(), and UCmdExeInit().

bool UCmdExe::threadStop
private

Flag to stop thread - terminates the thread

Referenced by handleMessagesThreadStart(), handleOneMessageFromQueue(), run(), runIdle(), stop(), and UCmdExeInit().

UVariable* UCmdExe::varAlivePunkTime
private

time to wait before punking silent clients

Referenced by createBaseVar(), and setServer().

UVariable* UCmdExe::varAllowConnection
private

pointer to allowConnection plag

Referenced by createBaseVar(), and run().

UVariable* UCmdExe::varClients
private

number of active clients

Referenced by createBaseVar(), and updateLocalVar().

UVariable* UCmdExe::varIdle
private

estimated load of server main thread

Referenced by createBaseVar(), and run().

UVariable* UCmdExe::varLastClient
private

number of last client connected

Referenced by createBaseVar(), and updateLocalVar().

UVariable* UCmdExe::varLastClientSerial
private

number of clients ever connected in this session

Referenced by createBaseVar(), and updateLocalVar().

UVariable* UCmdExe::varOpen4connections
private

is server open for connections

Referenced by createBaseVar(), and updateLocalVar().

UVariable* UCmdExe::varPort
private

port number for server

Referenced by createBaseVar(), and updateLocalVar().

UVariable* UCmdExe::varQTvarUpdate
private

time between update tests to QT gui

Referenced by createBaseVar(), and run().

UVariable* UCmdExe::varTime
private

pointer to allowConnection plag

Referenced by createBaseVar(), and updateLocalVar().

bool UCmdExe::verboseMessages
private

If verboseMessages is true, then more messages are prionted to the console

Referenced by executeScriptFile(), handleOneMessageFromQueue(), handleServerCommand(), setVerbose(), systemFunction(), and UCmdExeInit().

double UCmdExe::wakeupSec
private

time to wait before main thread i woken (to test for e.g. timed events)

Referenced by handleServerPushCommand(), runIdle(), and UCmdExeInit().

double UCmdExe::wLoad
private

Server log filename Server load figure in the range [0..1]. Is calculated from the number of idle waits executed in a fixed number of seconds.

Referenced by getLoad().


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