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
qnetworkinformation_p.h
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#ifndef QNETWORKINFORMATION_P_H
5#define QNETWORKINFORMATION_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of the Network Information API. This header file may change from
13// version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtNetwork/private/qtnetworkglobal_p.h>
19
20#include <QtNetwork/qnetworkinformation.h>
21
22#include <QtCore/qloggingcategory.h>
23#include <QtCore/qreadwritelock.h>
24
26
27class Q_NETWORK_EXPORT QNetworkInformationBackend : public QObject
28{
30
33
34public:
35 static inline const char16_t PluginNames[4][22] = {
36 { u"networklistmanager" },
37 { u"scnetworkreachability" },
38 { u"android" },
39 { u"networkmanager" },
40 };
41 static constexpr int PluginNamesWindowsIndex = 0;
42 static constexpr int PluginNamesAppleIndex = 1;
43 static constexpr int PluginNamesAndroidIndex = 2;
44 static constexpr int PluginNamesLinuxIndex = 3;
45
48
49 virtual QString name() const = 0;
50 virtual QNetworkInformation::Features featuresSupported() const = 0;
51
53 {
54 QReadLocker locker(&m_lock);
55 return m_reachability;
56 }
57
59 {
60 QReadLocker locker(&m_lock);
61 return m_behindCaptivePortal;
62 }
63
65 {
66 QReadLocker locker(&m_lock);
67 return m_transportMedium;
68 }
69
70 bool isMetered() const
71 {
72 QReadLocker locker(&m_lock);
73 return m_metered;
74 }
75
78 void behindCaptivePortalChanged(bool behindPortal);
80 void isMeteredChanged(bool isMetered);
81
82protected:
84 {
85 QWriteLocker locker(&m_lock);
86 if (m_reachability != reachability) {
87 m_reachability = reachability;
88 locker.unlock();
89 emit reachabilityChanged(reachability);
90 }
91 }
92
93 void setBehindCaptivePortal(bool behindPortal)
94 {
95 QWriteLocker locker(&m_lock);
96 if (m_behindCaptivePortal != behindPortal) {
97 m_behindCaptivePortal = behindPortal;
98 locker.unlock();
99 emit behindCaptivePortalChanged(behindPortal);
100 }
101 }
102
104 {
105 QWriteLocker locker(&m_lock);
106 if (m_transportMedium != medium) {
107 m_transportMedium = medium;
108 locker.unlock();
110 }
111 }
112
113 void setMetered(bool isMetered)
114 {
115 QWriteLocker locker(&m_lock);
116 if (m_metered != isMetered) {
117 m_metered = isMetered;
118 locker.unlock();
119 emit isMeteredChanged(isMetered);
120 }
121 }
122
123private:
124 mutable QReadWriteLock m_lock;
125 Reachability m_reachability = Reachability::Unknown;
126 TransportMedium m_transportMedium = TransportMedium::Unknown;
127 bool m_behindCaptivePortal = false;
128 bool m_metered = false;
129
130 Q_DISABLE_COPY_MOVE(QNetworkInformationBackend)
133};
134
135class Q_NETWORK_EXPORT QNetworkInformationBackendFactory : public QObject
136{
138
139 using Features = QNetworkInformation::Features;
140
141public:
144 virtual QString name() const = 0;
145 virtual QNetworkInformationBackend *create(Features requiredFeatures) const = 0;
146 virtual Features featuresSupported() const = 0;
147
148private:
149 Q_DISABLE_COPY_MOVE(QNetworkInformationBackendFactory)
150};
151#define QNetworkInformationBackendFactory_iid "org.qt-project.Qt.NetworkInformationBackendFactory"
153
155
156#endif
static void transportMediumChanged(JNIEnv *env, jobject obj, jint enumValue)
QNetworkInformationBackendFactory provides the interface for creating instances of QNetworkInformatio...
virtual QString name() const =0
Backend name, return the same in QNetworkInformationBackend::name().
virtual Features featuresSupported() const =0
Features supported, return the same in QNetworkInformationBackend::featuresSupported().
virtual QNetworkInformationBackend * create(Features requiredFeatures) const =0
Create and return an instance of QNetworkInformationBackend.
QNetworkInformationBackend provides the interface with which QNetworkInformation does all of its actu...
void transportMediumChanged(TransportMedium medium)
~QNetworkInformationBackend() override
void isMeteredChanged(bool isMetered)
TransportMedium transportMedium() const
virtual QNetworkInformation::Features featuresSupported() const =0
Features supported, return the same in QNetworkInformationBackendFactory::featuresSupported().
void setTransportMedium(TransportMedium medium)
void behindCaptivePortalChanged(bool behindPortal)
virtual QString name() const =0
Backend name, return the same in QNetworkInformationBackendFactory::name().
void reachabilityChanged(Reachability reachability)
You should not emit this signal manually, call setReachability() instead which will emit this signal ...
void setBehindCaptivePortal(bool behindPortal)
QNetworkInformationBackend()=default
Reachability reachability() const
void setReachability(QNetworkInformation::Reachability reachability)
Call this when reachability has changed.
\inmodule QtNetwork
Reachability
\value Unknown If this value is returned then we may be connected but the OS has still not confirmed ...
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
Combined button and popup list for selecting options.
#define QNetworkInformationBackendFactory_iid
#define Q_DECLARE_INTERFACE(IFace, IId)
Definition qobject.h:460
#define Q_OBJECT
#define Q_SIGNALS
#define emit