1// Copyright (C) 2019 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QNETCONMONITOR_P_H
6#define QNETCONMONITOR_P_H
7
8#include <private/qtnetworkglobal_p.h>
9
10#include <QtCore/qloggingcategory.h>
11#include <QtNetwork/qhostaddress.h>
12#include <QtCore/qobject.h>
13
14//
15// W A R N I N G
16// -------------
17//
18// This file is not part of the Qt API. It exists purely as an
19// implementation detail. This header file may change from version to
20// version without notice, or even be removed.
21//
22// We mean it.
23//
24
25QT_BEGIN_NAMESPACE
26
27class QNetworkConnectionMonitorPrivate;
28class Q_NETWORK_EXPORT QNetworkConnectionMonitor : public QObject
29{
30 Q_OBJECT
31
32public:
33#ifdef Q_OS_APPLE
34 enum class InterfaceType {
35 Unknown,
36 Ethernet,
37 Cellular,
38 WiFi,
39 };
40 Q_ENUM(InterfaceType)
41#endif
42
43 QNetworkConnectionMonitor();
44 QNetworkConnectionMonitor(const QHostAddress &local, const QHostAddress &remote = {});
45 ~QNetworkConnectionMonitor();
46
47 bool setTargets(const QHostAddress &local, const QHostAddress &remote);
48 bool isReachable();
49#ifdef Q_OS_APPLE
50 InterfaceType getInterfaceType() const;
51#endif
52
53 // Important: on Darwin you should not call isReachable/isWwan() after
54 // startMonitoring(), you have to listen to reachabilityChanged()
55 // signal instead.
56 bool startMonitoring();
57 bool isMonitoring() const;
58 void stopMonitoring();
59
60 static bool isEnabled();
61
62Q_SIGNALS:
63 // Important: connect to this using QueuedConnection. On Darwin
64 // callback is coming on a special dispatch queue.
65 void reachabilityChanged(bool isOnline);
66#ifdef Q_OS_APPLE
67 void interfaceTypeChanged(InterfaceType type);
68#endif
69
70private:
71 Q_DECLARE_PRIVATE(QNetworkConnectionMonitor)
72 Q_DISABLE_COPY_MOVE(QNetworkConnectionMonitor)
73};
74
75Q_DECLARE_LOGGING_CATEGORY(lcNetMon)
76
77QT_END_NAMESPACE
78
79#endif // QNETCONMONITOR_P_H
80

source code of qtbase/src/network/kernel/qnetconmonitor_p.h