File: Decoder.h

package info (click to toggle)
js8call 2.5.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,720 kB
  • sloc: cpp: 562,655; sh: 898; python: 132; ansic: 102; makefile: 4
file content (90 lines) | stat: -rw-r--r-- 2,022 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#ifndef DECODER_H
#define DECODER_H

/**
 * (C) 2019 Jordan Sherer <kn4crd@gmail.com> - All Rights Reserved
 **/

#include "JS8_Main/ProcessThread.h"

#include <QByteArray>
#include <QLoggingCategory>
#include <QPointer>
#include <QProcess>

class Worker : public QObject {
    Q_OBJECT
  public:
    ~Worker();
  public slots:
    void start(QString path, QStringList args);
    void quit();

    QProcess *process() const { return m_proc.data(); }

  private:
    void setProcess(QProcess *proc, int msecs = 1000);

  signals:
    void ready(QByteArray t);
    void error(int errorCode, QString errorString);
    void finished(int exitCode, int statusCode, QString errorString);

  private:
    QScopedPointer<QProcess> m_proc;
};

class Decoder : public QObject {
    Q_OBJECT
  public:
    Decoder(QObject *parent = nullptr);
    ~Decoder();

    void lock();
    void unlock();

    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 {};
    }

  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();

    void processError(int errorCode, QString errorString);
    void processFinished(int exitCode, int statusCode, QString errorString);

  signals:
    void startWorker(QString path, QStringList args);
    void quitWorker();

    void ready(QByteArray t);
    void error(int errorCode, QString errorString);
    void finished(int exitCode, int statusCode, QString errorString);

  private:
    QPointer<Worker> m_worker;
    QThread m_thread;
};

Q_DECLARE_LOGGING_CATEGORY(decoder_js8)

#endif // DECODER_H