From a6c18d1babb2b38ade3d7a67c0a903701ef3ebf2 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 28 Oct 2014 16:44:15 +0100 Subject: 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 --- src/bluetooth/qbluetoothdeviceinfo.cpp | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'src/bluetooth/qbluetoothdeviceinfo.cpp') 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 @@ -306,6 +306,37 @@ QBluetoothDeviceInfo::QBluetoothDeviceInfo(const QBluetoothAddress &address, con d->rssi = 0; } +/*! + 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((classOfDevice >> 2) & 0x3f); + d->majorDeviceClass = static_cast((classOfDevice >> 8) & 0x1f); + d->serviceClasses = static_cast((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. */ @@ -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 -- cgit v1.2.3