trikRuntime
trikScriptRunner::TrikScriptRunnerInterface Class Referenceabstract

Interface for all script executors. More...

#include <trikScriptRunnerInterface.h>

Inheritance diagram for trikScriptRunner::TrikScriptRunnerInterface:
Collaboration diagram for trikScriptRunner::TrikScriptRunnerInterface:

Classes

struct  Helper
 

Public Slots

virtual void run (const QString &script, const QString &fileName="")=0
 Executes given script asynchronously. More...
 
virtual void runDirectCommand (const QString &command)=0
 Executes given script as direct command, so it will use existing script execution environment (or create one if needed) and will not reset execution state before or after execution. More...
 
virtual void abort ()=0
 Aborts script execution. More...
 
virtual void brickBeep ()=0
 Plays "beep" sound. More...
 

Signals

void completed (const QString &error, int scriptId)
 Emitted when current script completes execution (for event-driven mode it means that script requested to quit or was aborted). More...
 
void startedScript (const QString &fileName, int scriptId)
 Emitted when new script from file started. More...
 
void startedDirectScript (int scriptId)
 Emitted when new direct script started. More...
 
void sendMessage (const QString &text)
 Emitted when a message must be sent to a desktop. More...
 

Public Member Functions

virtual void registerUserFunction (const QString &name, QScriptEngine::FunctionSignature function)=0
 Registers given C++ function as callable from script, with given name. More...
 
virtual void addCustomEngineInitStep (const std::function< void(QScriptEngine *)> &step)=0
 Adds custom initialization steps when creating script engine (useful when used from outside of the TrikRuntime). More...
 
virtual QStringList knownMethodNames () const =0
 Gets all method names from executive objects (brick, script, etc.) from ScriptEngineWorker (useful when used from outside of the TrikRuntime). More...
 
virtual bool wasError ()=0
 Get status of last direct command/script. More...
 

Detailed Description

Interface for all script executors.

Member Function Documentation

virtual void trikScriptRunner::TrikScriptRunnerInterface::abort ( )
pure virtualslot

Aborts script execution.

completed() signal will be emitted when script will be actually aborted, robot will be stopped and execution state will be reset. Note that direct commands and scripts in event-driven mode will be stopped as well.

virtual void trikScriptRunner::TrikScriptRunnerInterface::addCustomEngineInitStep ( const std::function< void(QScriptEngine *)> &  step)
pure virtual

Adds custom initialization steps when creating script engine (useful when used from outside of the TrikRuntime).

Implemented in trikScriptRunner::TrikJavaScriptRunner, trikScriptRunner::TrikPythonRunner, and trikScriptRunner::TrikScriptRunner.

virtual void trikScriptRunner::TrikScriptRunnerInterface::brickBeep ( )
pure virtualslot

Plays "beep" sound.

void trikScriptRunner::TrikScriptRunnerInterface::completed ( const QString &  error,
int  scriptId 
)
signal

Emitted when current script completes execution (for event-driven mode it means that script requested to quit or was aborted).

Parameters
error- localized error message if any error occured during script execution or empty string if everything is fine.
scriptId- unique identifier of a script completed
virtual QStringList trikScriptRunner::TrikScriptRunnerInterface::knownMethodNames ( ) const
pure virtual

Gets all method names from executive objects (brick, script, etc.) from ScriptEngineWorker (useful when used from outside of the TrikRuntime).

Implemented in trikScriptRunner::TrikScriptRunner, trikScriptRunner::TrikJavaScriptRunner, and trikScriptRunner::TrikPythonRunner.

virtual void trikScriptRunner::TrikScriptRunnerInterface::registerUserFunction ( const QString &  name,
QScriptEngine::FunctionSignature  function 
)
pure virtual

Registers given C++ function as callable from script, with given name.

Implemented in trikScriptRunner::TrikJavaScriptRunner, trikScriptRunner::TrikPythonRunner, and trikScriptRunner::TrikScriptRunner.

virtual void trikScriptRunner::TrikScriptRunnerInterface::run ( const QString &  script,
const QString &  fileName = "" 
)
pure virtualslot

Executes given script asynchronously.

If some script is already executing, it will be aborted. For event-driven mode (where script has brick.run() command) script counts as finished when it requests to quit by itself or was aborted. When script is finished, completed() signal will be emitted.

Parameters
script- script in Qt Script language to be executed.
fileName- name of a file from which the script was loaded.
Warning
: The multithreaded script must not contain useful actions in the global context (function calls, variable initializations and so on in the global context is restricted). The reason is in non-thread-safety of script engine. We must run scripts by separate script engines and thus to have an opportunity to start concrete function from the given file. But QScriptEngine API has no such possibility so we should append function call to the end of the script. So if script will run some actions in the global context they will be invoked on each thread start.
virtual void trikScriptRunner::TrikScriptRunnerInterface::runDirectCommand ( const QString &  command)
pure virtualslot

Executes given script as direct command, so it will use existing script execution environment (or create one if needed) and will not reset execution state before or after execution.

Sequence of direct commands counts as finished when one of them directly requests to quit (by brick.quit() command), then robot will be stopped, execution state will reset and completed() signal will be emitted.

Parameters
command- script in Qt Script to be executed as direct command.
void trikScriptRunner::TrikScriptRunnerInterface::sendMessage ( const QString &  text)
signal

Emitted when a message must be sent to a desktop.

void trikScriptRunner::TrikScriptRunnerInterface::startedDirectScript ( int  scriptId)
signal

Emitted when new direct script started.

Parameters
scriptId- unique id of executed script assigned when script started.
void trikScriptRunner::TrikScriptRunnerInterface::startedScript ( const QString &  fileName,
int  scriptId 
)
signal

Emitted when new script from file started.

Parameters
fileName- name of a file from where the script was loaded.
scriptId- unique id of executed script assigned when script started.
virtual bool trikScriptRunner::TrikScriptRunnerInterface::wasError ( )
pure virtual

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