trikRuntime
trikScriptRunner.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 <QFileInfo>
19 #include <QScopedPointer>
20 #include <array>
23 
24 namespace trikScriptRunner {
25 
28 {
29  Q_OBJECT
30 public:
36  );
37 
38  ~TrikScriptRunner() override;
39 
41  void setDefaultRunner(ScriptType t);
42 
43  void registerUserFunction(const QString &name, QScriptEngine::FunctionSignature function) override;
44  void addCustomEngineInitStep(const std::function<void (QScriptEngine *)> &step) override;
45  bool wasError() override;
46 
48  QStringList knownMethodNamesFor(ScriptType t);
49 
51  QStringList knownMethodNames() const override;
53  void run(const QString &script, ScriptType stype, const QString &fileName = "");
54 
55 public slots:
57  void run(const QString &script, const QString &fileName = "") override;
59  void runDirectCommand(const QString &command) override;
61  void abort() override;
63  void abortAll();
65  void brickBeep() override;
66 
67 private:
68  TrikScriptRunnerInterface * fetchRunner(ScriptType stype);
69 
72  std::array<QScopedPointer<TrikScriptRunnerInterface>, to_underlying(ScriptType::Size)> mScriptRunnerArray;
73  ScriptType mLastRunner;
74 };
75 
76 }
#define TRIKSCRIPTRUNNER_EXPORT
Definition: trikScriptRunnerInterface.h:28
Definition: trikCommunicator.h:23
General wrapper for other executors (such as Python, JavaScript)
Definition: trikScriptRunner.h:27
Interface for all script executors.
Definition: trikScriptRunnerInterface.h:100
ScriptType
Definition: trikScriptRunnerInterface.h:87
static constexpr std::underlying_type< ScriptType >::type to_underlying(ScriptType t) noexcept
Definition: trikScriptRunnerInterface.h:94
Allows communication between robots.
Definition: mailboxInterface.h:31
script
Definition: system.py:83
Interface representing TRIK controller board and devices installed on it, also provides access to per...
Definition: brickInterface.h:46