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
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// Qt-Security score:significant reason:default
4
5#ifndef QNETWORKINFORMATION_P_H
6#define QNETWORKINFORMATION_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the Network Information API. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/private/qtnetworkglobal_p.h>
20
21#include <QtNetwork/qnetworkinformation.h>
22
23#include <QtCore/qloggingcategory.h>
24#include <QtCore/qreadwritelock.h>
25
27
29{
30 Q_OBJECT
31
32 using Reachability = QNetworkInformation::Reachability;
33 using TransportMedium = QNetworkInformation::TransportMedium;
34
35public:
36 static inline const char16_t PluginNames[4][24] = {
37 { u"networklistmanager" },
38 { u"applenetworkinformation" },
39 { u"android" },
40 { u"networkmanager" },
41 };
42 static constexpr int PluginNamesWindowsIndex = 0;
43 static constexpr int PluginNamesAppleIndex = 1;
44 static constexpr int PluginNamesAndroidIndex = 2;
45 static constexpr int PluginNamesLinuxIndex = 3;
46
47 QNetworkInformationBackend() = default;
48 ~QNetworkInformationBackend() override;
49
50 virtual QString name() const = 0;
51 virtual QNetworkInformation::Features featuresSupported() const = 0;
52
53 Reachability reachability() const
54 {
55 QReadLocker locker(&m_lock);
56 return m_reachability;
57 }
58
59 bool behindCaptivePortal() const
60 {
61 QReadLocker locker(&m_lock);
62 return m_behindCaptivePortal;
63 }
64
65 TransportMedium transportMedium() const
66 {
67 QReadLocker locker(&m_lock);
68 return m_transportMedium;
69 }
70
71 bool isMetered() const
72 {
73 QReadLocker locker(&m_lock);
74 return m_metered;
75 }
76
77Q_SIGNALS:
78 void reachabilityChanged(QNetworkInformation::Reachability reachability);
79 void behindCaptivePortalChanged(bool behindPortal);
80 void transportMediumChanged(QNetworkInformation::TransportMedium medium);
81 void isMeteredChanged(bool isMetered);
82
83protected:
84 void setReachability(QNetworkInformation::Reachability reachability)
85 {
86 QWriteLocker locker(&m_lock);
87 if (m_reachability != reachability) {
88 m_reachability = reachability;
89 locker.unlock();
90 emit reachabilityChanged(reachability);
91 }
92 }
93
94 void setBehindCaptivePortal(bool behindPortal)
95 {
96 QWriteLocker locker(&m_lock);
97 if (m_behindCaptivePortal != behindPortal) {
98 m_behindCaptivePortal = behindPortal;
99 locker.unlock();
100 emit behindCaptivePortalChanged(behindPortal);
101 }
102 }
103
104 void setTransportMedium(TransportMedium medium)
105 {
106 QWriteLocker locker(&m_lock);
107 if (m_transportMedium != medium) {
108 m_transportMedium = medium;
109 locker.unlock();
110 emit transportMediumChanged(medium);
111 }
112 }
113
114 void setMetered(bool isMetered)
115 {
116 QWriteLocker locker(&m_lock);
117 if (m_metered != isMetered) {
118 m_metered = isMetered;
119 locker.unlock();
120 emit isMeteredChanged(isMetered);
121 }
122 }
123
124private:
125 mutable QReadWriteLock m_lock;
126 Reachability m_reachability = Reachability::Unknown;
127 TransportMedium m_transportMedium = TransportMedium::Unknown;
128 bool m_behindCaptivePortal = false;
129 bool m_metered = false;
130
131 Q_DISABLE_COPY_MOVE(QNetworkInformationBackend)
132 friend class QNetworkInformation;
133 friend class QNetworkInformationPrivate;
134};
135
136class Q_NETWORK_EXPORT QNetworkInformationBackendFactory : public QObject
137{
138 Q_OBJECT
139
140 using Features = QNetworkInformation::Features;
141
142public:
143 QNetworkInformationBackendFactory();
144 virtual ~QNetworkInformationBackendFactory();
145 virtual QString name() const = 0;
146 virtual QNetworkInformationBackend *create(Features requiredFeatures) const = 0;
147 virtual Features featuresSupported() const = 0;
148
149private:
150 Q_DISABLE_COPY_MOVE(QNetworkInformationBackendFactory)
151};
152#define QNetworkInformationBackendFactory_iid "org.qt-project.Qt.NetworkInformationBackendFactory"
154
155QT_END_NAMESPACE
156
157#endif
QNetworkInformationBackendFactory provides the interface for creating instances of QNetworkInformatio...
QNetworkInformationBackend provides the interface with which QNetworkInformation does all of its actu...
Q_DECLARE_INTERFACE(QNetworkAccessBackendFactory, QNetworkAccessBackendFactory_iid)
#define QNetworkInformationBackendFactory_iid