summaryrefslogtreecommitdiff
path: root/src/plugins/boot2qt/device-detection/qdbwatcher.h
blob: c609627d7d546485ece2cec01246bdf937ed7f7d (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
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#pragma once

#include <QLocalSocket>
#include <QMutex>
#include <QObject>

#include <memory>

enum class RequestType;
QT_BEGIN_NAMESPACE
class QJsonDocument;
QT_END_NAMESPACE

namespace Qdb::Internal {

class QdbWatcher : public QObject
{
    Q_OBJECT

public:
    QdbWatcher(QObject *parent = nullptr);
    virtual ~QdbWatcher();
    void stop();
    void start(RequestType requestType);

signals:
    void incomingMessage(const QJsonDocument &);
    void watcherError(const QString &);

private:
    void startPrivate();

private:
    void handleWatchConnection();
    void handleWatchError(QLocalSocket::LocalSocketError error);
    void handleWatchMessage();
    static void forkHostServer();
    void retry();

    static QMutex s_startMutex;
    static bool s_startedServer;

    std::unique_ptr<QLocalSocket> m_socket = nullptr;
    bool m_shuttingDown = false;
    bool m_retried = false;
    RequestType m_requestType;
};

} // Qdb::Internal