32 using Reachability = QNetworkInformation::Reachability;
33 using TransportMedium = QNetworkInformation::TransportMedium;
36 static inline const char16_t PluginNames[4][24] = {
37 { u"networklistmanager" },
38 { u"applenetworkinformation" },
40 { u"networkmanager" },
42 static constexpr int PluginNamesWindowsIndex = 0;
43 static constexpr int PluginNamesAppleIndex = 1;
44 static constexpr int PluginNamesAndroidIndex = 2;
45 static constexpr int PluginNamesLinuxIndex = 3;
47 QNetworkInformationBackend() =
default;
48 ~QNetworkInformationBackend() override;
50 virtual QString name()
const = 0;
51 virtual QNetworkInformation::Features featuresSupported()
const = 0;
53 Reachability reachability()
const
55 QReadLocker locker(&m_lock);
56 return m_reachability;
59 bool behindCaptivePortal()
const
61 QReadLocker locker(&m_lock);
62 return m_behindCaptivePortal;
65 TransportMedium transportMedium()
const
67 QReadLocker locker(&m_lock);
68 return m_transportMedium;
71 bool isMetered()
const
73 QReadLocker locker(&m_lock);
78 void reachabilityChanged(QNetworkInformation::Reachability reachability);
79 void behindCaptivePortalChanged(
bool behindPortal);
80 void transportMediumChanged(QNetworkInformation::TransportMedium medium);
81 void isMeteredChanged(
bool isMetered);
84 void setReachability(QNetworkInformation::Reachability reachability)
86 QWriteLocker locker(&m_lock);
87 if (m_reachability != reachability) {
88 m_reachability = reachability;
90 emit reachabilityChanged(reachability);
94 void setBehindCaptivePortal(
bool behindPortal)
96 QWriteLocker locker(&m_lock);
97 if (m_behindCaptivePortal != behindPortal) {
98 m_behindCaptivePortal = behindPortal;
100 emit behindCaptivePortalChanged(behindPortal);
104 void setTransportMedium(TransportMedium medium)
106 QWriteLocker locker(&m_lock);
107 if (m_transportMedium != medium) {
108 m_transportMedium = medium;
110 emit transportMediumChanged(medium);
114 void setMetered(
bool isMetered)
116 QWriteLocker locker(&m_lock);
117 if (m_metered != isMetered) {
118 m_metered = isMetered;
120 emit isMeteredChanged(isMetered);
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;
131 Q_DISABLE_COPY_MOVE(QNetworkInformationBackend)
132 friend class QNetworkInformation;
133 friend class QNetworkInformationPrivate;
140 using Features = QNetworkInformation::Features;
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;
150 Q_DISABLE_COPY_MOVE(QNetworkInformationBackendFactory)