diff options
author | Timur Pocheptsov <Timur.Pocheptsov@digia.com> | 2014-10-28 16:44:15 +0100 |
---|---|---|
committer | Timur Pocheptsov <Timur.Pocheptsov@digia.com> | 2014-10-29 10:31:40 +0100 |
commit | a6c18d1babb2b38ade3d7a67c0a903701ef3ebf2 (patch) | |
tree | 8bb9dffc49a612a36371adc8148c7eaf2364bcbd /src/bluetooth/qbluetoothdeviceinfo.cpp | |
parent | a3d24e23f20b88d941c014bb92e6511a2a3f0d01 (diff) |
QBluetoothDeviceInfo - add "non-addressable" devices support
On OS X and iOS CoreBluetooth hides addresses from a user, providing
NSUUID (similar to uuid, by generated by Apple) to identify devices ("peripherals").
Since we still must be able to somehow "address" these devices later,
we use these (unique) uuids instead of addresses for LE devices:
add a data-member, setter/getter/ctor + update operators '=' and '=='.
Change-Id: I74b73c1413d7014e04cbfda6cef501defa15ed8e
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/bluetooth/qbluetoothdeviceinfo.cpp')
-rw-r--r-- | src/bluetooth/qbluetoothdeviceinfo.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/bluetooth/qbluetoothdeviceinfo.cpp b/src/bluetooth/qbluetoothdeviceinfo.cpp index c0562c45..b8a68113 100644 --- a/src/bluetooth/qbluetoothdeviceinfo.cpp +++ b/src/bluetooth/qbluetoothdeviceinfo.cpp @@ -307,6 +307,37 @@ QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothAddress &address, con } /*! + Constructs a QBluetoothDeviceInfo object with unique \a uuid, device name + \a name and the encoded class of device \a classOfDevice. + + This constructor is required for Low Energy devices on OS X and iOS. CoreBluetooth + API hides addresses and provides unique UUIDs to identify a device. This UUID is + not the same thing as a service UUID and is required to work later with CoreBluetooth API + and discovered devices. + + \since 5.5 +*/ +QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothUuid &uuid, const QString &name, + quint32 classOfDevice) : + d_ptr(new QBluetoothDeviceInfoPrivate) +{ + Q_D(QBluetoothDeviceInfo); + + d->name = name; + d->deviceUuid = uuid; + + d->minorDeviceClass = static_cast<quint8>((classOfDevice >> 2) & 0x3f); + d->majorDeviceClass = static_cast<MajorDeviceClass>((classOfDevice >> 8) & 0x1f); + d->serviceClasses = static_cast<ServiceClasses>((classOfDevice >> 13) & 0x7ff); + + d->serviceUuidsCompleteness = DataUnavailable; + + d->valid = true; + d->cached = false; + d->rssi = 0; +} + +/*! Constructs a QBluetoothDeviceInfo that is a copy of \a other. */ QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothDeviceInfo &other) : @@ -370,6 +401,7 @@ QBluetoothDeviceInfo &QBluetoothDeviceInfo::operator=(const QBluetoothDeviceInfo d->serviceUuids = other.d_func()->serviceUuids; d->rssi = other.d_func()->rssi; d->deviceCoreConfiguration = other.d_func()->deviceCoreConfiguration; + d->deviceUuid = other.d_func()->deviceUuid; return *this; } @@ -403,6 +435,8 @@ bool QBluetoothDeviceInfo::operator==(const QBluetoothDeviceInfo &other) const return false; if (d->deviceCoreConfiguration != other.d_func()->deviceCoreConfiguration) return false; + if (d->deviceUuid != other.d_func()->deviceUuid) + return false; return true; } @@ -560,4 +594,32 @@ void QBluetoothDeviceInfo::setCached(bool cached) d->cached = cached; } +/*! + Unique identifier for Bluetooth devices, that do not have addresses. This can happen on OS X and iOS, + where CoreBluetooth API hides addresses, but provides UUIDs to identify devices/peripherals. + This uuid is invalid on any other platform. + + \sa deviceUuid() + \since 5.5 + */ +void QBluetoothDeviceInfo::setDeviceUuid(const QBluetoothUuid &uuid) +{ + Q_D(QBluetoothDeviceInfo); + + d->deviceUuid = uuid; +} + +/*! + Unique identifier for a Bluetooth device without an address. + + \sa setDeviceUuid() + \since 5.5 + */ +QBluetoothUuid QBluetoothDeviceInfo::deviceUuid() const +{ + Q_D(const QBluetoothDeviceInfo); + + return d->deviceUuid; +} + QT_END_NAMESPACE |