diff options
author | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2023-03-27 10:15:18 +0200 |
---|---|---|
committer | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2023-04-03 10:59:34 +0200 |
commit | 55abcc47ee36e901b6f14d08d9a2ea0483b40dab (patch) | |
tree | 26da3974d92269d1e2b8059ee9cc0420f43574f3 /src | |
parent | 913fb687a2f59003e81a42785b02450ffd3788cd (diff) |
QBluetoothUuid - add platform-specific conversion functions
Namely: fromCBUUID and toCBUUID, similar to fromNSUUID and toNSUUID that
we already have.
[ChangeLog][QtBluetooth] Add CoreBluetooth-specific conversion to
QBluetoothUuid class, to get CBUUID out of QBluetoothUuid and convert
CBUUID to QBluetoothUuid.
Fixes: QTBUG-112303
Change-Id: I4ca0b13395b4346f7c830a0e042a16f976998a33
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/bluetooth/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothuuid.h | 9 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothuuid_darwin.mm | 46 |
3 files changed, 57 insertions, 0 deletions
diff --git a/src/bluetooth/CMakeLists.txt b/src/bluetooth/CMakeLists.txt index 45cddda3..a603e3c9 100644 --- a/src/bluetooth/CMakeLists.txt +++ b/src/bluetooth/CMakeLists.txt @@ -190,6 +190,7 @@ elseif(MACOS) qbluetoothserviceinfo_macos.mm qbluetoothsocket_macos.mm qbluetoothsocket_macos_p.h qlowenergycontroller_darwin.mm qlowenergycontroller_darwin_p.h + qbluetoothuuid_darwin.mm DEFINES QT_OSX_BLUETOOTH LIBRARIES @@ -216,6 +217,7 @@ elseif(IOS) qbluetoothsocket_dummy.cpp qbluetoothsocket_dummy_p.h qlowenergycontroller_darwin.mm qlowenergycontroller_darwin_p.h darwin/btperipheralmanager.mm darwin/btperipheralmanager_p.h + qbluetoothuuid_darwin.mm DEFINES QT_IOS_BLUETOOTH LIBRARIES diff --git a/src/bluetooth/qbluetoothuuid.h b/src/bluetooth/qbluetoothuuid.h index 6ee1f26f..0978780d 100644 --- a/src/bluetooth/qbluetoothuuid.h +++ b/src/bluetooth/qbluetoothuuid.h @@ -12,6 +12,10 @@ #include <QtCore/QDebug> +#if defined(Q_OS_DARWIN) || defined(Q_QDOC) +Q_FORWARD_DECLARE_OBJC_CLASS(CBUUID); +#endif + QT_BEGIN_NAMESPACE #if QT_BLUETOOTH_REMOVED_SINCE(6, 6) @@ -376,6 +380,11 @@ public: quint128 toUInt128() const; #endif +#if defined(Q_OS_DARWIN) || defined(Q_QDOC) + static QBluetoothUuid fromCBUUID(CBUUID *cbUuid); + CBUUID *toCBUUID() const Q_DECL_NS_RETURNS_AUTORELEASED; +#endif + static QString serviceClassToString(ServiceClassUuid uuid); static QString protocolToString(ProtocolUuid uuid); static QString characteristicToString(CharacteristicType uuid); diff --git a/src/bluetooth/qbluetoothuuid_darwin.mm b/src/bluetooth/qbluetoothuuid_darwin.mm new file mode 100644 index 00000000..056a2666 --- /dev/null +++ b/src/bluetooth/qbluetoothuuid_darwin.mm @@ -0,0 +1,46 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#include "darwin/btutility_p.h" + +#include "qbluetoothuuid.h" + +QT_BEGIN_NAMESPACE + +/*! + \brief Constructs a new QBluetoothUuid, containing a copy of the \a cbUuid CBUUID. + + \note this function is only available on Apple platforms. + + \since 6.6 + \ingroup platform-type-conversions +*/ +QBluetoothUuid QBluetoothUuid::fromCBUUID(CBUUID *cbUuid) +{ + if (!cbUuid) + return {}; + + return DarwinBluetooth::qt_uuid(cbUuid); +} + +/*! + \brief Creates a CBUUID from a QBluetoothUuid. + + The resulting CBUUID is autoreleased. + + \note this function is only available on Apple platforms. + + \since 6.6 + \ingroup platform-type-conversions +*/ + +CBUUID *QBluetoothUuid::toCBUUID() const +{ + const auto cbUuidGuard = DarwinBluetooth::cb_uuid(*this); + // cb_uuid returns a strong reference (RAII object). Let + // it do its job and release, but we return auto-released + // CBUUID, as documented. + return [[cbUuidGuard.data() retain] autorelease]; +} + +QT_END_NAMESPACE |