2019-11-20 00:11:30 -05:00
|
|
|
#ifndef DECODER_H
|
|
|
|
#define DECODER_H
|
|
|
|
|
|
|
|
/**
|
|
|
|
* (C) 2019 Jordan Sherer <kn4crd@gmail.com> - All Rights Reserved
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "ProcessThread.h"
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QPointer>
|
|
|
|
#include <QProcess>
|
|
|
|
|
|
|
|
|
|
|
|
class Worker : public QObject{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
~Worker();
|
|
|
|
public slots:
|
|
|
|
void start(QString path, QStringList args);
|
|
|
|
void quit();
|
|
|
|
|
2019-11-22 15:00:06 -05:00
|
|
|
QProcess* process() const { return m_proc.data(); }
|
2019-11-20 00:11:30 -05:00
|
|
|
private:
|
|
|
|
void setProcess(QProcess *proc, int msecs=1000);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
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
|
|
|
|
|
|
|
private:
|
|
|
|
QScopedPointer<QProcess> m_proc;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Decoder: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
Decoder(QObject *parent=nullptr);
|
|
|
|
~Decoder();
|
|
|
|
|
|
|
|
void lock();
|
|
|
|
void unlock();
|
|
|
|
|
2019-11-22 15:00:06 -05:00
|
|
|
QString program() const {
|
|
|
|
if(!m_worker.isNull() && m_worker->process() != nullptr){
|
|
|
|
return m_worker->process()->program();
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
QStringList arguments() const {
|
|
|
|
if(!m_worker.isNull() && m_worker->process() != nullptr){
|
|
|
|
return m_worker->process()->arguments();
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-11-20 00:11:30 -05:00
|
|
|
private:
|
|
|
|
Worker* createWorker();
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
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
|
|
|
|
2019-11-20 00:11:30 -05:00
|
|
|
signals:
|
|
|
|
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
|
|
|
|
|
|
|
private:
|
|
|
|
QPointer<Worker> m_worker;
|
|
|
|
QThread m_thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // DECODER_H
|