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
4#ifndef QNETCONMONITOR_P_H
5#define QNETCONMONITOR_P_H
6
7#include <private/qtnetworkglobal_p.h>
8
9#include <QtCore/qloggingcategory.h>
10#include <QtNetwork/qhostaddress.h>
11#include <QtCore/qglobal.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 QNetworkConnectionMonitor();
34 QNetworkConnectionMonitor(const QHostAddress &local, const QHostAddress &remote = {});
35 ~QNetworkConnectionMonitor();
36
37 bool setTargets(const QHostAddress &local, const QHostAddress &remote);
38 bool isReachable();
39
40#ifdef QT_PLATFORM_UIKIT
41 bool isWwan() const;
42#endif
43
44 // Important: on Darwin you should not call isReachable/isWwan() after
45 // startMonitoring(), you have to listen to reachabilityChanged()
46 // signal instead.
47 bool startMonitoring();
48 bool isMonitoring() const;
49 void stopMonitoring();
50
51 static bool isEnabled();
52
53Q_SIGNALS:
54 // Important: connect to this using QueuedConnection. On Darwin
55 // callback is coming on a special dispatch queue.
56 void reachabilityChanged(bool isOnline);
57
58#ifdef QT_PLATFORM_UIKIT
59 void isWwanChanged(bool isWwan);
60#endif
61
62private:
63 Q_DECLARE_PRIVATE(QNetworkConnectionMonitor)
64 Q_DISABLE_COPY_MOVE(QNetworkConnectionMonitor)
65};
66
67Q_DECLARE_LOGGING_CATEGORY(lcNetMon)
68
69QT_END_NAMESPACE
70
71#endif // QNETCONMONITOR_P_H
72

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