Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
RTT::scripting::ScriptingService Class Reference

#include <ScriptingService.hpp>

Inheritance diagram for RTT::scripting::ScriptingService:
Inheritance graph
[legend]

List of all members.

Public Types

typedef std::vector
< ProgramInterfacePtr
Functions
typedef ProgramInterface::Status ProgramStatus
typedef boost::shared_ptr
< ScriptingService
shared_ptr
typedef
scripting::StateMachine::Status 
StateMachineStatus

Public Member Functions

void clear ()
bool deleteProgram (const std::string &name)
bool deleteStateMachine (const std::string &name)
bool eval (const std::string &code)
int execute (const std::string &code)
const ProgramInterfacePtr getProgram (const std::string &name) const
ProgramInterfacePtr getProgram (const std::string &name)
virtual int getProgramLine (const std::string &name) const
std::vector< std::string > getProgramList () const
ProgramStatus::ProgramStatus getProgramStatus (const std::string &name) const
std::string getProgramStatusStr (const std::string &name) const
virtual std::string getProgramText (const std::string &name) const
const StateMachinePtr getStateMachine (const std::string &name) const
StateMachinePtr getStateMachine (const std::string &name)
virtual int getStateMachineLine (const std::string &name) const
std::vector< std::string > getStateMachineList () const
StateMachineStatus::StateMachineStatus getStateMachineStatus (const std::string &name) const
std::string getStateMachineStatusStr (const std::string &name) const
virtual std::string getStateMachineText (const std::string &name) const
virtual Functions loadFunctions (const std::string &filename, bool do_throw)
virtual Functions loadFunctions (const std::string &code, const std::string &filename, bool do_throw)
bool loadProgram (ProgramInterfacePtr pi)
virtual bool loadPrograms (const std::string &filename, bool do_throw)
virtual bool loadPrograms (const std::string &code, const std::string &filename, bool do_throw)
bool loadStateMachine (StateMachinePtr sc)
virtual bool loadStateMachines (const std::string &filename, bool do_throw)
virtual bool loadStateMachines (const std::string &code, const std::string &filename, bool do_throw)
bool runScript (const std::string &filename)
 ScriptingService (TaskContext *parent)
bool unloadProgram (const std::string &name)
virtual bool unloadProgram (const std::string &name, bool do_throw)
bool unloadStateMachine (const std::string &name)
virtual bool unloadStateMachine (const std::string &name, bool do_throw)
virtual ~ScriptingService ()
Script Program Commands
bool startProgram (const std::string &name)
bool stopProgram (const std::string &name)
bool pauseProgram (const std::string &name)
bool stepProgram (const std::string &name)
Script Program OperationCallers
virtual bool hasProgram (const std::string &name) const
bool isProgramRunning (const std::string &name) const
bool isProgramPaused (const std::string &name) const
bool inProgramError (const std::string &name) const
Script State Machine Commands
bool activateStateMachine (const std::string &name)
bool deactivateStateMachine (const std::string &name)
bool startStateMachine (const std::string &name)
bool pauseStateMachine (const std::string &name)
bool stopStateMachine (const std::string &name)
bool resetStateMachine (const std::string &name)
bool requestStateMachineState (const std::string &name, const std::string &state)
Script State Machine OperationCallers
virtual bool hasStateMachine (const std::string &name) const
bool isStateMachineActive (const std::string &name) const
bool isStateMachineRunning (const std::string &name) const
bool inStateMachineError (const std::string &name) const
bool isStateMachinePaused (const std::string &name) const
std::string getStateMachineState (const std::string &name) const
bool inStateMachineState (const std::string &name, const std::string &state) const

Static Public Member Functions

static shared_ptr Create (TaskContext *parent)

Protected Types

typedef std::map< std::string,
ProgramInterfacePtr
ProgMap
typedef ProgMap::const_iterator ProgMapIt
typedef std::map< std::string,
StateMachinePtr
StateMap
typedef StateMap::const_iterator StateMapIt

Protected Member Functions

void createInterface (void)
bool doExecute (const std::string &code)
bool doLoadPrograms (const std::string &filename)
bool doLoadProgramText (const std::string &code)
bool doLoadStateMachines (const std::string &filename)
bool doLoadStateMachineText (const std::string &code)
bool doUnloadProgram (const std::string &name)
bool doUnloadStateMachine (const std::string &name)
bool evalInternal (const std::string &filename, const std::string &code)
bool recursiveCheckLoadStateMachine (StateMachinePtr sc)
bool recursiveCheckUnloadStateMachine (StateMachinePtr si)
void recursiveLoadStateMachine (StateMachinePtr sc)
void recursiveUnloadStateMachine (StateMachinePtr sc)

Protected Attributes

ProgMap programs
StatementProcessorsproc
StateMap states
bool ZeroPeriodWarning

Detailed Description

This interface allows to load program scripts and state machines and allows execution of code. It keeps track of all loaded scripts of the parent component. It can be found as the scripting object of a TaskContext.

Definition at line 60 of file ScriptingService.hpp.


Member Typedef Documentation

List of executed functions.

Definition at line 224 of file ScriptingService.hpp.

typedef std::map<std::string,ProgramInterfacePtr> RTT::scripting::ScriptingService::ProgMap [protected]

Definition at line 571 of file ScriptingService.hpp.

typedef ProgMap::const_iterator RTT::scripting::ScriptingService::ProgMapIt [protected]

Definition at line 573 of file ScriptingService.hpp.

Definition at line 80 of file ScriptingService.hpp.

Reimplemented from RTT::Service.

Definition at line 64 of file ScriptingService.hpp.

Definition at line 81 of file ScriptingService.hpp.

typedef std::map<std::string,StateMachinePtr> RTT::scripting::ScriptingService::StateMap [protected]

Definition at line 567 of file ScriptingService.hpp.

typedef StateMap::const_iterator RTT::scripting::ScriptingService::StateMapIt [protected]

Definition at line 569 of file ScriptingService.hpp.


Constructor & Destructor Documentation

Creates a ScriptingService object. You need to add the service to parent yourself, or use Create().

Definition at line 70 of file ScriptingService.cpp.

Definition at line 83 of file ScriptingService.cpp.


Member Function Documentation

bool RTT::ScriptingService::activateStateMachine ( const std::string &  name)

Activate a previously loaded StateMachine.

Parameters:
nameThe name of the StateMachine.

Definition at line 868 of file ScriptingService.cpp.

Stop and unload all program scripts.

Reimplemented from RTT::Service.

Definition at line 91 of file ScriptingService.cpp.

Creates a ScriptingService object and registers the service to parent.

Definition at line 64 of file ScriptingService.cpp.

void RTT::ScriptingService::createInterface ( void  ) [protected]

Definition at line 447 of file ScriptingService.cpp.

bool RTT::ScriptingService::deactivateStateMachine ( const std::string &  name)

Deactivate a stopped StateMachine.

Parameters:
nameThe name of the StateMachine.

Definition at line 876 of file ScriptingService.cpp.

bool RTT::scripting::ScriptingService::deleteProgram ( const std::string &  name)

Completely discard a loaded Program.

Exceptions:
program_unload_exceptionif the program is not stopped or does not exist.
Deprecated:
by unloadProgram
bool RTT::ScriptingService::deleteStateMachine ( const std::string &  name)

Delete a deactivated State Machine and all its children.

Exceptions:
program_unload_exceptionif the state machine or one of its children is still active.
Deprecated:
by unloadStateMachine

Definition at line 305 of file ScriptingService.cpp.

bool RTT::ScriptingService::doExecute ( const std::string &  code) [protected]

Definition at line 415 of file ScriptingService.cpp.

bool RTT::ScriptingService::doLoadPrograms ( const std::string &  filename) [protected]

Definition at line 420 of file ScriptingService.cpp.

bool RTT::ScriptingService::doLoadProgramText ( const std::string &  code) [protected]

Definition at line 425 of file ScriptingService.cpp.

bool RTT::ScriptingService::doLoadStateMachines ( const std::string &  filename) [protected]

Definition at line 434 of file ScriptingService.cpp.

bool RTT::ScriptingService::doLoadStateMachineText ( const std::string &  code) [protected]

Definition at line 438 of file ScriptingService.cpp.

bool RTT::ScriptingService::doUnloadProgram ( const std::string &  name) [protected]

Definition at line 429 of file ScriptingService.cpp.

bool RTT::ScriptingService::doUnloadStateMachine ( const std::string &  name) [protected]

Definition at line 442 of file ScriptingService.cpp.

bool RTT::ScriptingService::eval ( const std::string &  code)

Evaluate and run all statements in code. This function is in functionality equivalent to runScript, except that runScript takes a filename as an argument, while this function takes the contents of the script itself as an argument. All possible syntax may be used.

Parameters:
codeA list of statements, program/function definitions etc. which get evaluated in the context of this component
Returns:
true if the parsing and execution succeeded (= no syntax errors and no exceptions thrown when executing code ), false otherwise.
Exceptions:
parse_exceptionand its derivatives for parse errors in code.

Definition at line 595 of file ScriptingService.cpp.

bool RTT::ScriptingService::evalInternal ( const std::string &  filename,
const std::string &  code 
) [protected]

Definition at line 599 of file ScriptingService.cpp.

int RTT::ScriptingService::execute ( const std::string &  code)

Parse and execute a statement.

Parameters:
codeA single statement to execute.
Returns:
A ticket number.
Return values:
-1if the code could not be parsed.
0if the code was an expression and could be executed.
>0if the code was a command and is being executed.
See also:
getCommand
Deprecated:
by eval()

Definition at line 515 of file ScriptingService.cpp.

const ProgramInterfacePtr RTT::scripting::ScriptingService::getProgram ( const std::string &  name) const

Get a pointer to a loaded Program.

int RTT::ScriptingService::getProgramLine ( const std::string &  name) const [virtual]

Get the current line of execution of a loaded program script.

Parameters:
nameThe name of the program.
Returns:
The line number.
Return values:
-1if the program does not exist.
0if the program is not running.
nthe line number if the program is executing.

Definition at line 788 of file ScriptingService.cpp.

vector< string > RTT::ScriptingService::getProgramList ( ) const

Get a list of all loaded Programs.

Definition at line 397 of file ScriptingService.cpp.

Return the status of a Program.

Definition at line 327 of file ScriptingService.cpp.

string RTT::ScriptingService::getProgramStatusStr ( const std::string &  name) const

Return the status of a Program as a human readable string.

Definition at line 336 of file ScriptingService.cpp.

string RTT::ScriptingService::getProgramText ( const std::string &  name) const [virtual]

Get the original script description of a loaded program.

Parameters:
nameThe name of the program.
Returns:
A string containing only that program.

Definition at line 793 of file ScriptingService.cpp.

const StateMachinePtr RTT::scripting::ScriptingService::getStateMachine ( const std::string &  name) const

Get a pointer to a loaded StateMachine.

Get a pointer to a loaded StateMachine.

int RTT::ScriptingService::getStateMachineLine ( const std::string &  name) const [virtual]

Get the current line of execution of a loaded state machine script.

Parameters:
nameThe name of the state machine.
Returns:
The line number.
Return values:
-1if the state machine does not exist.
0if the state machine is not running.
nthe line number if the state machine is executing.

Definition at line 807 of file ScriptingService.cpp.

vector< string > RTT::ScriptingService::getStateMachineList ( ) const

Get a list of all loaded StateMachines and their children.

Definition at line 322 of file ScriptingService.cpp.

string RTT::ScriptingService::getStateMachineState ( const std::string &  name) const

Get the current state of a state machine.

Parameters:
nameThe name of the StateMachine.

Definition at line 940 of file ScriptingService.cpp.

Return the status of a StateMachine.

Definition at line 131 of file ScriptingService.cpp.

string RTT::ScriptingService::getStateMachineStatusStr ( const std::string &  name) const

Return the status of a StateMachine as a human readable string

Definition at line 140 of file ScriptingService.cpp.

string RTT::ScriptingService::getStateMachineText ( const std::string &  name) const [virtual]

Get the original script description of a loaded state machine.

Parameters:
nameThe name of the state machine.
Returns:
A string containing only that state machine.

Definition at line 802 of file ScriptingService.cpp.

bool RTT::ScriptingService::hasProgram ( const std::string &  name) const [virtual]

Check if a program is loaded

Parameters:
nameThe name of the program.
Returns:
True if so.

Definition at line 784 of file ScriptingService.cpp.

bool RTT::ScriptingService::hasStateMachine ( const std::string &  name) const [virtual]

Check if a state machine is loaded.

Parameters:
nameThe name of the state machine.
Returns:
True if so.

Definition at line 798 of file ScriptingService.cpp.

bool RTT::ScriptingService::inProgramError ( const std::string &  name) const

Inspect if a loaded program is in the error state

Parameters:
nameThe name of the Program.
Returns:
true if so.

Definition at line 836 of file ScriptingService.cpp.

bool RTT::ScriptingService::inStateMachineError ( const std::string &  name) const

Returns true if the state machine is in error.

Parameters:
nameThe name of the StateMachine.

Definition at line 932 of file ScriptingService.cpp.

bool RTT::ScriptingService::inStateMachineState ( const std::string &  name,
const std::string &  state 
) const

Check if a state machine is in a given state

Parameters:
nameThe name of the StateMachine.
stateThe state to enter.
Returns:
true if so.

Definition at line 956 of file ScriptingService.cpp.

bool RTT::ScriptingService::isProgramPaused ( const std::string &  name) const

Inspect if a loaded program is in the paused state

Parameters:
nameThe name of the Program.
Returns:
true if so.

Definition at line 828 of file ScriptingService.cpp.

bool RTT::ScriptingService::isProgramRunning ( const std::string &  name) const

Inspect if a loaded program is in the running state

Parameters:
nameThe name of the Program.
Returns:
true if so.

Definition at line 820 of file ScriptingService.cpp.

bool RTT::ScriptingService::isStateMachineActive ( const std::string &  name) const

Returns true if the state machine has been activated.

Parameters:
nameThe name of the StateMachine.

Definition at line 916 of file ScriptingService.cpp.

bool RTT::ScriptingService::isStateMachinePaused ( const std::string &  name) const

Returns true if the state machine is paused.

Parameters:
nameThe name of the StateMachine.

Definition at line 908 of file ScriptingService.cpp.

bool RTT::ScriptingService::isStateMachineRunning ( const std::string &  name) const

Returns true if the state machine was successfully started.

Parameters:
nameThe name of the StateMachine.

Definition at line 924 of file ScriptingService.cpp.

virtual Functions RTT::scripting::ScriptingService::loadFunctions ( const std::string &  filename,
bool  do_throw 
) [virtual]

Load and execute a set of functions into the Program Processor for execution

Parameters:
filenameThe file to load
do_throwSet to yes to cause the parse errors to be thrown instead of being printed to the Logger interface.
Returns:
A list of functions loaded in the ProgramProcessor.
Deprecated:
by runScript
virtual Functions RTT::scripting::ScriptingService::loadFunctions ( const std::string &  code,
const std::string &  filename,
bool  do_throw 
) [virtual]

Load and execute a set of functions into the Program Processor for execution

Parameters:
codeA string containing the function definitions.
filenameThe file name to use in the error messages.
do_throwSet to yes to cause the parse errors to be thrown instead of being printed to the Logger interface.
Returns:
A list of functions loaded in the ProgramProcessor.
Deprecated:
by runScript

Load a new Program. The Processor takes full ownership and will delete it upon destruction.

Exceptions:
program_load_exceptionif a program with the same name already exists.

Definition at line 359 of file ScriptingService.cpp.

virtual bool RTT::scripting::ScriptingService::loadPrograms ( const std::string &  filename,
bool  do_throw 
) [virtual]

Load a set of programs into the Program Processor for execution. The programs are just loaded, not started yet.

Parameters:
filenameThe file to load
do_throwSet to yes to cause the parse errors to be thrown instead of being printed to the Logger interface.
Returns:
true if all state machines could be loaded in the ProgramProcessor.
Deprecated:
by runScript
virtual bool RTT::scripting::ScriptingService::loadPrograms ( const std::string &  code,
const std::string &  filename,
bool  do_throw 
) [virtual]

Load a set of programs into the Program Processor for execution. The programs are just loaded, not started yet.

Parameters:
codeA string containing the function definitions.
filenameThe file name to use in the error messages.
do_throwSet to yes to cause the parse errors to be thrown instead of being printed to the Logger interface.
Returns:
true if all state machines could be loaded in the ProgramProcessor.
Deprecated:
by runScript

Load a new State Machine and all its children.

Exceptions:
program_load_exceptionif a state machine with the same name already exists.

Definition at line 184 of file ScriptingService.cpp.

virtual bool RTT::scripting::ScriptingService::loadStateMachines ( const std::string &  filename,
bool  do_throw 
) [virtual]

Load a set of state machines into the StateMachineProcessor for execution. The state machines are just loaded, not started yet.

Parameters:
filenameThe file to load
do_throwSet to yes to cause the parse errors to be thrown instead of being printed to the Logger interface.
Returns:
true if all state machines could be loaded in the StateMachineProcessor.
Deprecated:
by runScript
virtual bool RTT::scripting::ScriptingService::loadStateMachines ( const std::string &  code,
const std::string &  filename,
bool  do_throw 
) [virtual]

Load a set of state machines into the StateMachineProcessor for execution. The state machines are just loaded, not started yet.

Parameters:
codeA string containing the function definitions.
filenameThe file name to use in the error messages.
do_throwSet to yes to cause the parse errors to be thrown instead of being printed to the Logger interface.
Returns:
true if all state machines could be loaded in the StateMachineProcessor.
Deprecated:
by runScript
bool RTT::ScriptingService::pauseProgram ( const std::string &  name)

Pauses the execution of a running program.

Parameters:
nameThe name of the Program.

Definition at line 852 of file ScriptingService.cpp.

bool RTT::ScriptingService::pauseStateMachine ( const std::string &  name)

Pause a previously activated StateMachine.

Parameters:
nameThe name of the StateMachine.

Definition at line 892 of file ScriptingService.cpp.

Definition at line 209 of file ScriptingService.cpp.

Definition at line 265 of file ScriptingService.cpp.

Definition at line 229 of file ScriptingService.cpp.

Definition at line 287 of file ScriptingService.cpp.

bool RTT::ScriptingService::requestStateMachineState ( const std::string &  name,
const std::string &  state 
)

Request a state change in a state machine.

Parameters:
nameThe name of the StateMachine.
stateThe state to enter.
Returns:
true if the state change request was accepted.

Definition at line 948 of file ScriptingService.cpp.

bool RTT::ScriptingService::resetStateMachine ( const std::string &  name)

Resets the execution of a scripting::StateMachine and enters the Initial_State.

Parameters:
nameThe name of the StateMachine.

Definition at line 964 of file ScriptingService.cpp.

bool RTT::ScriptingService::runScript ( const std::string &  filename)

Run a script which is stored in a file.

Parameters:
filenameThe local file to load and execute
Returns:
true if the parsing and execution succeeded (= no syntax errors and no exceptions thrown when executing code ), false otherwise.
Exceptions:
parse_exceptionand its derivatives for parse errors in code.

Definition at line 577 of file ScriptingService.cpp.

bool RTT::ScriptingService::startProgram ( const std::string &  name)

Start a Program.

Parameters:
nameThe name of the Program.

Definition at line 812 of file ScriptingService.cpp.

bool RTT::ScriptingService::startStateMachine ( const std::string &  name)

Start a previously activated StateMachine.

Parameters:
nameThe name of the StateMachine.

Definition at line 884 of file ScriptingService.cpp.

bool RTT::ScriptingService::stepProgram ( const std::string &  name)

Steps a single instruction of a paused program.

Parameters:
nameThe name of the Program.

Definition at line 860 of file ScriptingService.cpp.

bool RTT::ScriptingService::stopProgram ( const std::string &  name)

Stops the execution of a program.

Parameters:
nameThe name of the Program.

Definition at line 844 of file ScriptingService.cpp.

bool RTT::ScriptingService::stopStateMachine ( const std::string &  name)

Stops the execution of a scripting::StateMachine and enters the Final_State.

Parameters:
nameThe name of the StateMachine.

Definition at line 900 of file ScriptingService.cpp.

bool RTT::scripting::ScriptingService::unloadProgram ( const std::string &  name)

Unload a program from this processor.

Exceptions:
program_unload_exceptionif the program is not stopped or does not exist.
virtual bool RTT::scripting::ScriptingService::unloadProgram ( const std::string &  name,
bool  do_throw 
) [virtual]

Unload a program from the Program Processor.

Parameters:
nameThe name of the loaded program.
do_throwSet to yes to cause the unloading errors to be thrown instead of being printed to the Logger interface.
Returns:
true if it could be unloaded
bool RTT::scripting::ScriptingService::unloadStateMachine ( const std::string &  name)

Unload a deactivated State Machine and all its children.

Exceptions:
program_unload_exceptionif the state machine or one of its children is still active.
virtual bool RTT::scripting::ScriptingService::unloadStateMachine ( const std::string &  name,
bool  do_throw 
) [virtual]

Unload a state machine from the StateMachineProcessor.

Parameters:
nameThe name of the loaded program.
do_throwSet to yes to cause the unloading errors to be thrown instead of being printed to the Logger interface.
Returns:
true if it could be unloaded

Member Data Documentation

Definition at line 572 of file ScriptingService.hpp.

Definition at line 548 of file ScriptingService.hpp.

Definition at line 568 of file ScriptingService.hpp.

This is a property of the Scripting service It is true by default If this is set to false, the warning log when loading a program or a state machine into a Component with a null period will not be printed.

Be sure you have something else triggering periodically your Component activity unless your script may not work.

Definition at line 583 of file ScriptingService.hpp.


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


rtt
Author(s): RTT Developers
autogenerated on Mon Oct 6 2014 03:14:00