Debian Codegraph @

src/systeminfo/qnetworkinfo.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSystems module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #include "qnetworkinfo.h"
41
42 #if defined(Q_OS_LINUX)
43 # include "linux/qnetworkinfo_linux_p.h"
44 #elif defined(Q_OS_WIN)
45 # include "windows/qnetworkinfo_win_p.h"
46 #elif defined(Q_OS_MAC)
47 # include "mac/qnetworkinfo_mac_p.h"
48 #else
49 QT_BEGIN_NAMESPACE
50 class QNetworkInfoPrivate
51 {
52 public:
53 QNetworkInfoPrivate(QNetworkInfo *) {}
54
55 int networkInterfaceCount(QNetworkInfo::NetworkMode) { return -1; }
56 int networkSignalStrength(QNetworkInfo::NetworkMode, int) { return -1; }
57 QNetworkInfo::CellDataTechnology currentCellDataTechnology(int) { return QNetworkInfo::UnknownDataTechnology; }
58 QNetworkInfo::NetworkMode currentNetworkMode() { return QNetworkInfo::UnknownMode; }
59 QNetworkInfo::NetworkStatus networkStatus(QNetworkInfo::NetworkMode, int) { return QNetworkInfo::UnknownStatus; }
60 #ifndef QT_NO_NETWORKINTERFACE
61 QNetworkInterface interfaceForMode(QNetworkInfo::NetworkMode, int) { return QNetworkInterface(); }
62 #endif // QT_NO_NETWORKINTERFACE
63 QString cellId(int) { return QString(); }
64 QString currentMobileCountryCode(int) { return QString(); }
65 QString currentMobileNetworkCode(int) { return QString(); }
66 QString homeMobileCountryCode(int) { return QString(); }
67 QString homeMobileNetworkCode(int) { return QString(); }
68 QString imsi(int) { return QString(); }
69 QString locationAreaCode(int) { return QString(); }
70 QString macAddress(QNetworkInfo::NetworkMode, int) { return QString(); }
71 QString networkName(QNetworkInfo::NetworkMode, int) { return QString(); }
72 };
73 QT_END_NAMESPACE
74 #endif
75
76 #include <QtCore/qmetaobject.h>
77
78 QT_BEGIN_NAMESPACE
79
80 /*!
81 \class QNetworkInfo
82 \inmodule QtSystemInfo
83 \brief The QNetworkInfo class provides various information about the network status.
84
85 \ingroup systeminfo
86
87 To support the cases where one has multiple interfaces / modems for the same network mode, you
88 can specify which interface you refer to. For those cases, the 'interface' parameter is the index
89 of the interface, starting from 0.
90 */
91
92 /*!
93 \enum QNetworkInfo::CellDataTechnology
94 This enum describes the type of cellular technology.
95
96 \value UnknownDataTechnology The cellular technology is unknown or an error occured.
97 \value GprsDataTechnology General Packet Radio Service (GPRS) data service.
98 \value EdgeDataTechnology Enhanced Data Rates for GSM Evolution (EDGE) data service.
99 \value UmtsDataTechnology Universal Mobile Telecommunications System (UMTS) data service.
100 \value HspaDataTechnology High Speed Packet Access (HSPA) data service.
101 */
102
103 /*!
104 \enum QNetworkInfo::NetworkMode
105 This enumeration describes the type of the network.
106
107 \value UnknownMode The network is unknown or an error occured.
108 \value GsmMode Global System for Mobile (GSM) network.
109 \value CdmaMode Code Division Multiple Access (CDMA) network.
110 \value WcdmaMode Wideband Code Division Multiple Access (WCDMA) network.
111 \value WlanMode Wireless local area network (WLAN) network.
112 \value EthernetMode Local area network (LAN), or Ethernet network.
113 \value BluetoothMode Bluetooth network.
114 \value WimaxMode Worldwide Interoperability for Microwave Access (WiMAX) network.
115 \value LteMode 3GPP Long Term Evolution (LTE) network.
116 \value TdscdmaMode Time Division Synchronous Code Division Multiple Access (TD-SCDMA) network.
117 */
118
119 /*!
120 \enum QNetworkInfo::NetworkStatus
121 This enumeration describes the status of the network.
122
123 \value UnknownStatus The status is unknown or an error occured.
124 \value NoNetworkAvailable There is no network available.
125 \value EmergencyOnly The network only allows emergency calls.
126 \value Searching The device is searching or connecting to the network.
127 \value Busy The network is too busy to be connected.
128 \value Denied The connection to the network has been denied.
129 \value HomeNetwork The device is connected to the home network.
130 \value Roaming The device is connected to some roaming network.
131 */
132
133 /*!
134 \fn void QNetworkInfo::cellIdChanged(int interface, const QString &id)
135
136 This signal is emitted whenever the cell ID for \a interface has changed to \a id.
137 */
138
139 /*!
140 \fn void QNetworkInfo::currentCellDataTechnologyChanged(int interface, QNetworkInfo::CellDataTechnology tech)
141
142 This signal is emitted whenever the current cell data technology for \a interface has changed to \a tech.
143 */
144
145 /*!
146 \fn void QNetworkInfo::currentMobileCountryCodeChanged(int interface, const QString &mcc)
147
148 This signal is emitted whenever the current Mobile Country Code (MCC) for \a interface has changed
149 to \a mcc.
150 */
151
152 /*!
153 \fn void QNetworkInfo::currentMobileNetworkCodeChanged(int interface, const QString &mnc)
154
155 This signal is emitted whenever the current Mobile Network Code (MNC) for \a interface has changed
156 to \a mnc.
157 */
158
159 /*!
160 \fn void QNetworkInfo::currentNetworkModeChanged(QNetworkInfo::NetworkMode mode)
161
162 This signal is emitted whenever the current network has changed to \a mode.
163 */
164
165 /*!
166 \fn void QNetworkInfo::locationAreaCodeChanged(int interface, const QString &lac)
167
168 This signal is emitted whenever the location area code for \a interface has changed to \a lac.
169 */
170
171 /*!
172 \fn void QNetworkInfo::networkInterfaceCountChanged(QNetworkInfo::NetworkMode mode, int count)
173
174 This signal is emitted whenever the number of interfaces for the \a mode has changed to \a count.
175 */
176
177 /*!
178 \fn void QNetworkInfo::networkNameChanged(QNetworkInfo::NetworkMode mode, int interface, const QString &name)
179
180 This signal is emitted whenever the name for the \a interface of \a mode has changed to \a name.
181 */
182
183 /*!
184 \fn void QNetworkInfo::networkSignalStrengthChanged(QNetworkInfo::NetworkMode mode, int interface, int strength)
185
186 This signal is emitted whenever the signal strength for the \a interface of \a mode has changed
187 to \a strength.
188 */
189
190 /*!
191 \fn void QNetworkInfo::networkStatusChanged(QNetworkInfo::NetworkMode mode, int interface, QNetworkInfo::NetworkStatus status)
192
193 This signal is emitted whenever the status for the \a interface of \a mode has changed to \a status.
194 */
195
196 /*!
197 Constructs a QNetworkInfo object with the given \a parent.
198 */
199 QNetworkInfo::QNetworkInfo(QObject *parent)
200 : QObject(parent)
201 , d_ptr(new QNetworkInfoPrivate(this))
202 {
203 }
204
205 /*!
206 Destroys the object
207 */
208 QNetworkInfo::~QNetworkInfo()
209 {
210 delete d_ptr;
211 }
212
213 /*!
214 Returns the number of interfaces for the \a mode. If the information is not available, or error
215 occurs, -1 is returned.
216 */
217 int QNetworkInfo::networkInterfaceCount(QNetworkInfo::NetworkMode mode) const
218 {
219 return d_ptr->networkInterfaceCount(mode);
220 }
221
222 /*!
223 Returns the signal strength for \a interfaceDevice of \a mode, in 0 - 100 scale. If the information
224 is not available, or error occurs, -1 is returned.
225 */
226 int QNetworkInfo::networkSignalStrength(QNetworkInfo::NetworkMode mode, int interfaceDevice) const
227 {
228 return d_ptr->networkSignalStrength(mode, interfaceDevice);
229 }
230
231 /*!
232 Returns the current cell data technology used for \a interfaceDevice.
233 */
234 QNetworkInfo::CellDataTechnology QNetworkInfo::currentCellDataTechnology(int interfaceDevice) const
235 {
236 return d_ptr->currentCellDataTechnology(interfaceDevice);
237 }
238
239 /*!
240 Returns the current active network mode. If there are more than one modes activated, the preferred
241 one is returned.
242 */
243 QNetworkInfo::NetworkMode QNetworkInfo::currentNetworkMode() const
244 {
245 return d_ptr->currentNetworkMode();
246 }
247
248 /*!
249 Returns the current status for \a interfaceDevice of \a mode.
250 */
251 QNetworkInfo::NetworkStatus QNetworkInfo::networkStatus(QNetworkInfo::NetworkMode mode, int interfaceDevice) const
252 {
253 return d_ptr->networkStatus(mode, interfaceDevice);
254 }
255
256 #ifndef QT_NO_NETWORKINTERFACE
257 /*!
258 Returns the first found interface for \a interfaceDevice of \a mode. If none is found, or it can't be
259 represented by QNetworkInterface (e.g. Bluetooth), and empty object is returned.
260 */
261 QNetworkInterface QNetworkInfo::interfaceForMode(QNetworkInfo::NetworkMode mode, int interfaceDevice) const
262 {
263 return d_ptr->interfaceForMode(mode, interfaceDevice);
264 }
265 #endif // QT_NO_NETWORKINTERFACE
266
267 /*!
268 Returns the cell ID of the connected tower or based station for \a interfaceDevice. If this information
269 is not available or error occurs, an empty string is returned.
270 */
271 QString QNetworkInfo::cellId(int interfaceDevice) const
272 {
273 return d_ptr->cellId(interfaceDevice);
274 }
275
276 /*!
277 Returns the current Mobile Country Code (MCC) for \a interfaceDevice. An empty string is returned if the
278 information is not available or an error occurs.
279 */
280 QString QNetworkInfo::currentMobileCountryCode(int interfaceDevice) const
281 {
282 return d_ptr->currentMobileCountryCode(interfaceDevice);
283 }
284
285 /*!
286 Returns the current Mobile Network Code (MNC) for \a interfaceDevice. An empty string is returned if the
287 information is not available or an error occurs.
288 */
289 QString QNetworkInfo::currentMobileNetworkCode(int interfaceDevice) const
290 {
291 return d_ptr->currentMobileNetworkCode(interfaceDevice);
292 }
293
294 /*!
295 Returns the home Mobile Country Code (MCC) for \a interfaceDevice. An empty string is returned if the
296 information is not available or an error occurs.
297 */
298 QString QNetworkInfo::homeMobileCountryCode(int interfaceDevice) const
299 {
300 return d_ptr->homeMobileCountryCode(interfaceDevice);
301 }
302
303 /*!
304 Returns the home Mobile Network Code (MNC) for \a interfaceDevice. An empty string is returned if the
305 information is not available or an error occurs.
306 */
307 QString QNetworkInfo::homeMobileNetworkCode(int interfaceDevice) const
308 {
309 return d_ptr->homeMobileNetworkCode(interfaceDevice);
310 }
311
312 /*!
313 Returns the International Mobile Subscriber Identity (IMSI) for \a interfaceDevice. If this information is
314 not available, or error occurs, an empty string is returned.
315 */
316 QString QNetworkInfo::imsi(int interfaceDevice) const
317 {
318 return d_ptr->imsi(interfaceDevice);
319 }
320
321 /*!
322 Returns the location area code of the current cellular radio network for \a interfaceDevice. If this information
323 is not available or error occurs, an empty string is returned.
324 */
325 QString QNetworkInfo::locationAreaCode(int interfaceDevice) const
326 {
327 return d_ptr->locationAreaCode(interfaceDevice);
328 }
329
330 /*!
331 Returns the MAC address for \a interfaceDevice of \a mode. If the MAC address is not available or error
332 occurs, an empty string is returned.
333 */
334 QString QNetworkInfo::macAddress(QNetworkInfo::NetworkMode mode, int interfaceDevice) const
335 {
336 return d_ptr->macAddress(mode, interfaceDevice);
337 }
338
339 /*!
340 Returns the name of the operator for \a interfaceDevice of \a mode. If the information is not available,
341 or an error occurs, an empty string is returned.
342
343 In case of WLAN, the SSID is returned; for Ethernet, the domain name is returned if available.
344 */
345 QString QNetworkInfo::networkName(QNetworkInfo::NetworkMode mode, int interfaceDevice) const
346 {
347 return d_ptr->networkName(mode, interfaceDevice);
348 }
349
350 extern QMetaMethod proxyToSourceSignal(const QMetaMethod &, QObject *);
351
352 /*!
353 \internal
354 */
355 void QNetworkInfo::connectNotify(const QMetaMethod &signal)
356 {
357 #if defined(Q_OS_LINUX) || defined(Q_OS_WIN) || defined(Q_OS_MAC)
358 QMetaMethod sourceSignal = proxyToSourceSignal(signal, d_ptr);
359 connect(d_ptr, sourceSignal, this, signal, Qt::UniqueConnection);
360 #else
361 Q_UNUSED(signal)
362 #endif
363 }
364
365 /*!
366 \internal
367 */
368 void QNetworkInfo::disconnectNotify(const QMetaMethod &signal)
369 {
370 #if defined(Q_OS_LINUX) || defined(Q_OS_WIN) || defined(Q_OS_MAC)
371 // We can only disconnect with the private implementation, when there is no receivers for the signal.
372 if (isSignalConnected(signal))
373 return;
374
375 QMetaMethod sourceSignal = proxyToSourceSignal(signal, d_ptr);
376 disconnect(d_ptr, sourceSignal, this, signal);
377 #else
378 Q_UNUSED(signal)
379 #endif
380 }
381
382 QT_END_NAMESPACE