17 #include <QtCore/QQueue> 18 #include <QtCore/QThread> 19 #include <QtCore/QMutex> 20 #include <QtCore/QWaitCondition> 21 #include <QtCore/QSet> 23 #include <QtScript/QScriptEngine> 29 class ScriptEngineWorker;
48 Q_INVOKABLE
void startThread(
const QScriptValue &threadId,
const QScriptValue &
function);
51 Q_INVOKABLE
void joinThread(
const QString &threadId);
55 Q_INVOKABLE
void sendMessage(
const QString &threadId,
const QScriptValue &message);
58 Q_INVOKABLE QScriptValue
receiveMessage(
bool waitForMessage =
true);
61 Q_INVOKABLE
void killThread(
const QString &threadId);
73 Q_INVOKABLE
void reset();
100 void startThread(
const QString &threadId, QScriptEngine *engine,
const QString &script);
104 QScriptEngine *cloneEngine(QScriptEngine *engine);
109 QHash<QString, ScriptThread *> mThreads;
110 QSet<QString> mFinishedThreads;
111 QSet<QString> mPreventFromStart;
112 QMutex mThreadsMutex;
113 QString mErrorMessage;
115 QHash<QString, QQueue<QScriptValue>> mMessageQueues;
116 QMutex mMessageMutex;
117 QHash<QString, QMutex *> mMessageQueueMutexes;
118 QHash<QString, QWaitCondition *> mMessageQueueConditions;
120 bool mResetStarted =
false;
127 QScriptEngine *mMainScriptEngine;
128 const QString mMainThreadName =
"main";
Q_INVOKABLE void killThread(const QString &threadId)
Stops given thread.
Definition: threading.cpp:288
Q_INVOKABLE QScriptValue receiveMessage(bool waitForMessage=true)
Designed to be called from a thread receiving a message.
Definition: threading.cpp:249
~Threading() override
Definition: threading.cpp:38
QString errorMessage() const
The last error message.
Definition: threading.cpp:312
Q_INVOKABLE void joinThread(const QString &threadId)
Joins a thread with given threadId. Does nothing if there is no thread with such id.
Definition: threading.cpp:133
void variablesReady(const QJsonObject &data)
Emitted when variables values are ready.
Definition: trikCommunicator.h:23
Q_INVOKABLE void startThread(const QScriptValue &threadId, const QScriptValue &function)
Starts a thread with given threadId.
Definition: threading.cpp:57
Designed to support OS threads from a Qt Script.
Definition: threading.h:34
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.
Definition: threading.cpp:230
Q_INVOKABLE void reset()
Aborts evalutation of all threads, resets to initial state.
Definition: threading.cpp:166
bool inEventDrivenMode() const
Returns true if the script is being evaluated in event-driven mode.
Definition: threading.cpp:327
void waitForAll()
Wait until all threads finish execution.
Definition: threading.cpp:114
Threading(ScriptEngineWorker *scriptWorker, ScriptExecutionControl &scriptControl)
Constructs a Threading object with given script worker as a parent.
Definition: threading.cpp:29
Worker object to be run in a separate thread for Qt Script execution.
Definition: scriptEngineWorker.h:35
void waitForAllYielding()
Wait until all threads finish execution.
Definition: threading.cpp:126
void finished()
Signals that all threads have finished.
void threadFinished(const QString &id)
Designed to be called from a thread that's finished execution.
Definition: threading.cpp:205
Script execution controller, provides related functions to scripts.
Definition: scriptExecutionControl.h:24
void startMainThread(const QString &script)
Starts the main thread of a script.
Definition: threading.cpp:43
void getVariables(const QString &propertyName)
Emitted when there is a request for variables values.
script
Definition: system.py:83