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[5][24] = {
37 { u"networklistmanager" },
38 { u"applenetworkinformation" },
39 { u"android" },
40 { u"networkmanager" },
41 { u"ohos" },
42 };
43 static constexpr int PluginNamesWindowsIndex = 0;
44 static constexpr int PluginNamesAppleIndex = 1;
45 static constexpr int PluginNamesAndroidIndex = 2;
46 static constexpr int PluginNamesLinuxIndex = 3;
47 static constexpr int PluginNamesOhosIndex = 4;
48
49 QNetworkInformationBackend() = default;
50 ~QNetworkInformationBackend() override;
51
52 virtual QString name() const = 0;
53 virtual QNetworkInformation::Features featuresSupported() const = 0;
54
55 Reachability reachability() const
56 {
57 QReadLocker locker(&m_lock);
58 return m_reachability;
59 }
60
61 bool behindCaptivePortal() const
62 {
63 QReadLocker locker(&m_lock);
64 return m_behindCaptivePortal;
65 }
66
67 TransportMedium transportMedium() const
68 {
69 QReadLocker locker(&m_lock);
70 return m_transportMedium;
71 }
72
73 bool isMetered() const
74 {
75 QReadLocker locker(&m_lock);
76 return m_metered;
77 }
78
79Q_SIGNALS:
80 void reachabilityChanged(QNetworkInformation::Reachability reachability);
81 void behindCaptivePortalChanged(bool behindPortal);
82 void transportMediumChanged(QNetworkInformation::TransportMedium medium);
83 void isMeteredChanged(bool isMetered);
84
85protected:
86 void setReachability(QNetworkInformation::Reachability reachability)
87 {
88 QWriteLocker locker(&m_lock);
89 if (m_reachability != reachability) {
90 m_reachability = reachability;
91 locker.unlock();
92 emit reachabilityChanged(reachability);
93 }
94 }
95
96 void setBehindCaptivePortal(bool behindPortal)
97 {
98 QWriteLocker locker(&m_lock);
99 if (m_behindCaptivePortal != behindPortal) {
100 m_behindCaptivePortal = behindPortal;
101 locker.unlock();
102 emit behindCaptivePortalChanged(behindPortal);
103 }
104 }
105
106 void setTransportMedium(TransportMedium medium)
107 {
108 QWriteLocker locker(&m_lock);
109 if (m_transportMedium != medium) {
110 m_transportMedium = medium;
111 locker.unlock();
112 emit transportMediumChanged(medium);
113 }
114 }
115
116 void setMetered(bool isMetered)
117 {
118 QWriteLocker locker(&m_lock);
119 if (m_metered != isMetered) {
120 m_metered = isMetered;
121 locker.unlock();
122 emit isMeteredChanged(isMetered);
123 }
124 }
125
126private:
127 mutable QReadWriteLock m_lock;
128 Reachability m_reachability = Reachability::Unknown;
129 TransportMedium m_transportMedium = TransportMedium::Unknown;
130 bool m_behindCaptivePortal = false;
131 bool m_metered = false;
132
133 Q_DISABLE_COPY_MOVE(QNetworkInformationBackend)
134 friend class QNetworkInformation;
135 friend class QNetworkInformationPrivate;
136};
137
138class Q_NETWORK_EXPORT QNetworkInformationBackendFactory : public QObject
139{
140 Q_OBJECT
141
142 using Features = QNetworkInformation::Features;
143
144public:
145 QNetworkInformationBackendFactory();
146 virtual ~QNetworkInformationBackendFactory();
147 virtual QString name() const = 0;
148 virtual QNetworkInformationBackend *create(Features requiredFeatures) const = 0;
149 virtual Features featuresSupported() const = 0;
150
151private:
152 Q_DISABLE_COPY_MOVE(QNetworkInformationBackendFactory)
153};
154#define QNetworkInformationBackendFactory_iid "org.qt-project.Qt.NetworkInformationBackendFactory"
156
157QT_END_NAMESPACE
158
159#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