trikRuntime
scriptThread.h
Go to the documentation of this file.
1 /* Copyright 2014 CyberTech Labs Ltd.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License. */
14 
15 #pragma once
16 
17 #include <QtCore/QThread>
18 #include <QtScript/QScriptEngine>
19 
20 namespace trikScriptRunner {
21 
22 class Threading;
23 
25 class ScriptThread : public QThread
26 {
27  Q_OBJECT
28 
29 public:
34  ScriptThread(Threading &threading, const QString &id, QScriptEngine *engine, const QString &script);
35 
36  ~ScriptThread() override;
37 
39  void abort();
40 
42  QString id() const;
43 
45  QString error() const;
46 
48  bool isEvaluating() const;
49 
50 signals:
52  void stopRunning();
53 
56  void variablesReady(const QJsonObject &json);
57 
58 public slots:
61  void onGetVariables(const QString &propertyName);
62 
63 protected:
64  void run() override;
65 
66 private:
67  QString mId;
68 
70  QScriptEngine *mEngine;
71  QString mScript;
72 
73  Threading &mThreading;
74 
75  QString mError;
76 };
77 
78 }
bool isEvaluating() const
Definition: scriptThread.cpp:79
Definition: trikCommunicator.h:23
Designed to support OS threads from a Qt Script.
Definition: threading.h:34
Thread object which executes a script with a QScriptEngine.
Definition: scriptThread.h:25
QString id() const
Definition: scriptThread.cpp:69
void stopRunning()
Emitted when event loop must be stopped.
QString error() const
Definition: scriptThread.cpp:74
~ScriptThread() override
Definition: scriptThread.cpp:35
ScriptThread(Threading &threading, const QString &id, QScriptEngine *engine, const QString &script)
Constructor.
Definition: scriptThread.cpp:27
void abort()
Aborts execution. Asynchronous: a thread will not be finished on return from this function...
Definition: scriptThread.cpp:63
void run() override
Definition: scriptThread.cpp:39
void variablesReady(const QJsonObject &json)
Emitted when variables values are ready.
void onGetVariables(const QString &propertyName)
Catch variables values from current script execution.
Definition: scriptThread.cpp:86
script
Definition: system.py:83