History

Added HelperScriptEngine class

Karol Suprynowicz committed 2 years ago

Commit 9f80c9d1 parent 93a243d10 files · +159 −134Browse files

Showing the changes to libraries/script-engine/src/HelperScriptEngine.cpp (1 of 10 files). Show all

Unified · Split

libraries/script-engine/src/HelperScriptEngine.cpp+31−0
@@ -0,0 +1,31 @@
1+//
2+// HelperScriptEngine.h
3+// libraries/script-engine/src/HelperScriptEngine.h
4+//
5+// Created by dr Karol Suprynowicz on 2024/04/28.
6+// Copyright 2024 Overte e.V.
7+//
8+// Distributed under the Apache License, Version 2.0.
9+// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10+//
11+
12+#include "HelperScriptEngine.h"
13+
14+HelperScriptEngine::HelperScriptEngine() {
15+ std::lock_guard<std::mutex> lock(_scriptEngineLock);
16+ _scriptEngine = newScriptEngine();
17+ _scriptEngineThread.reset(new QThread());
18+ _scriptEngine->setThread(_scriptEngineThread.get());
19+ _scriptEngineThread->start();
20+}
21+
22+HelperScriptEngine::~HelperScriptEngine() {
23+ std::lock_guard<std::mutex> lock(_scriptEngineLock);
24+ if (_scriptEngine) {
25+ if (_scriptEngineThread) {
26+ _scriptEngineThread->quit();
27+ _scriptEngineThread->wait();
28+ }
29+ _scriptEngine.reset();
30+ }
31+}