| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtBluetooth 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 "qbluetoothdeviceinfo.h" |
| 41 | #include "qbluetoothdeviceinfo_p.h" |
| 42 | |
| 43 | QT_BEGIN_NAMESPACE |
| 44 | |
| 45 | /*! |
| 46 | \class QBluetoothDeviceInfo |
| 47 | \inmodule QtBluetooth |
| 48 | \brief The QBluetoothDeviceInfo class stores information about the Bluetooth |
| 49 | device. |
| 50 | |
| 51 | \since 5.2 |
| 52 | |
| 53 | QBluetoothDeviceInfo provides information about a Bluetooth device's name, address and class of device. |
| 54 | */ |
| 55 | |
| 56 | /*! |
| 57 | \enum QBluetoothDeviceInfo::MajorDeviceClass |
| 58 | |
| 59 | This enum describes a Bluetooth device's major device class. |
| 60 | |
| 61 | \value MiscellaneousDevice A miscellaneous device. |
| 62 | \value ComputerDevice A computer device or PDA. |
| 63 | \value PhoneDevice A telephone device. |
| 64 | \value LANAccessDevice A device that provides access to a local area network |
| 65 | (deprecated since Qt 5.13 and replaced by |
| 66 | \l QBluetoothDeviceInfo::NetworkDevice). |
| 67 | \value NetworkDevice A device that provides access to a local area network (since Qt 5.13). |
| 68 | \value AudioVideoDevice A device capable of playback or capture of audio and/or video. |
| 69 | \value PeripheralDevice A peripheral device such as a keyboard, mouse, and so on. |
| 70 | \value ImagingDevice An imaging device such as a display, printer, scanner or camera. |
| 71 | \value WearableDevice A wearable device such as a watch or pager. |
| 72 | \value ToyDevice A toy. |
| 73 | \value HealthDevice A health reated device such as heart rate or temperature monitor. |
| 74 | \value UncategorizedDevice A device that does not fit into any of the other device classes. |
| 75 | */ |
| 76 | |
| 77 | /*! |
| 78 | \enum QBluetoothDeviceInfo::Field |
| 79 | |
| 80 | This enum is used in conjuntion with the \l QBluetoothDeviceDiscoveryAgent::deviceUpdated() signal |
| 81 | and indicates the field that changed. |
| 82 | |
| 83 | \value None None of the values changed. |
| 84 | \value RSSI The \l rssi() value of the device changed. |
| 85 | \value ManufacturerData The \l manufacturerData() field changed |
| 86 | \value All Matches every possible field. |
| 87 | |
| 88 | \since 5.12 |
| 89 | */ |
| 90 | |
| 91 | /*! |
| 92 | \enum QBluetoothDeviceInfo::MinorMiscellaneousClass |
| 93 | |
| 94 | This enum describes the minor device classes for miscellaneous Bluetooth devices. |
| 95 | |
| 96 | \value UncategorizedMiscellaneous An uncategorized miscellaneous device. |
| 97 | */ |
| 98 | |
| 99 | /*! |
| 100 | \enum QBluetoothDeviceInfo::MinorComputerClass |
| 101 | |
| 102 | This enum describes the minor device classes for computer devices. |
| 103 | |
| 104 | \value UncategorizedComputer An uncategorized computer device. |
| 105 | \value DesktopComputer A desktop computer. |
| 106 | \value ServerComputer A server computer. |
| 107 | \value LaptopComputer A laptop computer. |
| 108 | \value HandheldClamShellComputer A clamshell handheld computer or PDA. |
| 109 | \value HandheldComputer A handheld computer or PDA. |
| 110 | \value WearableComputer A wearable computer. |
| 111 | */ |
| 112 | |
| 113 | /*! |
| 114 | \enum QBluetoothDeviceInfo::MinorPhoneClass |
| 115 | |
| 116 | This enum describes the minor device classes for phone devices. |
| 117 | |
| 118 | \value UncategorizedPhone An uncategorized phone device. |
| 119 | \value CellularPhone A cellular phone. |
| 120 | \value CordlessPhone A cordless phone. |
| 121 | \value SmartPhone A smart phone. |
| 122 | \value WiredModemOrVoiceGatewayPhone A wired modem or voice gateway. |
| 123 | \value CommonIsdnAccessPhone A device that provides ISDN access. |
| 124 | */ |
| 125 | |
| 126 | /*! |
| 127 | \enum QBluetoothDeviceInfo::MinorNetworkClass |
| 128 | |
| 129 | This enum describes the minor device classes for local area network access devices. Local area |
| 130 | network access devices use the minor device class to specify the current network utilization. |
| 131 | |
| 132 | \value NetworkFullService 100% of the total bandwidth is available. |
| 133 | \value NetworkLoadFactorOne 0 - 17% of the total bandwidth is currently being used. |
| 134 | \value NetworkLoadFactorTwo 17 - 33% of the total bandwidth is currently being used. |
| 135 | \value NetworkLoadFactorThree 33 - 50% of the total bandwidth is currently being used. |
| 136 | \value NetworkLoadFactorFour 50 - 67% of the total bandwidth is currently being used. |
| 137 | \value NetworkLoadFactorFive 67 - 83% of the total bandwidth is currently being used. |
| 138 | \value NetworkLoadFactorSix 83 - 99% of the total bandwidth is currently being used. |
| 139 | \value NetworkNoService No network service available. |
| 140 | */ |
| 141 | |
| 142 | /*! |
| 143 | \enum QBluetoothDeviceInfo::MinorAudioVideoClass |
| 144 | |
| 145 | This enum describes the minor device classes for audio/video devices. |
| 146 | |
| 147 | \value UncategorizedAudioVideoDevice An uncategorized audio/video device. |
| 148 | \value WearableHeadsetDevice A wearable headset device. |
| 149 | \value HandsFreeDevice A handsfree device. |
| 150 | \value Microphone A microphone. |
| 151 | \value Loudspeaker A loudspeaker. |
| 152 | \value Headphones Headphones. |
| 153 | \value PortableAudioDevice A portable audio device. |
| 154 | \value CarAudio A car audio device. |
| 155 | \value SetTopBox A settop box. |
| 156 | \value HiFiAudioDevice A HiFi audio device. |
| 157 | \value Vcr A video cassette recorder. |
| 158 | \value VideoCamera A video camera. |
| 159 | \value Camcorder A video camera. |
| 160 | \value VideoMonitor A video monitor. |
| 161 | \value VideoDisplayAndLoudspeaker A video display with built-in loudspeaker. |
| 162 | \value VideoConferencing A video conferencing device. |
| 163 | \value GamingDevice A gaming device. |
| 164 | */ |
| 165 | |
| 166 | /*! |
| 167 | \enum QBluetoothDeviceInfo::MinorPeripheralClass |
| 168 | |
| 169 | This enum describes the minor device classes for peripheral devices. |
| 170 | |
| 171 | \value UncategorizedPeripheral An uncategorized peripheral device. |
| 172 | \value KeyboardPeripheral A keyboard. |
| 173 | \value PointingDevicePeripheral A pointing device, for example a mouse. |
| 174 | \value KeyboardWithPointingDevicePeripheral A keyboard with built-in pointing device. |
| 175 | \value JoystickPeripheral A joystick. |
| 176 | \value GamepadPeripheral A game pad. |
| 177 | \value RemoteControlPeripheral A remote control. |
| 178 | \value SensingDevicePeripheral A sensing device. |
| 179 | \value DigitizerTabletPeripheral A digitizer tablet peripheral. |
| 180 | \value CardReaderPeripheral A card reader peripheral. |
| 181 | */ |
| 182 | |
| 183 | /*! |
| 184 | \enum QBluetoothDeviceInfo::MinorImagingClass |
| 185 | |
| 186 | This enum describes the minor device classes for imaging devices. |
| 187 | |
| 188 | \value UncategorizedImagingDevice An uncategorized imaging device. |
| 189 | \value ImageDisplay A device capable of displaying images. |
| 190 | \value ImageCamera A camera. |
| 191 | \value ImageScanner An image scanner. |
| 192 | \value ImagePrinter A printer. |
| 193 | */ |
| 194 | |
| 195 | /*! |
| 196 | \enum QBluetoothDeviceInfo::MinorWearableClass |
| 197 | |
| 198 | This enum describes the minor device classes for wearable devices. |
| 199 | |
| 200 | \value UncategorizedWearableDevice An uncategorized wearable device. |
| 201 | \value WearableWristWatch A wristwatch. |
| 202 | \value WearablePager A pager. |
| 203 | \value WearableJacket A jacket. |
| 204 | \value WearableHelmet A helmet. |
| 205 | \value WearableGlasses A pair of glasses. |
| 206 | */ |
| 207 | |
| 208 | /*! |
| 209 | \enum QBluetoothDeviceInfo::MinorToyClass |
| 210 | |
| 211 | This enum describes the minor device classes for toy devices. |
| 212 | |
| 213 | \value UncategorizedToy An uncategorized toy. |
| 214 | \value ToyRobot A toy robot. |
| 215 | \value ToyVehicle A toy vehicle. |
| 216 | \value ToyDoll A toy doll or action figure. |
| 217 | \value ToyController A controller. |
| 218 | \value ToyGame A game. |
| 219 | */ |
| 220 | |
| 221 | /*! |
| 222 | \enum QBluetoothDeviceInfo::MinorHealthClass |
| 223 | |
| 224 | This enum describes the minor device classes for health devices. |
| 225 | |
| 226 | \value UncategorizedHealthDevice An uncategorized health device. |
| 227 | \value HealthBloodPressureMonitor A blood pressure monitor. |
| 228 | \value HealthThermometer A Thermometer. |
| 229 | \value HealthWeightScale A scale. |
| 230 | \value HealthGlucoseMeter A glucose meter. |
| 231 | \value HealthPulseOximeter A blood oxygen saturation meter. |
| 232 | \value HealthDataDisplay A data display. |
| 233 | \value HealthStepCounter A pedometer. |
| 234 | */ |
| 235 | |
| 236 | /*! |
| 237 | \enum QBluetoothDeviceInfo::ServiceClass |
| 238 | |
| 239 | This enum describes the service class of the Bluetooth device. The service class is used as a |
| 240 | rudimentary form of service discovery. It is meant to provide a list of the types |
| 241 | of services that the device might provide. |
| 242 | |
| 243 | \value NoService The device does not provide any services. |
| 244 | \value PositioningService The device provides positioning services. |
| 245 | \value NetworkingService The device provides networking services. |
| 246 | \value RenderingService The device provides rendering services. |
| 247 | \value CapturingService The device provides capturing services. |
| 248 | \value ObjectTransferService The device provides object transfer services. |
| 249 | \value AudioService The device provides audio services. |
| 250 | \value TelephonyService The device provides telephony services. |
| 251 | \value InformationService The device provides information services. |
| 252 | \value AllServices The device provides services of all types. |
| 253 | */ |
| 254 | |
| 255 | /*! |
| 256 | \enum QBluetoothDeviceInfo::DataCompleteness |
| 257 | |
| 258 | This enum describes the completeness of the received data. |
| 259 | |
| 260 | \value DataComplete The data is complete. |
| 261 | \value DataIncomplete The data is incomplete. Addition datum is available via other |
| 262 | interfaces. |
| 263 | \value DataUnavailable No data is available. |
| 264 | */ |
| 265 | |
| 266 | /*! |
| 267 | \enum QBluetoothDeviceInfo::CoreConfiguration |
| 268 | \since 5.4 |
| 269 | |
| 270 | This enum describes the configuration of the device. |
| 271 | |
| 272 | \value UnknownCoreConfiguration The type of the Bluetooth device cannot be determined. |
| 273 | \value BaseRateCoreConfiguration The device is a standard Bluetooth device. |
| 274 | \value BaseRateAndLowEnergyCoreConfiguration The device is a Bluetooth Smart device with support |
| 275 | for standard and Low Energy device. |
| 276 | \value LowEnergyCoreConfiguration The device is a Bluetooth Low Energy device. |
| 277 | */ |
| 278 | QBluetoothDeviceInfoPrivate::QBluetoothDeviceInfoPrivate() : |
| 279 | valid(false), |
| 280 | cached(false), |
| 281 | rssi(1), |
| 282 | serviceClasses(QBluetoothDeviceInfo::NoService), |
| 283 | majorDeviceClass(QBluetoothDeviceInfo::MiscellaneousDevice), |
| 284 | minorDeviceClass(0), |
| 285 | #if QT_DEPRECATED_SINCE(5, 13) |
| 286 | serviceUuidsCompleteness(QBluetoothDeviceInfo::DataUnavailable), |
| 287 | #endif |
| 288 | deviceCoreConfiguration(QBluetoothDeviceInfo::UnknownCoreConfiguration) |
| 289 | { |
| 290 | } |
| 291 | |
| 292 | /*! |
| 293 | Constructs an invalid QBluetoothDeviceInfo object. |
| 294 | */ |
| 295 | QBluetoothDeviceInfo::QBluetoothDeviceInfo() : |
| 296 | d_ptr(new QBluetoothDeviceInfoPrivate) |
| 297 | { |
| 298 | } |
| 299 | |
| 300 | /*! |
| 301 | Constructs a QBluetoothDeviceInfo object with Bluetooth address \a address, device name |
| 302 | \a name and the encoded class of device \a classOfDevice. |
| 303 | |
| 304 | The \a classOfDevice parameter is encoded in the following format |
| 305 | |
| 306 | \table |
| 307 | \header \li Bits \li Size \li Description |
| 308 | \row \li 0 - 1 \li 2 \li Unused, set to 0. |
| 309 | \row \li 2 - 7 \li 6 \li Minor device class. |
| 310 | \row \li 8 - 12 \li 5 \li Major device class. |
| 311 | \row \li 13 - 23 \li 11 \li Service class. |
| 312 | \endtable |
| 313 | */ |
| 314 | QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothAddress &address, const QString &name, |
| 315 | quint32 classOfDevice) : |
| 316 | d_ptr(new QBluetoothDeviceInfoPrivate) |
| 317 | { |
| 318 | Q_D(QBluetoothDeviceInfo); |
| 319 | |
| 320 | d->address = address; |
| 321 | d->name = name; |
| 322 | |
| 323 | d->minorDeviceClass = static_cast<quint8>((classOfDevice >> 2) & 0x3f); |
| 324 | d->majorDeviceClass = static_cast<MajorDeviceClass>((classOfDevice >> 8) & 0x1f); |
| 325 | d->serviceClasses = static_cast<ServiceClasses>((classOfDevice >> 13) & 0x7ff); |
| 326 | |
| 327 | #if QT_DEPRECATED_SINCE(5, 13) |
| 328 | d->serviceUuidsCompleteness = DataUnavailable; |
| 329 | #endif |
| 330 | |
| 331 | d->valid = true; |
| 332 | d->cached = false; |
| 333 | d->rssi = 0; |
| 334 | } |
| 335 | |
| 336 | /*! |
| 337 | Constructs a QBluetoothDeviceInfo object with unique \a uuid, device name |
| 338 | \a name and the encoded class of device \a classOfDevice. |
| 339 | |
| 340 | This constructor is required for Low Energy devices on \macos and iOS. CoreBluetooth |
| 341 | API hides addresses and provides unique UUIDs to identify a device. This UUID is |
| 342 | not the same thing as a service UUID and is required to work later with CoreBluetooth API |
| 343 | and discovered devices. |
| 344 | |
| 345 | \since 5.5 |
| 346 | */ |
| 347 | QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothUuid &uuid, const QString &name, |
| 348 | quint32 classOfDevice) : |
| 349 | d_ptr(new QBluetoothDeviceInfoPrivate) |
| 350 | { |
| 351 | Q_D(QBluetoothDeviceInfo); |
| 352 | |
| 353 | d->name = name; |
| 354 | d->deviceUuid = uuid; |
| 355 | |
| 356 | d->minorDeviceClass = static_cast<quint8>((classOfDevice >> 2) & 0x3f); |
| 357 | d->majorDeviceClass = static_cast<MajorDeviceClass>((classOfDevice >> 8) & 0x1f); |
| 358 | d->serviceClasses = static_cast<ServiceClasses>((classOfDevice >> 13) & 0x7ff); |
| 359 | |
| 360 | #if QT_DEPRECATED_SINCE(5, 13) |
| 361 | d->serviceUuidsCompleteness = DataUnavailable; |
| 362 | #endif |
| 363 | |
| 364 | d->valid = true; |
| 365 | d->cached = false; |
| 366 | d->rssi = 0; |
| 367 | } |
| 368 | |
| 369 | /*! |
| 370 | Constructs a QBluetoothDeviceInfo that is a copy of \a other. |
| 371 | */ |
| 372 | QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothDeviceInfo &other) : |
| 373 | d_ptr(new QBluetoothDeviceInfoPrivate) |
| 374 | { |
| 375 | *this = other; |
| 376 | } |
| 377 | |
| 378 | /*! |
| 379 | Destroys the QBluetoothDeviceInfo. |
| 380 | */ |
| 381 | QBluetoothDeviceInfo::~QBluetoothDeviceInfo() |
| 382 | { |
| 383 | delete d_ptr; |
| 384 | } |
| 385 | |
| 386 | /*! |
| 387 | Returns true if the QBluetoothDeviceInfo object is valid, otherwise returns false. |
| 388 | */ |
| 389 | bool QBluetoothDeviceInfo::isValid() const |
| 390 | { |
| 391 | Q_D(const QBluetoothDeviceInfo); |
| 392 | |
| 393 | return d->valid; |
| 394 | } |
| 395 | |
| 396 | /*! |
| 397 | Returns the signal strength when the device was last scanned |
| 398 | */ |
| 399 | qint16 QBluetoothDeviceInfo::() const |
| 400 | { |
| 401 | Q_D(const QBluetoothDeviceInfo); |
| 402 | |
| 403 | return d->rssi; |
| 404 | } |
| 405 | |
| 406 | /*! |
| 407 | Set the \a signal strength value, used internally. |
| 408 | */ |
| 409 | void QBluetoothDeviceInfo::(qint16 signal) |
| 410 | { |
| 411 | Q_D(QBluetoothDeviceInfo); |
| 412 | d->rssi = signal; |
| 413 | } |
| 414 | |
| 415 | /*! |
| 416 | Makes a copy of the \a other and assigns it to this QBluetoothDeviceInfo object. |
| 417 | */ |
| 418 | QBluetoothDeviceInfo &QBluetoothDeviceInfo::operator=(const QBluetoothDeviceInfo &other) |
| 419 | { |
| 420 | Q_D(QBluetoothDeviceInfo); |
| 421 | |
| 422 | d->address = other.d_func()->address; |
| 423 | d->name = other.d_func()->name; |
| 424 | d->minorDeviceClass = other.d_func()->minorDeviceClass; |
| 425 | d->majorDeviceClass = other.d_func()->majorDeviceClass; |
| 426 | d->serviceClasses = other.d_func()->serviceClasses; |
| 427 | d->valid = other.d_func()->valid; |
| 428 | d->cached = other.d_func()->cached; |
| 429 | #if QT_DEPRECATED_SINCE(5, 13) |
| 430 | d->serviceUuidsCompleteness = other.d_func()->serviceUuidsCompleteness; |
| 431 | #endif |
| 432 | d->serviceUuids = other.d_func()->serviceUuids; |
| 433 | d->manufacturerData = other.d_func()->manufacturerData; |
| 434 | d->rssi = other.d_func()->rssi; |
| 435 | d->deviceCoreConfiguration = other.d_func()->deviceCoreConfiguration; |
| 436 | d->deviceUuid = other.d_func()->deviceUuid; |
| 437 | |
| 438 | return *this; |
| 439 | } |
| 440 | |
| 441 | /*! |
| 442 | Returns true if the \a other QBluetoothDeviceInfo object and this are identical. |
| 443 | */ |
| 444 | bool QBluetoothDeviceInfo::operator==(const QBluetoothDeviceInfo &other) const |
| 445 | { |
| 446 | Q_D(const QBluetoothDeviceInfo); |
| 447 | |
| 448 | if (d->cached != other.d_func()->cached) |
| 449 | return false; |
| 450 | if (d->valid != other.d_func()->valid) |
| 451 | return false; |
| 452 | if (d->majorDeviceClass != other.d_func()->majorDeviceClass) |
| 453 | return false; |
| 454 | if (d->minorDeviceClass != other.d_func()->minorDeviceClass) |
| 455 | return false; |
| 456 | if (d->serviceClasses != other.d_func()->serviceClasses) |
| 457 | return false; |
| 458 | if (d->name != other.d_func()->name) |
| 459 | return false; |
| 460 | if (d->address != other.d_func()->address) |
| 461 | return false; |
| 462 | #if QT_DEPRECATED_SINCE(5, 13) |
| 463 | if (d->serviceUuidsCompleteness != other.d_func()->serviceUuidsCompleteness) |
| 464 | return false; |
| 465 | #endif |
| 466 | if (d->serviceUuids.count() != other.d_func()->serviceUuids.count()) |
| 467 | return false; |
| 468 | if (d->serviceUuids != other.d_func()->serviceUuids) |
| 469 | return false; |
| 470 | if (d->manufacturerData != other.d_func()->manufacturerData) |
| 471 | return false; |
| 472 | if (d->deviceCoreConfiguration != other.d_func()->deviceCoreConfiguration) |
| 473 | return false; |
| 474 | if (d->deviceUuid != other.d_func()->deviceUuid) |
| 475 | return false; |
| 476 | |
| 477 | return true; |
| 478 | } |
| 479 | |
| 480 | /*! |
| 481 | Returns true if this object is different from \a other, or false otherwise. |
| 482 | |
| 483 | \sa operator==() |
| 484 | */ |
| 485 | bool QBluetoothDeviceInfo::operator!=(const QBluetoothDeviceInfo &other) const |
| 486 | { |
| 487 | return !(*this == other); |
| 488 | } |
| 489 | |
| 490 | /*! |
| 491 | Returns the address of the device. |
| 492 | |
| 493 | \note On iOS and \macos this address is invalid. Instead \l deviceUuid() should be used. |
| 494 | Those two platforms do not expose Bluetooth addresses for found Bluetooth devices |
| 495 | and utilize unique device identifiers. |
| 496 | |
| 497 | \sa deviceUuid() |
| 498 | */ |
| 499 | QBluetoothAddress QBluetoothDeviceInfo::address() const |
| 500 | { |
| 501 | Q_D(const QBluetoothDeviceInfo); |
| 502 | |
| 503 | return d->address; |
| 504 | } |
| 505 | |
| 506 | /*! |
| 507 | Returns the name assigned to the device. |
| 508 | */ |
| 509 | QString QBluetoothDeviceInfo::name() const |
| 510 | { |
| 511 | Q_D(const QBluetoothDeviceInfo); |
| 512 | |
| 513 | return d->name; |
| 514 | } |
| 515 | |
| 516 | /*! |
| 517 | Returns the service class of the device. |
| 518 | */ |
| 519 | QBluetoothDeviceInfo::ServiceClasses QBluetoothDeviceInfo::serviceClasses() const |
| 520 | { |
| 521 | Q_D(const QBluetoothDeviceInfo); |
| 522 | |
| 523 | return d->serviceClasses; |
| 524 | } |
| 525 | |
| 526 | /*! |
| 527 | Returns the major device class of the device. |
| 528 | */ |
| 529 | QBluetoothDeviceInfo::MajorDeviceClass QBluetoothDeviceInfo::majorDeviceClass() const |
| 530 | { |
| 531 | Q_D(const QBluetoothDeviceInfo); |
| 532 | |
| 533 | return d->majorDeviceClass; |
| 534 | } |
| 535 | |
| 536 | /*! |
| 537 | Returns the minor device class of the device. The actual information |
| 538 | is context dependent on the value of \l majorDeviceClass(). |
| 539 | |
| 540 | \sa MinorAudioVideoClass, MinorComputerClass, MinorHealthClass, MinorImagingClass, |
| 541 | MinorMiscellaneousClass, MinorNetworkClass, MinorPeripheralClass, MinorPhoneClass, |
| 542 | MinorToyClass, MinorWearableClass |
| 543 | */ |
| 544 | quint8 QBluetoothDeviceInfo::minorDeviceClass() const |
| 545 | { |
| 546 | Q_D(const QBluetoothDeviceInfo); |
| 547 | |
| 548 | return d->minorDeviceClass; |
| 549 | } |
| 550 | |
| 551 | #if QT_DEPRECATED_SINCE(5, 13) |
| 552 | /*! |
| 553 | \deprecated |
| 554 | |
| 555 | Sets the list of service UUIDs to \a uuids and the completeness of the data to \a completeness. |
| 556 | */ |
| 557 | void QBluetoothDeviceInfo::setServiceUuids(const QList<QBluetoothUuid> &uuids, |
| 558 | DataCompleteness completeness) |
| 559 | { |
| 560 | Q_D(QBluetoothDeviceInfo); |
| 561 | |
| 562 | d->serviceUuids = uuids.toVector(); |
| 563 | d->serviceUuidsCompleteness = completeness; |
| 564 | } |
| 565 | #endif |
| 566 | |
| 567 | /*! |
| 568 | Sets the list of service UUIDs to \a uuids. |
| 569 | \since 5.13 |
| 570 | */ |
| 571 | void QBluetoothDeviceInfo::setServiceUuids(const QVector<QBluetoothUuid> &uuids) |
| 572 | { |
| 573 | Q_D(QBluetoothDeviceInfo); |
| 574 | d->serviceUuids = uuids; |
| 575 | } |
| 576 | |
| 577 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 578 | /*! |
| 579 | Returns the list of service UUIDS supported by the device. Most commonly this |
| 580 | list of uuids represents custom uuids or a uuid value specified by |
| 581 | \l QBluetoothUuid::ServiceClassUuid. |
| 582 | |
| 583 | \sa serviceUuids() |
| 584 | \since 6.0 |
| 585 | */ |
| 586 | QVector<QBluetoothUuid> QBluetoothDeviceInfo::serviceUuids() const |
| 587 | { |
| 588 | Q_D(const QBluetoothDeviceInfo); |
| 589 | return d->serviceUuids; |
| 590 | } |
| 591 | |
| 592 | #elif QT_DEPRECATED_SINCE(5, 13) |
| 593 | |
| 594 | /*! |
| 595 | Returns the list of service UUIDS supported by the device. If \a completeness is not 0 it will |
| 596 | be set to DataComplete and the complete list of UUIDs supported by the device is returned. |
| 597 | DataIncomplete if additional service UUIDs are supported by the device and DataUnavailable if |
| 598 | no service UUID information is available. |
| 599 | |
| 600 | This function requires both the Bluetooth devices to support the 2.1 specification. |
| 601 | */ |
| 602 | QList<QBluetoothUuid> QBluetoothDeviceInfo::serviceUuids(DataCompleteness *completeness) const |
| 603 | { |
| 604 | Q_D(const QBluetoothDeviceInfo); |
| 605 | |
| 606 | if (completeness) |
| 607 | *completeness = d->serviceUuidsCompleteness; |
| 608 | |
| 609 | return d->serviceUuids.toList(); |
| 610 | } |
| 611 | |
| 612 | #else |
| 613 | |
| 614 | /* |
| 615 | Returns the list of service UUIDS supported by the device. Most commonly this |
| 616 | list of uuids represents custom uuids or a uuid value specified by |
| 617 | \l QBluetoothUuid::ServiceClassUuid. |
| 618 | */ |
| 619 | QList<QBluetoothUuid> QBluetoothDeviceInfo::serviceUuids() const |
| 620 | { |
| 621 | Q_D(const QBluetoothDeviceInfo); |
| 622 | return d->serviceUuids.toList(); |
| 623 | } |
| 624 | |
| 625 | #endif //QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 626 | |
| 627 | #if QT_DEPRECATED_SINCE(5, 13) |
| 628 | /*! |
| 629 | \deprecated |
| 630 | |
| 631 | Returns the completeness of the service UUID list. If DataComplete is returned, |
| 632 | serviceUuids() returns the complete list of service UUIDs supported by the device, otherwise |
| 633 | only the partial or empty list of service UUIDs. To get a list |
| 634 | of all services supported by the device, a full service discovery needs to be performed. |
| 635 | */ |
| 636 | QBluetoothDeviceInfo::DataCompleteness QBluetoothDeviceInfo::serviceUuidsCompleteness() const |
| 637 | { |
| 638 | Q_D(const QBluetoothDeviceInfo); |
| 639 | return d->serviceUuidsCompleteness; |
| 640 | } |
| 641 | #endif |
| 642 | |
| 643 | /*! |
| 644 | Returns all manufacturer ids attached to this device information. |
| 645 | |
| 646 | \sa manufacturerData(), setManufacturerData() |
| 647 | |
| 648 | \since 5.12 |
| 649 | */ |
| 650 | QVector<quint16> QBluetoothDeviceInfo::manufacturerIds() const |
| 651 | { |
| 652 | Q_D(const QBluetoothDeviceInfo); |
| 653 | return d->manufacturerData.keys().toVector(); |
| 654 | } |
| 655 | |
| 656 | /*! |
| 657 | Returns the data associated with the given \a manufacturerId. |
| 658 | |
| 659 | Manufacturer data is defined by |
| 660 | the Supplement to the Bluetooth Core Specification and consists of two segments: |
| 661 | |
| 662 | \list |
| 663 | \li Manufacturer specific identifier code from the |
| 664 | \l {https://www.bluetooth.com/specifications/assigned-numbers} {Assigned Numbers} |
| 665 | Company Identifiers document |
| 666 | \li Sequence of arbitrary data octets |
| 667 | \endlist |
| 668 | |
| 669 | The interpretation of the data octets is defined by the manufacturer |
| 670 | specified by the company identifier. |
| 671 | |
| 672 | \note The remote device may provide multiple data entries per manufacturerId. |
| 673 | This function only returns the first entry. If all entries are needed use |
| 674 | \l manufacturerData() which returns a multi hash. |
| 675 | |
| 676 | \sa manufacturerIds(), setManufacturerData() |
| 677 | \since 5.12 |
| 678 | */ |
| 679 | QByteArray QBluetoothDeviceInfo::manufacturerData(quint16 manufacturerId) const |
| 680 | { |
| 681 | Q_D(const QBluetoothDeviceInfo); |
| 682 | return d->manufacturerData.value(akey: manufacturerId); |
| 683 | } |
| 684 | |
| 685 | /*! |
| 686 | Sets the advertised manufacturer \a data for the given \a manufacturerId. |
| 687 | Returns \c true if it was inserted, \c false if it was already known. |
| 688 | |
| 689 | Since Qt 5.14, different values for \a data and the same \a manufacturerId no longer |
| 690 | replace each other but are accumulated for the duration of a device scan. |
| 691 | |
| 692 | \sa manufacturerData |
| 693 | \since 5.12 |
| 694 | */ |
| 695 | bool QBluetoothDeviceInfo::setManufacturerData(quint16 manufacturerId, const QByteArray &data) |
| 696 | { |
| 697 | Q_D(QBluetoothDeviceInfo); |
| 698 | auto it = d->manufacturerData.constFind(akey: manufacturerId); |
| 699 | while (it != d->manufacturerData.cend() && it.key() == manufacturerId) { |
| 700 | if (*it == data) |
| 701 | return false; |
| 702 | it++; |
| 703 | } |
| 704 | |
| 705 | d->manufacturerData.insert(akey: manufacturerId, avalue: data); |
| 706 | return true; |
| 707 | } |
| 708 | |
| 709 | /*! |
| 710 | Returns the complete set of all manufacturer data. |
| 711 | |
| 712 | Some devices may provide multiple manufacturer data entries per manufacturer ID. |
| 713 | An example might be a Bluetooth Low Energy device that sends a different manufacturer data via |
| 714 | advertisement packets and scan response packets respectively. Therefore the returned hash table |
| 715 | may have multiple entries per manufacturer ID or hash key. |
| 716 | |
| 717 | \sa setManufacturerData |
| 718 | \since 5.12 |
| 719 | */ |
| 720 | QHash<quint16, QByteArray> QBluetoothDeviceInfo::manufacturerData() const |
| 721 | { |
| 722 | Q_D(const QBluetoothDeviceInfo); |
| 723 | return d->manufacturerData; |
| 724 | } |
| 725 | |
| 726 | /*! |
| 727 | Sets the CoreConfigurations of the device to \a coreConfigs. This will help to make a difference |
| 728 | between regular and Low Energy devices. |
| 729 | |
| 730 | \sa coreConfigurations() |
| 731 | \since 5.4 |
| 732 | */ |
| 733 | void QBluetoothDeviceInfo::setCoreConfigurations(QBluetoothDeviceInfo::CoreConfigurations coreConfigs) |
| 734 | { |
| 735 | Q_D(QBluetoothDeviceInfo); |
| 736 | |
| 737 | d->deviceCoreConfiguration = coreConfigs; |
| 738 | } |
| 739 | |
| 740 | /*! |
| 741 | |
| 742 | Returns the configuration of the device. If device configuration is not set, |
| 743 | basic rate device configuration will be returned. |
| 744 | |
| 745 | \sa setCoreConfigurations() |
| 746 | \since 5.4 |
| 747 | */ |
| 748 | QBluetoothDeviceInfo::CoreConfigurations QBluetoothDeviceInfo::coreConfigurations() const |
| 749 | { |
| 750 | Q_D(const QBluetoothDeviceInfo); |
| 751 | |
| 752 | return d->deviceCoreConfiguration; |
| 753 | } |
| 754 | |
| 755 | /*! |
| 756 | Returns true if the QBluetoothDeviceInfo object is created from cached data. |
| 757 | */ |
| 758 | bool QBluetoothDeviceInfo::isCached() const |
| 759 | { |
| 760 | Q_D(const QBluetoothDeviceInfo); |
| 761 | |
| 762 | return d->cached; |
| 763 | } |
| 764 | |
| 765 | /*! |
| 766 | Used by the system to set the \a cached flag if the QBluetoothDeviceInfo is created from cached data. Cached |
| 767 | information may not be as accurate as data read from an active device. |
| 768 | */ |
| 769 | void QBluetoothDeviceInfo::setCached(bool cached) |
| 770 | { |
| 771 | Q_D(QBluetoothDeviceInfo); |
| 772 | |
| 773 | d->cached = cached; |
| 774 | } |
| 775 | |
| 776 | /*! |
| 777 | Sets the unique identifier \a uuid for Bluetooth devices, that do not have addresses. |
| 778 | This happens on \macos and iOS, where the CoreBluetooth API hides addresses, but provides |
| 779 | UUIDs to identify devices/peripherals. |
| 780 | |
| 781 | This uuid is invalid on any other platform. |
| 782 | |
| 783 | \sa deviceUuid() |
| 784 | \since 5.5 |
| 785 | */ |
| 786 | void QBluetoothDeviceInfo::setDeviceUuid(const QBluetoothUuid &uuid) |
| 787 | { |
| 788 | Q_D(QBluetoothDeviceInfo); |
| 789 | |
| 790 | d->deviceUuid = uuid; |
| 791 | } |
| 792 | |
| 793 | /*! |
| 794 | Returns a unique identifier for a Bluetooth device without an address. |
| 795 | |
| 796 | In general, this uuid is invalid on every platform but \macos and iOS. |
| 797 | It is used as a workaround for those two platforms as they do not |
| 798 | provide Bluetooth addresses for found Bluetooth Low Energy devices. |
| 799 | Every other platform uses \l address() instead. |
| 800 | |
| 801 | \sa setDeviceUuid() |
| 802 | \since 5.5 |
| 803 | */ |
| 804 | QBluetoothUuid QBluetoothDeviceInfo::deviceUuid() const |
| 805 | { |
| 806 | Q_D(const QBluetoothDeviceInfo); |
| 807 | |
| 808 | return d->deviceUuid; |
| 809 | } |
| 810 | |
| 811 | QT_END_NAMESPACE |
| 812 | |