2019-11-20 00:11:30 -05:00
|
|
|
#ifndef DECODER_H
|
|
|
|
|
#define DECODER_H
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* (C) 2019 Jordan Sherer <kn4crd@gmail.com> - All Rights Reserved
|
|
|
|
|
**/
|
|
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
#include "JS8_Main/ProcessThread.h"
|
2019-11-20 00:11:30 -05:00
|
|
|
|
|
|
|
|
#include <QByteArray>
|
2026-01-01 15:12:24 -06:00
|
|
|
#include <QLoggingCategory>
|
2019-11-20 00:11:30 -05:00
|
|
|
#include <QPointer>
|
|
|
|
|
#include <QProcess>
|
|
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
class Worker : public QObject {
|
2019-11-20 00:11:30 -05:00
|
|
|
Q_OBJECT
|
2026-01-01 15:12:24 -06:00
|
|
|
public:
|
2019-11-20 00:11:30 -05:00
|
|
|
~Worker();
|
2026-01-01 15:12:24 -06:00
|
|
|
public slots:
|
2019-11-20 00:11:30 -05:00
|
|
|
void start(QString path, QStringList args);
|
|
|
|
|
void quit();
|
|
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
QProcess *process() const { return m_proc.data(); }
|
2019-11-20 00:11:30 -05:00
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
private:
|
|
|
|
|
void setProcess(QProcess *proc, int msecs = 1000);
|
|
|
|
|
|
|
|
|
|
signals:
|
2019-11-20 00:11:30 -05:00
|
|
|
void ready(QByteArray t);
|
2019-11-22 15:00:06 -05:00
|
|
|
void error(int errorCode, QString errorString);
|
|
|
|
|
void finished(int exitCode, int statusCode, QString errorString);
|
2019-11-20 00:11:30 -05:00
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
private:
|
2019-11-20 00:11:30 -05:00
|
|
|
QScopedPointer<QProcess> m_proc;
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
class Decoder : public QObject {
|
2019-11-20 00:11:30 -05:00
|
|
|
Q_OBJECT
|
2026-01-01 15:12:24 -06:00
|
|
|
public:
|
|
|
|
|
Decoder(QObject *parent = nullptr);
|
2019-11-20 00:11:30 -05:00
|
|
|
~Decoder();
|
|
|
|
|
|
|
|
|
|
void lock();
|
|
|
|
|
void unlock();
|
|
|
|
|
|
2019-11-22 15:00:06 -05:00
|
|
|
QString program() const {
|
2026-01-01 15:12:24 -06:00
|
|
|
if (!m_worker.isNull() && m_worker->process() != nullptr) {
|
2019-11-22 15:00:06 -05:00
|
|
|
return m_worker->process()->program();
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList arguments() const {
|
2026-01-01 15:12:24 -06:00
|
|
|
if (!m_worker.isNull() && m_worker->process() != nullptr) {
|
2019-11-22 15:00:06 -05:00
|
|
|
return m_worker->process()->arguments();
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
private:
|
|
|
|
|
Worker *createWorker();
|
2019-11-20 00:11:30 -05:00
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
public slots:
|
2019-11-20 00:11:30 -05:00
|
|
|
void start(QThread::Priority priority);
|
|
|
|
|
void quit();
|
|
|
|
|
bool wait();
|
|
|
|
|
|
|
|
|
|
void processStart(QString path, QStringList args);
|
|
|
|
|
void processReady(QByteArray t);
|
|
|
|
|
void processQuit();
|
|
|
|
|
|
2019-11-22 15:00:06 -05:00
|
|
|
void processError(int errorCode, QString errorString);
|
|
|
|
|
void processFinished(int exitCode, int statusCode, QString errorString);
|
2019-11-22 14:20:05 -05:00
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
signals:
|
2019-11-20 00:11:30 -05:00
|
|
|
void startWorker(QString path, QStringList args);
|
|
|
|
|
void quitWorker();
|
|
|
|
|
|
|
|
|
|
void ready(QByteArray t);
|
2019-11-22 15:00:06 -05:00
|
|
|
void error(int errorCode, QString errorString);
|
|
|
|
|
void finished(int exitCode, int statusCode, QString errorString);
|
2019-11-20 00:11:30 -05:00
|
|
|
|
2026-01-01 15:12:24 -06:00
|
|
|
private:
|
2019-11-20 00:11:30 -05:00
|
|
|
QPointer<Worker> m_worker;
|
|
|
|
|
QThread m_thread;
|
|
|
|
|
};
|
|
|
|
|
|
2025-10-12 03:34:26 +02:00
|
|
|
Q_DECLARE_LOGGING_CATEGORY(decoder_js8)
|
2019-11-20 00:11:30 -05:00
|
|
|
|
|
|
|
|
#endif // DECODER_H
|