trikRuntime
trikJavaScriptRunner.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 
18 #include "trikVariablesServer.h"
19 
20 namespace trikNetwork {
21 class MailboxInterface;
22 }
23 
24 namespace trikControl {
25 class BrickInterface;
26 }
27 
28 namespace trikScriptRunner {
29 
30 class ScriptEngineWorker;
31 class ScriptExecutionControl;
32 
35 {
36  Q_OBJECT
37 public:
43  );
44 
46 
47  void registerUserFunction(const QString &name, QScriptEngine::FunctionSignature function) override;
48  void addCustomEngineInitStep(const std::function<void (QScriptEngine *)> &step) override;
49 
50  QStringList knownMethodNames() const override;
51 
52  bool wasError() override { return false; }
53 
54 public slots:
55  void run(const QString &script, const QString &fileName = "") override;
56  void runDirectCommand(const QString &command) override;
57  void abort() override;
58  void brickBeep() override;
59 
60 private slots:
61  void onScriptStart(int scriptId);
62 
64  void sendMessageFromMailBox(int senderNumber, const QString &message);
65 
66 private:
67  QScopedPointer<ScriptExecutionControl> mScriptController;
68 
70  ScriptEngineWorker *mScriptEngineWorker;
71  QThread mWorkerThread;
72 
73  int mMaxScriptId;
74 
75  QHash<int, QString> mScriptFileNames;
76  QScopedPointer<TrikVariablesServer> mVariablesServer;
77 };
78 
79 }
Definition: trikCommunicator.h:23
Definition: trikCommunicator.h:31
Interface for all script executors.
Definition: trikScriptRunnerInterface.h:100
Worker object to be run in a separate thread for Qt Script execution.
Definition: scriptEngineWorker.h:35
Executes scripts in Qt Scripting Engine.
Definition: trikJavaScriptRunner.h:34
Definition: trikCommunicator.h:27
Allows communication between robots.
Definition: mailboxInterface.h:31
bool wasError() override
Get status of last direct command/script.
Definition: trikJavaScriptRunner.h:52
script
Definition: system.py:83
Interface representing TRIK controller board and devices installed on it, also provides access to per...
Definition: brickInterface.h:46