JS8Call-Improved master
Loading...
Searching...
No Matches
Decoder.h
Go to the documentation of this file.
1
12
13#ifndef DECODER_H
14#define DECODER_H
15
16#include "JS8_Main/ProcessThread.h"
17
18#include <QByteArray>
19#include <QLoggingCategory>
20#include <QPointer>
21#include <QProcess>
22
32class Worker : public QObject {
33 Q_OBJECT
34 public:
36 ~Worker();
37
38 public slots:
44 void start(QString path, QStringList args);
45
47 void quit();
48
53 QProcess *process() const { return m_proc.data(); }
54
55 private:
61 void setProcess(QProcess *proc, int msecs = 1000);
62
63 signals:
65 void ready(QByteArray t);
66
68 void error(int errorCode, QString errorString);
69
71 void finished(int exitCode, int statusCode, QString errorString);
72
73 private:
74 QScopedPointer<QProcess> m_proc;
75};
76
86class Decoder : public QObject {
87 Q_OBJECT
88 public:
90 Decoder(QObject *parent = nullptr);
91
94
96 void lock();
97
99 void unlock();
100
105 QString program() const {
106 if (!m_worker.isNull() && m_worker->process() != nullptr) {
107 return m_worker->process()->program();
108 }
109 return {};
110 }
111
116 QStringList arguments() const {
117 if (!m_worker.isNull() && m_worker->process() != nullptr) {
118 return m_worker->process()->arguments();
119 }
120 return {};
121 }
122
123 private:
125 Worker *createWorker();
126
127 public slots:
129 void start(QThread::Priority priority);
130
132 void quit();
133
138 bool wait();
139
140 // Slots forwarded from the UI or internal code to control the process.
141 void processStart(QString path, QStringList args);
142 void processReady(QByteArray t);
143 void processQuit();
144
145 void processError(int errorCode, QString errorString);
146 void processFinished(int exitCode, int statusCode, QString errorString);
147
148 signals:
150 void startWorker(QString path, QStringList args);
153
155 void ready(QByteArray t);
157 void error(int errorCode, QString errorString);
159 void finished(int exitCode, int statusCode, QString errorString);
160
161 private:
162 QPointer<Worker> m_worker;
163 QThread m_thread;
164};
165
166Q_DECLARE_LOGGING_CATEGORY(decoder_js8)
167
168#endif // DECODER_H
void finished(int exitCode, int statusCode, QString errorString)
bool wait()
Wait for the worker to finish shutdown.
Definition Decoder.cpp:53
QString program() const
Return the program path of the managed decoder process.
Definition Decoder.h:105
void quit()
Definition Decoder.cpp:50
void lock()
void start(QThread::Priority priority)
Definition Decoder.cpp:47
Decoder(QObject *parent=nullptr)
void quitWorker()
void startWorker(QString path, QStringList args)
void unlock()
void error(int errorCode, QString errorString)
QStringList arguments() const
Return the argument list configured for the decoder process.
Definition Decoder.h:116
void ready(QByteArray t)
Manage an external decoder process and forward its I/O.
Definition Decoder.h:32
void ready(QByteArray t)
QProcess * process() const
Return the underlying QProcess instance, if any.
Definition Decoder.h:53
void error(int errorCode, QString errorString)
~Worker()
Definition Decoder.cpp:89
void start(QString path, QStringList args)
Launch the external decoder process.
Definition Decoder.cpp:106
void finished(int exitCode, int statusCode, QString errorString)
void quit()
Request the running process to quit.
Definition Decoder.cpp:137