trikRuntime
trikScriptRunner::Threading Class Reference

Designed to support OS threads from a Qt Script. More...

#include <threading.h>

Inheritance diagram for trikScriptRunner::Threading:
Collaboration diagram for trikScriptRunner::Threading:

Signals

void finished ()
 Signals that all threads have finished. More...
 
void getVariables (const QString &propertyName)
 Emitted when there is a request for variables values. More...
 
void variablesReady (const QJsonObject &data)
 Emitted when variables values are ready. More...
 

Public Member Functions

 Threading (ScriptEngineWorker *scriptWorker, ScriptExecutionControl &scriptControl)
 Constructs a Threading object with given script worker as a parent. More...
 
 ~Threading () override
 
void startMainThread (const QString &script)
 Starts the main thread of a script. More...
 
Q_INVOKABLE void startThread (const QScriptValue &threadId, const QScriptValue &function)
 Starts a thread with given threadId. More...
 
Q_INVOKABLE void joinThread (const QString &threadId)
 Joins a thread with given threadId. Does nothing if there is no thread with such id. More...
 
Q_INVOKABLE void sendMessage (const QString &threadId, const QScriptValue &message)
 Sends message to a mailbox with given threadId, even if such thread does not exist. More...
 
Q_INVOKABLE QScriptValue receiveMessage (bool waitForMessage=true)
 Designed to be called from a thread receiving a message. More...
 
Q_INVOKABLE void killThread (const QString &threadId)
 Stops given thread. More...
 
void waitForAll ()
 Wait until all threads finish execution. More...
 
void waitForAllYielding ()
 Wait until all threads finish execution. More...
 
Q_INVOKABLE void reset ()
 Aborts evalutation of all threads, resets to initial state. More...
 
QString errorMessage () const
 The last error message. More...
 
void threadFinished (const QString &id)
 Designed to be called from a thread that's finished execution. More...
 
bool inEventDrivenMode () const
 Returns true if the script is being evaluated in event-driven mode. More...
 

Detailed Description

Designed to support OS threads from a Qt Script.

Provides methods for creation and joining threads and for sending messages between threads.

Constructor & Destructor Documentation

Threading::Threading ( ScriptEngineWorker scriptWorker,
ScriptExecutionControl scriptControl 
)
explicit

Constructs a Threading object with given script worker as a parent.

Threading::~Threading ( )
override

Member Function Documentation

QString Threading::errorMessage ( ) const

The last error message.

void trikScriptRunner::Threading::finished ( )
signal

Signals that all threads have finished.

void trikScriptRunner::Threading::getVariables ( const QString &  propertyName)
signal

Emitted when there is a request for variables values.

Parameters
propertyName- name of variables prefix, i.e prefix "web" for variable "web.light"
bool Threading::inEventDrivenMode ( ) const

Returns true if the script is being evaluated in event-driven mode.

void Threading::joinThread ( const QString &  threadId)

Joins a thread with given threadId. Does nothing if there is no thread with such id.

void Threading::killThread ( const QString &  threadId)

Stops given thread.

QScriptValue Threading::receiveMessage ( bool  waitForMessage = true)

Designed to be called from a thread receiving a message.

void Threading::reset ( )

Aborts evalutation of all threads, resets to initial state.

void Threading::sendMessage ( const QString &  threadId,
const QScriptValue &  message 
)

Sends message to a mailbox with given threadId, even if such thread does not exist.

The message can be accessed in the future by any thread with the same threadId.

void Threading::startMainThread ( const QString &  script)

Starts the main thread of a script.

void Threading::startThread ( const QScriptValue &  threadId,
const QScriptValue &  function 
)

Starts a thread with given threadId.

Parameters
function- a thread routine
void Threading::threadFinished ( const QString &  id)

Designed to be called from a thread that's finished execution.

void trikScriptRunner::Threading::variablesReady ( const QJsonObject &  data)
signal

Emitted when variables values are ready.

Parameters
json- JSON container for variables values
void Threading::waitForAll ( )

Wait until all threads finish execution.

During this function execution other events can be processed.

void Threading::waitForAllYielding ( )

Wait until all threads finish execution.

During this function execution other events can not be processed, they will be processed after.


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