summaryrefslogtreecommitdiff
path: root/src/plugins/projectexplorer/windebuginterface.h
blob: a9d78fc11159231ec66679238ab1d985f4164d29 (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
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include <QMap>
#include <QThread>

#include <map>
#include <mutex>
#include <vector>

namespace ProjectExplorer {
namespace Internal {

class WinDebugInterface : public QThread
{
    Q_OBJECT

public:
    explicit WinDebugInterface(QObject *parent = nullptr);
    ~WinDebugInterface() override;

    static WinDebugInterface *instance();

    static bool stop();
    static void startIfNeeded();

signals:
    void debugOutput(qint64 pid, const QString &message);
    void cannotRetrieveDebugOutput();
    void _q_debugOutputReady();

private:
    enum Handles { DataReadyEventHandle, TerminateEventHandle, HandleCount };

    void run() override;
    bool runLoop();
    void emitReadySignal();
    void dispatchDebugOutput();

    static WinDebugInterface *m_instance;

    qint64 m_creatorPid = -1;
    Qt::HANDLE m_waitHandles[HandleCount] = {};
    Qt::HANDLE m_bufferReadyEvent = nullptr;
    Qt::HANDLE m_sharedFile = nullptr;
    void *m_sharedMem = nullptr;
    std::mutex m_outputMutex;
    bool m_readySignalEmitted = false;
    std::map<qint64, std::vector<QString>> m_debugOutput;
};

} // namespace Internal
} // namespace ProjectExplorer