summaryrefslogtreecommitdiff
path: root/gui/retracer.h
blob: 1b5a4bd04313ed0ed3406eb42588397583bdc60f (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef RETRACER_H
#define RETRACER_H

#include <QThread>
#include <QProcess>

class ApiTraceState;
namespace QJson {
    class Parser;
}

struct RetraceError {
    int callIndex;
    QString type;
    QString message;
};

/* internal class used by the retracer to run
 * in the thread */
class RetraceProcess : public QObject
{
    Q_OBJECT
public:
    RetraceProcess(QObject *parent=0);
    ~RetraceProcess();

    QProcess *process() const;

    QString fileName() const;
    void setFileName(const QString &name);

    bool isBenchmarking() const;
    void setBenchmarking(bool bench);

    bool isDoubleBuffered() const;
    void setDoubleBuffered(bool db);

    void setCaptureAtCallNumber(qlonglong num);
    qlonglong captureAtCallNumber() const;

    bool captureState() const;
    void setCaptureState(bool enable);

public slots:
    void start();
    void terminate();

signals:
    void finished(const QString &output);
    void error(const QString &msg);
    void foundState(const ApiTraceState &state);
    void retraceErrors(const QList<RetraceError> &errors);

private slots:
    void replayFinished();
    void replayError(QProcess::ProcessError err);

private:
    QString m_fileName;
    bool m_benchmarking;
    bool m_doubleBuffered;
    bool m_captureState;
    qlonglong m_captureCall;

    QProcess *m_process;
    QJson::Parser *m_jsonParser;
};

class Retracer : public QThread
{
    Q_OBJECT
public:
    Retracer(QObject *parent=0);

    QString fileName() const;
    void setFileName(const QString &name);

    bool isBenchmarking() const;
    void setBenchmarking(bool bench);

    bool isDoubleBuffered() const;
    void setDoubleBuffered(bool db);

    void setCaptureAtCallNumber(qlonglong num);
    qlonglong captureAtCallNumber() const;

    bool captureState() const;
    void setCaptureState(bool enable);

signals:
    void finished(const QString &output);
    void foundState(const ApiTraceState &state);
    void error(const QString &msg);
    void retraceErrors(const QList<RetraceError> &errors);

protected:
    virtual void run();

private slots:
    void cleanup();
private:
    QString m_fileName;
    bool m_benchmarking;
    bool m_doubleBuffered;
    bool m_captureState;
    qlonglong m_captureCall;

    QProcessEnvironment m_processEnvironment;
};

#endif