diff --git a/trikControl/src/abstractVirtualSensorWorker.cpp b/trikControl/src/abstractVirtualSensorWorker.cpp index 74c3b3642..e58371325 100644 --- a/trikControl/src/abstractVirtualSensorWorker.cpp +++ b/trikControl/src/abstractVirtualSensorWorker.cpp @@ -29,10 +29,11 @@ using namespace trikControl; AbstractVirtualSensorWorker::AbstractVirtualSensorWorker(const QString &script, const QString &inputFile , const QString &outputFile, DeviceState &state, trikHal::HardwareAbstractionInterface &hardwareAbstraction) : mSystemConsole(hardwareAbstraction.systemConsole()) - , mOutputFifo(hardwareAbstraction.createFifo(outputFile)) , mScript(script) , mInputFile(hardwareAbstraction.createOutputDeviceFile(inputFile)) , mState(state) + , mHardwareAbstraction(hardwareAbstraction) + , mOutputFile(outputFile) { } @@ -59,6 +60,8 @@ void AbstractVirtualSensorWorker::stop() void AbstractVirtualSensorWorker::init() { + mOutputFifo.reset(mHardwareAbstraction.createFifo(mOutputFile)); + if (mState.isReady() && QFileInfo(mInputFile->fileName()).exists() && QFileInfo(mOutputFifo->fileName()).exists()) { // Sensor is up and ready. QLOG_ERROR() << "Trying to init video sensor that is already running, ignoring"; diff --git a/trikControl/src/abstractVirtualSensorWorker.h b/trikControl/src/abstractVirtualSensorWorker.h index 4135bd83d..d46adef1a 100644 --- a/trikControl/src/abstractVirtualSensorWorker.h +++ b/trikControl/src/abstractVirtualSensorWorker.h @@ -115,6 +115,12 @@ private slots: /// Current state of a device, shared between worker and proxy. DeviceState &mState; + + /// Reference to hardware abstraction needed to create FIFO objects in correct thread. + trikHal::HardwareAbstractionInterface &mHardwareAbstraction; + + /// Name of an output file. + const QString mOutputFile; }; } diff --git a/trikScriptRunner/src/threading.cpp b/trikScriptRunner/src/threading.cpp index 61e96e96a..9a630b216 100644 --- a/trikScriptRunner/src/threading.cpp +++ b/trikScriptRunner/src/threading.cpp @@ -42,8 +42,8 @@ void Threading::startMainThread(const QString &script) mFinishedThreads.clear(); mPreventFromStart.clear(); - QRegExp const mainRegexp("(.*var main\\s*=\\s*\\w*\\s*function\\(.*\\).*)|(.*function\\s+%1\\s*\\(.*\\).*)"); - bool needCallMain = mainRegexp.exactMatch(script) && !script.trimmed().endsWith("main();"); + const QRegExp mainRegexp("(.*var main\\s*=\\s*\\w*\\s*function\\(.*\\).*)|(.*function\\s+%1\\s*\\(.*\\).*)"); + const bool needCallMain = mainRegexp.exactMatch(script) && !script.trimmed().endsWith("main();"); startThread("main", mScriptWorker->createScriptEngine(), needCallMain ? script + "\nmain();" : script); } @@ -84,7 +84,7 @@ void Threading::startThread(const QString &threadId, QScriptEngine *engine, cons } QLOG_INFO() << "Starting new thread" << threadId << "with engine" << engine; - ScriptThread *thread = new ScriptThread(*this, threadId, engine, script); + ScriptThread * const thread = new ScriptThread(*this, threadId, engine, script); connect(&mScriptControl, SIGNAL(quitSignal()), thread, SIGNAL(stopRunning()), Qt::DirectConnection); mThreads[threadId] = thread; mFinishedThreads.remove(threadId);