Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qapplenetworkinformationbackend.mm
Go to the documentation of this file.
1// Copyright (C) 2024 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
11QT_BEGIN_NAMESPACE
12Q_DECLARE_LOGGING_CATEGORY(lcNetInfoSCR)
13Q_LOGGING_CATEGORY(lcNetInfoSCR, "qt.network.info.applenetworkinfo");
14
16{
17 return QString::fromUtf16(QNetworkInformationBackend::PluginNames
18 [QNetworkInformationBackend::PluginNamesAppleIndex]);
19}
20
22{
24public:
27
28 QString name() const override { return backendName(); }
30 {
31 return featuresSupportedStatic();
32 }
33
35 {
36 return QNetworkInformation::Features(QNetworkInformation::Feature::Reachability
37 | QNetworkInformation::Feature::TransportMedium);
38 }
39
40private Q_SLOTS:
42 void interfaceTypeChanged(QNetworkConnectionMonitor::InterfaceType type);
43
44private:
46
48};
49
51{
52 Q_OBJECT
53 Q_PLUGIN_METADATA(IID QNetworkInformationBackendFactory_iid)
55public:
58 QString name() const override { return backendName(); }
60 {
61 return QAppleNetworkInformationBackend::featuresSupportedStatic();
62 }
63
65 QNetworkInformation::Features requiredFeatures) const override
66 {
67 if ((requiredFeatures & featuresSupported()) != requiredFeatures)
68 return nullptr;
70 }
71
72private:
74};
75
76QAppleNetworkInformationBackend::QAppleNetworkInformationBackend()
77{
78 connect(&probe, &QNetworkConnectionMonitor::reachabilityChanged, this,
79 &QAppleNetworkInformationBackend::reachabilityChanged,
80 Qt::QueuedConnection);
81 connect(&probe, &QNetworkConnectionMonitor::interfaceTypeChanged, this,
82 &QAppleNetworkInformationBackend::interfaceTypeChanged,
83 Qt::QueuedConnection);
84 probe.startMonitoring();
85}
86
90
91void QAppleNetworkInformationBackend::reachabilityChanged(bool isOnline)
92{
93 setReachability(isOnline ? QNetworkInformation::Reachability::Online
94 : QNetworkInformation::Reachability::Disconnected);
95}
96
97void QAppleNetworkInformationBackend::interfaceTypeChanged(
98 QNetworkConnectionMonitor::InterfaceType type)
99{
100
101 if (reachability() == QNetworkInformation::Reachability::Disconnected) {
102 setTransportMedium(QNetworkInformation::TransportMedium::Unknown);
103 } else {
104 switch (type) {
105 case QNetworkConnectionMonitor::InterfaceType::Ethernet:
106 setTransportMedium(QNetworkInformation::TransportMedium::Ethernet);
107 break;
108 case QNetworkConnectionMonitor::InterfaceType::Cellular:
109 setTransportMedium(QNetworkInformation::TransportMedium::Cellular);
110 break;
111 case QNetworkConnectionMonitor::InterfaceType::WiFi:
112 setTransportMedium(QNetworkInformation::TransportMedium::WiFi);
113 break;
114 case QNetworkConnectionMonitor::InterfaceType::Unknown:
115 setTransportMedium(QNetworkInformation::TransportMedium::Unknown);
116 break;
117 }
118 }
119}
120
121QT_END_NAMESPACE
122
123#include "qapplenetworkinformationbackend.moc"
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().
QNetworkInformationBackend * create(QNetworkInformation::Features requiredFeatures) const override
Create and return an instance of QNetworkInformationBackend.
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().
static QNetworkInformation::Features featuresSupportedStatic()
static QString backendName()