2019-11-20 00:11:30 -05:00
|
|
|
/**
|
|
|
|
|
* This file is part of JS8Call.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
* (C) 2019 Jordan Sherer <kn4crd@gmail.com> - All Rights Reserved
|
|
|
|
|
*
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
#include "Decoder.h"
|
|
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
#include "JS8_Include/commons.h"
|
2019-11-20 00:11:30 -05:00
|
|
|
|
2025-10-12 03:34:27 +02:00
|
|
|
#include <QLoggingCategory>
|
2019-11-20 00:11:30 -05:00
|
|
|
#include <QTimer>
|
|
|
|
|
|
2025-10-12 03:34:27 +02:00
|
|
|
Q_DECLARE_LOGGING_CATEGORY(decoder_js8)
|
|
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
Do not let youself be confused
|
|
|
|
|
: This source file does not presently take part in the build.
|
2019-11-20 00:11:30 -05:00
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
Decoder::Decoder(QObject * parent)
|
|
|
|
|
: QObject(parent) {}
|
2019-11-20 00:11:30 -05:00
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
Decoder::~Decoder() {}
|
2019-11-20 00:11:30 -05:00
|
|
|
|
|
|
|
|
//
|
2026-01-01 15:12:24 -06:00
|
|
|
void Decoder::lock() {
|
2019-11-20 00:11:30 -05:00
|
|
|
// NOOP
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
2026-01-01 15:12:24 -06:00
|
|
|
void Decoder::unlock() {
|
2019-11-20 00:11:30 -05:00
|
|
|
// NOOP
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
2026-01-01 15:12:24 -06:00
|
|
|
Worker *Decoder::createWorker() {
|
2019-11-20 00:11:30 -05:00
|
|
|
auto worker = new Worker();
|
|
|
|
|
worker->moveToThread(&m_thread);
|
|
|
|
|
connect(&m_thread, &QThread::finished, worker, &QObject::deleteLater);
|
|
|
|
|
connect(this, &Decoder::startWorker, worker, &Worker::start);
|
|
|
|
|
connect(this, &Decoder::quitWorker, worker, &Worker::quit);
|
2019-11-22 14:20:05 -05:00
|
|
|
connect(worker, &Worker::ready, this, &Decoder::processReady);
|
|
|
|
|
connect(worker, &Worker::error, this, &Decoder::processError);
|
|
|
|
|
connect(worker, &Worker::finished, this, &Decoder::processFinished);
|
2019-11-20 00:11:30 -05:00
|
|
|
return worker;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
2026-01-01 15:12:24 -06:00
|
|
|
void Decoder::start(QThread::Priority priority) { m_thread.start(priority); }
|
2019-11-20 00:11:30 -05:00
|
|
|
|
|
|
|
|
//
|
2026-01-01 15:12:24 -06:00
|
|
|
void Decoder::quit() { m_thread.quit(); }
|
2019-11-20 00:11:30 -05:00
|
|
|
|
|
|
|
|
//
|
2026-01-01 15:12:24 -06:00
|
|
|
bool Decoder::wait() { return m_thread.wait(); }
|
2019-11-20 00:11:30 -05:00
|
|
|
|
|
|
|
|
//
|
2026-01-01 15:12:24 -06:00
|
|
|
void Decoder::processStart(QString path, QStringList args) {
|
|
|
|
|
if (m_worker.isNull()) {
|
2019-11-20 00:11:30 -05:00
|
|
|
m_worker = createWorker();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit startWorker(path, args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
2026-01-01 15:12:24 -06:00
|
|
|
void Decoder::processReady(QByteArray t) { emit ready(t); }
|
2019-11-20 00:11:30 -05:00
|
|
|
|
|
|
|
|
//
|
2026-01-01 15:12:24 -06:00
|
|
|
void Decoder::processQuit() { emit quitWorker(); }
|
2019-11-20 00:11:30 -05:00
|
|
|
|
2019-11-22 14:20:05 -05:00
|
|
|
//
|
2026-01-01 15:12:24 -06:00
|
|
|
void Decoder::processError(int errorCode, QString errorString) {
|
|
|
|
|
qCDebug(decoder_js8) << "decoder process error" << errorCode << errorString;
|
2019-11-22 15:00:06 -05:00
|
|
|
emit error(errorCode, errorString);
|
2019-11-22 14:20:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
2026-01-01 15:12:24 -06:00
|
|
|
void Decoder::processFinished(int exitCode, int statusCode,
|
|
|
|
|
QString errorString) {
|
|
|
|
|
qCDebug(decoder_js8) << "decoder process finished" << exitCode << statusCode
|
|
|
|
|
<< errorString;
|
2019-11-22 15:00:06 -05:00
|
|
|
emit finished(exitCode, statusCode, errorString);
|
2019-11-22 14:20:05 -05:00
|
|
|
}
|
|
|
|
|
|
2019-11-20 00:11:30 -05:00
|
|
|
////////////////////////////////////////
|
|
|
|
|
//////////////// WORKER ////////////////
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//
|
2026-01-01 15:12:24 -06:00
|
|
|
Worker::~Worker() {}
|
2019-11-20 00:11:30 -05:00
|
|
|
|
|
|
|
|
//
|
2026-01-01 15:12:24 -06:00
|
|
|
void Worker::setProcess(QProcess *proc, int msecs) {
|
|
|
|
|
if (!m_proc.isNull()) {
|
2019-11-20 00:11:30 -05:00
|
|
|
bool b = m_proc->waitForFinished(msecs);
|
2026-01-01 15:12:24 -06:00
|
|
|
if (!b)
|
|
|
|
|
m_proc->close();
|
2019-11-20 00:11:30 -05:00
|
|
|
m_proc.reset();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
if (proc) {
|
2019-11-20 00:11:30 -05:00
|
|
|
m_proc.reset(proc);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
2026-01-01 15:12:24 -06:00
|
|
|
void Worker::start(QString path, QStringList args) {
|
|
|
|
|
qCDebug(decoder_js8) << "decoder process starting...";
|
2019-11-20 00:11:30 -05:00
|
|
|
|
|
|
|
|
auto proc = new QProcess(this);
|
|
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
connect(proc, &QProcess::readyReadStandardOutput, [this, proc]() {
|
|
|
|
|
while (proc->canReadLine()) {
|
|
|
|
|
emit ready(proc->readLine());
|
|
|
|
|
}
|
|
|
|
|
});
|
2019-11-20 00:11:30 -05:00
|
|
|
|
2024-08-31 09:40:28 -07:00
|
|
|
connect(proc, &QProcess::errorOccurred,
|
2026-01-01 15:12:24 -06:00
|
|
|
[this, proc](QProcess::ProcessError errorCode) {
|
|
|
|
|
emit error(int(errorCode), proc->errorString());
|
2019-11-20 00:11:30 -05:00
|
|
|
});
|
|
|
|
|
|
2024-08-31 10:48:53 -07:00
|
|
|
connect(proc, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
2026-01-01 15:12:24 -06:00
|
|
|
[this, proc](int exitCode, QProcess::ExitStatus status) {
|
|
|
|
|
emit finished(exitCode, int(status),
|
|
|
|
|
QString{proc->readAllStandardError()});
|
2019-11-20 00:11:30 -05:00
|
|
|
});
|
|
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
QProcessEnvironment env{QProcessEnvironment::systemEnvironment()};
|
|
|
|
|
env.insert("OMP_STACKSIZE", "4M");
|
|
|
|
|
proc->setProcessEnvironment(env);
|
2019-11-20 00:11:30 -05:00
|
|
|
proc->start(path, args, QIODevice::ReadWrite | QIODevice::Unbuffered);
|
|
|
|
|
|
|
|
|
|
setProcess(proc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
2026-01-01 15:12:24 -06:00
|
|
|
void Worker::quit() { setProcess(nullptr); }
|
2025-10-12 03:34:26 +02:00
|
|
|
|
|
|
|
|
Q_LOGGING_CATEGORY(decoder_js8, "decoder.js8", QtWarningMsg)
|