#include <ScriptingService.hpp>
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 |
StatementProcessor * | sproc |
StateMap | states |
bool | ZeroPeriodWarning |
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.
typedef std::vector< ProgramInterfacePtr > RTT::scripting::ScriptingService::Functions |
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.
typedef boost::shared_ptr<ScriptingService> RTT::scripting::ScriptingService::shared_ptr |
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.
RTT::ScriptingService::ScriptingService | ( | TaskContext * | parent | ) |
Creates a ScriptingService object. You need to add the service to parent yourself, or use Create().
Definition at line 71 of file ScriptingService.cpp.
RTT::ScriptingService::~ScriptingService | ( | ) | [virtual] |
Definition at line 84 of file ScriptingService.cpp.
bool RTT::ScriptingService::activateStateMachine | ( | const std::string & | name | ) |
Activate a previously loaded StateMachine.
name | The name of the StateMachine. |
Definition at line 869 of file ScriptingService.cpp.
void RTT::ScriptingService::clear | ( | ) |
Stop and unload all program scripts.
Reimplemented from RTT::Service.
Definition at line 92 of file ScriptingService.cpp.
ScriptingService::shared_ptr RTT::ScriptingService::Create | ( | TaskContext * | parent | ) | [static] |
Creates a ScriptingService object and registers the service to parent.
Definition at line 65 of file ScriptingService.cpp.
void RTT::ScriptingService::createInterface | ( | void | ) | [protected] |
Definition at line 448 of file ScriptingService.cpp.
bool RTT::ScriptingService::deactivateStateMachine | ( | const std::string & | name | ) |
Deactivate a stopped StateMachine.
name | The name of the StateMachine. |
Definition at line 877 of file ScriptingService.cpp.
bool RTT::scripting::ScriptingService::deleteProgram | ( | const std::string & | name | ) |
Completely discard a loaded Program.
program_unload_exception | if the program is not stopped or does not exist. |
bool RTT::ScriptingService::deleteStateMachine | ( | const std::string & | name | ) |
Delete a deactivated State Machine and all its children.
program_unload_exception | if the state machine or one of its children is still active. |
Definition at line 306 of file ScriptingService.cpp.
bool RTT::ScriptingService::doExecute | ( | const std::string & | code | ) | [protected] |
Definition at line 416 of file ScriptingService.cpp.
bool RTT::ScriptingService::doLoadPrograms | ( | const std::string & | filename | ) | [protected] |
Definition at line 421 of file ScriptingService.cpp.
bool RTT::ScriptingService::doLoadProgramText | ( | const std::string & | code | ) | [protected] |
Definition at line 426 of file ScriptingService.cpp.
bool RTT::ScriptingService::doLoadStateMachines | ( | const std::string & | filename | ) | [protected] |
Definition at line 435 of file ScriptingService.cpp.
bool RTT::ScriptingService::doLoadStateMachineText | ( | const std::string & | code | ) | [protected] |
Definition at line 439 of file ScriptingService.cpp.
bool RTT::ScriptingService::doUnloadProgram | ( | const std::string & | name | ) | [protected] |
Definition at line 430 of file ScriptingService.cpp.
bool RTT::ScriptingService::doUnloadStateMachine | ( | const std::string & | name | ) | [protected] |
Definition at line 443 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.
code | A list of statements, program/function definitions etc. which get evaluated in the context of this component |
parse_exception | and its derivatives for parse errors in code. |
Definition at line 596 of file ScriptingService.cpp.
bool RTT::ScriptingService::evalInternal | ( | const std::string & | filename, |
const std::string & | code | ||
) | [protected] |
Definition at line 600 of file ScriptingService.cpp.
int RTT::ScriptingService::execute | ( | const std::string & | code | ) |
Parse and execute a statement.
code | A single statement to execute. |
-1 | if the code could not be parsed. |
0 | if the code was an expression and could be executed. |
>0 | if the code was a command and is being executed. |
Definition at line 516 of file ScriptingService.cpp.
const ProgramInterfacePtr RTT::scripting::ScriptingService::getProgram | ( | const std::string & | name | ) | const |
Get a pointer to a loaded Program.
ProgramInterfacePtr RTT::scripting::ScriptingService::getProgram | ( | const std::string & | name | ) |
int RTT::ScriptingService::getProgramLine | ( | const std::string & | name | ) | const [virtual] |
Get the current line of execution of a loaded program script.
name | The name of the program. |
-1 | if the program does not exist. |
0 | if the program is not running. |
n | the line number if the program is executing. |
Definition at line 789 of file ScriptingService.cpp.
vector< string > RTT::ScriptingService::getProgramList | ( | ) | const |
Get a list of all loaded Programs.
Definition at line 398 of file ScriptingService.cpp.
ProgramInterface::Status::ProgramStatus RTT::ScriptingService::getProgramStatus | ( | const std::string & | name | ) | const |
Return the status of a Program.
Definition at line 328 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 337 of file ScriptingService.cpp.
string RTT::ScriptingService::getProgramText | ( | const std::string & | name | ) | const [virtual] |
Get the original script description of a loaded program.
name | The name of the program. |
Definition at line 794 of file ScriptingService.cpp.
const StateMachinePtr RTT::scripting::ScriptingService::getStateMachine | ( | const std::string & | name | ) | const |
Get a pointer to a loaded StateMachine.
StateMachinePtr RTT::scripting::ScriptingService::getStateMachine | ( | const std::string & | name | ) |
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.
name | The name of the state machine. |
-1 | if the state machine does not exist. |
0 | if the state machine is not running. |
n | the line number if the state machine is executing. |
Definition at line 808 of file ScriptingService.cpp.
vector< string > RTT::ScriptingService::getStateMachineList | ( | ) | const |
Get a list of all loaded StateMachines and their children.
Definition at line 323 of file ScriptingService.cpp.
string RTT::ScriptingService::getStateMachineState | ( | const std::string & | name | ) | const |
Get the current state of a state machine.
name | The name of the StateMachine. |
Definition at line 941 of file ScriptingService.cpp.
StateMachine::Status::StateMachineStatus RTT::ScriptingService::getStateMachineStatus | ( | const std::string & | name | ) | const |
Return the status of a StateMachine.
Definition at line 132 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 141 of file ScriptingService.cpp.
string RTT::ScriptingService::getStateMachineText | ( | const std::string & | name | ) | const [virtual] |
Get the original script description of a loaded state machine.
name | The name of the state machine. |
Definition at line 803 of file ScriptingService.cpp.
bool RTT::ScriptingService::hasProgram | ( | const std::string & | name | ) | const [virtual] |
Check if a program is loaded
name | The name of the program. |
Definition at line 785 of file ScriptingService.cpp.
bool RTT::ScriptingService::hasStateMachine | ( | const std::string & | name | ) | const [virtual] |
Check if a state machine is loaded.
name | The name of the state machine. |
Definition at line 799 of file ScriptingService.cpp.
bool RTT::ScriptingService::inProgramError | ( | const std::string & | name | ) | const |
Inspect if a loaded program is in the error state
name | The name of the Program. |
Definition at line 837 of file ScriptingService.cpp.
bool RTT::ScriptingService::inStateMachineError | ( | const std::string & | name | ) | const |
Returns true if the state machine is in error.
name | The name of the StateMachine. |
Definition at line 933 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
name | The name of the StateMachine. |
state | The state to enter. |
Definition at line 957 of file ScriptingService.cpp.
bool RTT::ScriptingService::isProgramPaused | ( | const std::string & | name | ) | const |
Inspect if a loaded program is in the paused state
name | The name of the Program. |
Definition at line 829 of file ScriptingService.cpp.
bool RTT::ScriptingService::isProgramRunning | ( | const std::string & | name | ) | const |
Inspect if a loaded program is in the running state
name | The name of the Program. |
Definition at line 821 of file ScriptingService.cpp.
bool RTT::ScriptingService::isStateMachineActive | ( | const std::string & | name | ) | const |
Returns true if the state machine has been activated.
name | The name of the StateMachine. |
Definition at line 917 of file ScriptingService.cpp.
bool RTT::ScriptingService::isStateMachinePaused | ( | const std::string & | name | ) | const |
Returns true if the state machine is paused.
name | The name of the StateMachine. |
Definition at line 909 of file ScriptingService.cpp.
bool RTT::ScriptingService::isStateMachineRunning | ( | const std::string & | name | ) | const |
Returns true if the state machine was successfully started.
name | The name of the StateMachine. |
Definition at line 925 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
filename | The file to load |
do_throw | Set to yes to cause the parse errors to be thrown instead of being printed to the Logger interface. |
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
code | A string containing the function definitions. |
filename | The file name to use in the error messages. |
do_throw | Set to yes to cause the parse errors to be thrown instead of being printed to the Logger interface. |
Load a new Program. The Processor takes full ownership and will delete it upon destruction.
program_load_exception | if a program with the same name already exists. |
Definition at line 360 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.
filename | The file to load |
do_throw | Set to yes to cause the parse errors to be thrown instead of being printed to the Logger interface. |
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.
code | A string containing the function definitions. |
filename | The file name to use in the error messages. |
do_throw | Set to yes to cause the parse errors to be thrown instead of being printed to the Logger interface. |
Load a new State Machine and all its children.
program_load_exception | if a state machine with the same name already exists. |
Definition at line 185 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.
filename | The file to load |
do_throw | Set to yes to cause the parse errors to be thrown instead of being printed to the Logger interface. |
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.
code | A string containing the function definitions. |
filename | The file name to use in the error messages. |
do_throw | Set to yes to cause the parse errors to be thrown instead of being printed to the Logger interface. |
bool RTT::ScriptingService::pauseProgram | ( | const std::string & | name | ) |
Pauses the execution of a running program.
name | The name of the Program. |
Definition at line 853 of file ScriptingService.cpp.
bool RTT::ScriptingService::pauseStateMachine | ( | const std::string & | name | ) |
Pause a previously activated StateMachine.
name | The name of the StateMachine. |
Definition at line 893 of file ScriptingService.cpp.
bool RTT::ScriptingService::recursiveCheckLoadStateMachine | ( | StateMachinePtr | sc | ) | [protected] |
Definition at line 210 of file ScriptingService.cpp.
bool RTT::ScriptingService::recursiveCheckUnloadStateMachine | ( | StateMachinePtr | si | ) | [protected] |
Definition at line 266 of file ScriptingService.cpp.
void RTT::ScriptingService::recursiveLoadStateMachine | ( | StateMachinePtr | sc | ) | [protected] |
Definition at line 230 of file ScriptingService.cpp.
void RTT::ScriptingService::recursiveUnloadStateMachine | ( | StateMachinePtr | sc | ) | [protected] |
Definition at line 288 of file ScriptingService.cpp.
bool RTT::ScriptingService::requestStateMachineState | ( | const std::string & | name, |
const std::string & | state | ||
) |
Request a state change in a state machine.
name | The name of the StateMachine. |
state | The state to enter. |
Definition at line 949 of file ScriptingService.cpp.
bool RTT::ScriptingService::resetStateMachine | ( | const std::string & | name | ) |
Resets the execution of a scripting::StateMachine and enters the Initial_State.
name | The name of the StateMachine. |
Definition at line 965 of file ScriptingService.cpp.
bool RTT::ScriptingService::runScript | ( | const std::string & | filename | ) |
Run a script which is stored in a file.
filename | The local file to load and execute |
parse_exception | and its derivatives for parse errors in code. |
Definition at line 578 of file ScriptingService.cpp.
bool RTT::ScriptingService::startProgram | ( | const std::string & | name | ) |
Start a Program.
name | The name of the Program. |
Definition at line 813 of file ScriptingService.cpp.
bool RTT::ScriptingService::startStateMachine | ( | const std::string & | name | ) |
Start a previously activated StateMachine.
name | The name of the StateMachine. |
Definition at line 885 of file ScriptingService.cpp.
bool RTT::ScriptingService::stepProgram | ( | const std::string & | name | ) |
Steps a single instruction of a paused program.
name | The name of the Program. |
Definition at line 861 of file ScriptingService.cpp.
bool RTT::ScriptingService::stopProgram | ( | const std::string & | name | ) |
Stops the execution of a program.
name | The name of the Program. |
Definition at line 845 of file ScriptingService.cpp.
bool RTT::ScriptingService::stopStateMachine | ( | const std::string & | name | ) |
Stops the execution of a scripting::StateMachine and enters the Final_State.
name | The name of the StateMachine. |
Definition at line 901 of file ScriptingService.cpp.
bool RTT::scripting::ScriptingService::unloadProgram | ( | const std::string & | name | ) |
Unload a program from this processor.
program_unload_exception | if 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.
name | The name of the loaded program. |
do_throw | Set to yes to cause the unloading errors to be thrown instead of being printed to the Logger interface. |
bool RTT::scripting::ScriptingService::unloadStateMachine | ( | const std::string & | name | ) |
Unload a deactivated State Machine and all its children.
program_unload_exception | if 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.
name | The name of the loaded program. |
do_throw | Set to yes to cause the unloading errors to be thrown instead of being printed to the Logger interface. |
ProgMap RTT::scripting::ScriptingService::programs [protected] |
Definition at line 572 of file ScriptingService.hpp.
Definition at line 548 of file ScriptingService.hpp.
StateMap RTT::scripting::ScriptingService::states [protected] |
Definition at line 568 of file ScriptingService.hpp.
bool RTT::scripting::ScriptingService::ZeroPeriodWarning [protected] |
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.