32 using Reachability = QNetworkInformation::Reachability;
33 using TransportMedium = QNetworkInformation::TransportMedium;
36 static inline const char16_t PluginNames[5][24] = {
37 { u"networklistmanager" },
38 { u"applenetworkinformation" },
40 { u"networkmanager" },
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;
49 QNetworkInformationBackend() =
default;
50 ~QNetworkInformationBackend() override;
52 virtual QString name()
const = 0;
53 virtual QNetworkInformation::Features featuresSupported()
const = 0;
55 Reachability reachability()
const
57 QReadLocker locker(&m_lock);
58 return m_reachability;
61 bool behindCaptivePortal()
const
63 QReadLocker locker(&m_lock);
64 return m_behindCaptivePortal;
67 TransportMedium transportMedium()
const
69 QReadLocker locker(&m_lock);
70 return m_transportMedium;
73 bool isMetered()
const
75 QReadLocker locker(&m_lock);
80 void reachabilityChanged(QNetworkInformation::Reachability reachability);
81 void behindCaptivePortalChanged(
bool behindPortal);
82 void transportMediumChanged(QNetworkInformation::TransportMedium medium);
83 void isMeteredChanged(
bool isMetered);
86 void setReachability(QNetworkInformation::Reachability reachability)
88 QWriteLocker locker(&m_lock);
89 if (m_reachability != reachability) {
90 m_reachability = reachability;
92 emit reachabilityChanged(reachability);
96 void setBehindCaptivePortal(
bool behindPortal)
98 QWriteLocker locker(&m_lock);
99 if (m_behindCaptivePortal != behindPortal) {
100 m_behindCaptivePortal = behindPortal;
102 emit behindCaptivePortalChanged(behindPortal);
106 void setTransportMedium(TransportMedium medium)
108 QWriteLocker locker(&m_lock);
109 if (m_transportMedium != medium) {
110 m_transportMedium = medium;
112 emit transportMediumChanged(medium);
116 void setMetered(
bool isMetered)
118 QWriteLocker locker(&m_lock);
119 if (m_metered != isMetered) {
120 m_metered = isMetered;
122 emit isMeteredChanged(isMetered);
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;
133 Q_DISABLE_COPY_MOVE(QNetworkInformationBackend)
134 friend class QNetworkInformation;
135 friend class QNetworkInformationPrivate;
142 using Features = QNetworkInformation::Features;
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;
152 Q_DISABLE_COPY_MOVE(QNetworkInformationBackendFactory)