Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qscnetworkreachabilitynetworkinformationbackend.mm
Go to the documentation of this file.
1// Copyright (C) 2021 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#include <QtNetwork/private/qnetworkinformation_p.h>
5
6#include <QtNetwork/private/qnetconmonitor_p.h>
7
8#include <QtCore/qglobal.h>
9#include <QtCore/private/qobject_p.h>
10
13Q_LOGGING_CATEGORY(lcNetInfoSCR, "qt.network.info.scnetworkreachability");
14
20
22{
24public:
27
28 QString name() const override { return backendName(); }
29 QNetworkInformation::Features featuresSupported() const override
30 {
32 }
33
34 static QNetworkInformation::Features featuresSupportedStatic()
35 {
36 return QNetworkInformation::Features(QNetworkInformation::Feature::Reachability
37#ifdef QT_PLATFORM_UIKIT
39#endif
40 );
41 }
42
43private Q_SLOTS:
44 void reachabilityChanged(bool isOnline);
45
46#ifdef QT_PLATFORM_UIKIT
47 void isWwanChanged(bool isOnline);
48#endif
49
50private:
52
55};
56
58{
62public:
65 QString name() const override { return backendName(); }
66 QNetworkInformation::Features featuresSupported() const override
67 {
69 }
70
71 QNetworkInformationBackend *create(QNetworkInformation::Features requiredFeatures) const override
72 {
73 if ((requiredFeatures & featuresSupported()) != requiredFeatures)
74 return nullptr;
76 }
77
78private:
80};
81
83{
84 bool isOnline = false;
85#ifdef QT_PLATFORM_UIKIT
86 bool isWwan = false;
87#endif
88 if (ipv4Probe.setTargets(QHostAddress::AnyIPv4, {})) {
89 // We manage to create SCNetworkReachabilityRef for IPv4, let's
90 // read the last known state then!
91 isOnline |= ipv4Probe.isReachable();
92#ifdef QT_PLATFORM_UIKIT
93 isWwan |= ipv4Probe.isWwan();
94#endif
95 ipv4Probe.startMonitoring();
96 }
97
98 if (ipv6Probe.setTargets(QHostAddress::AnyIPv6, {})) {
99 // We manage to create SCNetworkReachability ref for IPv6, let's
100 // read the last known state then!
101 isOnline |= ipv6Probe.isReachable();
102#ifdef QT_PLATFORM_UIKIT
103 isWwan |= ipv6Probe.isWwan();
104#endif
105 ipv6Probe.startMonitoring();
106 }
107 reachabilityChanged(isOnline);
108#ifdef QT_PLATFORM_UIKIT
109 isWwanChanged(isWwan);
110#endif
111
113 &QSCNetworkReachabilityNetworkInformationBackend::reachabilityChanged,
116 &QSCNetworkReachabilityNetworkInformationBackend::reachabilityChanged,
118
119#ifdef QT_PLATFORM_UIKIT
120 connect(&ipv4Probe, &QNetworkConnectionMonitor::isWwanChanged, this,
121 &QSCNetworkReachabilityNetworkInformationBackend::isWwanChanged,
123 connect(&ipv6Probe, &QNetworkConnectionMonitor::isWwanChanged, this,
124 &QSCNetworkReachabilityNetworkInformationBackend::isWwanChanged,
126#endif
127}
128
132
133void QSCNetworkReachabilityNetworkInformationBackend::reachabilityChanged(bool isOnline)
134{
136 : QNetworkInformation::Reachability::Disconnected);
137}
138
139#ifdef QT_PLATFORM_UIKIT
140void QSCNetworkReachabilityNetworkInformationBackend::isWwanChanged(bool isWwan)
141{
142 // The reachability API from Apple only has one entry regarding transport medium: "IsWWAN"[0].
143 // This is _serviceable_ on iOS where the only other credible options are "WLAN" or
144 // "Disconnected". But on macOS you could be connected by Ethernet as well, so how would that be
145 // reported? It doesn't matter anyway since "IsWWAN" is not available on macOS.
146 // [0]: https://developer.apple.com/documentation/systemconfiguration/scnetworkreachabilityflags/kscnetworkreachabilityflagsiswwan?language=objc
149 } else {
151 : QNetworkInformation::TransportMedium::WiFi);
152 }
153}
154#endif
155
157
158#include "qscnetworkreachabilitynetworkinformationbackend.moc"
bool setTargets(const QHostAddress &local, const QHostAddress &remote)
void reachabilityChanged(bool isOnline)
QNetworkInformationBackendFactory provides the interface for creating instances of QNetworkInformatio...
QNetworkInformationBackend provides the interface with which QNetworkInformation does all of its actu...
static constexpr int PluginNamesAppleIndex
void setTransportMedium(TransportMedium medium)
static const char16_t PluginNames[4][22]
Reachability reachability() const
void setReachability(QNetworkInformation::Reachability reachability)
Call this when reachability has changed.
\inmodule QtNetwork
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
QNetworkInformationBackend * create(QNetworkInformation::Features requiredFeatures) const override
Create and return an instance of QNetworkInformationBackend.
QString name() const override
Backend name, return the same in QNetworkInformationBackend::name().
QNetworkInformation::Features featuresSupported() const override
Features supported, return the same in QNetworkInformationBackend::featuresSupported().
QNetworkInformation::Features featuresSupported() const override
Features supported, return the same in QNetworkInformationBackendFactory::featuresSupported().
QString name() const override
Backend name, return the same in QNetworkInformationBackendFactory::name().
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromUtf16(const char16_t *, qsizetype size=-1)
Definition qstring.cpp:6045
Combined button and popup list for selecting options.
@ QueuedConnection
#define Q_LOGGING_CATEGORY(name,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
#define QNetworkInformationBackendFactory_iid
#define Q_OBJECT
#define Q_PLUGIN_METADATA(x)
#define Q_INTERFACES(x)
#define Q_SLOTS
QHostInfo info
[0]