diff options
-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 | ||||
-rw-r--r-- | tests/auto/qbluetoothuuid/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/auto/qbluetoothuuid/tst_qbluetoothuuid.cpp | 21 |
5 files changed, 79 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 diff --git a/tests/auto/qbluetoothuuid/CMakeLists.txt b/tests/auto/qbluetoothuuid/CMakeLists.txt index 214323a3..f9414100 100644 --- a/tests/auto/qbluetoothuuid/CMakeLists.txt +++ b/tests/auto/qbluetoothuuid/CMakeLists.txt @@ -10,4 +10,5 @@ qt_internal_add_test(tst_qbluetoothuuid tst_qbluetoothuuid.cpp LIBRARIES Qt::Bluetooth + Qt::CorePrivate ) diff --git a/tests/auto/qbluetoothuuid/tst_qbluetoothuuid.cpp b/tests/auto/qbluetoothuuid/tst_qbluetoothuuid.cpp index 1c58e60c..e31b0667 100644 --- a/tests/auto/qbluetoothuuid/tst_qbluetoothuuid.cpp +++ b/tests/auto/qbluetoothuuid/tst_qbluetoothuuid.cpp @@ -8,6 +8,10 @@ #include <qbluetoothuuid.h> +#if defined(Q_OS_DARWIN) +#include <QtCore/private/qcore_mac_p.h> +#endif + #if defined(Q_OS_UNIX) # include <arpa/inet.h> # include <netinet/in.h> @@ -229,6 +233,16 @@ void tst_QBluetoothUuid::tst_conversion() else if (constructUuid32) minimumSize = 4; +#if defined(Q_OS_DARWIN) +#define CHECK_PLATFORM_CONVERSION(qtUuid) \ + const QMacAutoReleasePool pool; \ + CBUUID *nativeUuid = qtUuid.toCBUUID(); \ + QVERIFY(nativeUuid); \ + QCOMPARE(qtUuid, QBluetoothUuid::fromCBUUID(nativeUuid)); +#else +#define CHECK_PLATFORM_CONVERSION(qtUuid) +#endif // Q_OS_DARWIN + if (constructUuid16) { QBluetoothUuid uuid(uuid16); @@ -245,6 +259,8 @@ void tst_QBluetoothUuid::tst_conversion() QCOMPARE(uuid.toString().toUpper(), uuidS.toUpper()); QCOMPARE(uuid.minimumSize(), minimumSize); + + CHECK_PLATFORM_CONVERSION(uuid) } if (constructUuid32) { @@ -266,6 +282,8 @@ void tst_QBluetoothUuid::tst_conversion() QCOMPARE(uuid.toString().toUpper(), uuidS.toUpper()); QCOMPARE(uuid.minimumSize(), minimumSize); + + CHECK_PLATFORM_CONVERSION(uuid) } if (constructUuid128) { @@ -288,7 +306,10 @@ void tst_QBluetoothUuid::tst_conversion() QCOMPARE(uuid.toString().toUpper(), uuidS.toUpper()); QCOMPARE(uuid.minimumSize(), minimumSize); + + CHECK_PLATFORM_CONVERSION(uuid) } +#undef CHECK_PLATFORM_CONVERSION } void tst_QBluetoothUuid::tst_comparison_data() |