diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2023-07-18 17:21:01 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-08-03 21:02:37 +0000 |
commit | 289fde9c66ecdfe76051fbd987def3ecea8405f7 (patch) | |
tree | e721c0d176e5483e9abc5405898d1a3b013ceb5b /src | |
parent | b23b40b23222995936af451c903d7e6fc31fe6b2 (diff) |
QBluetoothUuid: keep custom quint128 and related methods when 128-bit ints are not supported
... to retain SC with prior Qt versions.
For QBluetoothUuid::toUInt128() this is done by introducing
an extra condition to the method declaration and definition.
If the 128-bit ints are not supported, we shouldn't hide the
method under QT_BLUETOOTH_REMOVED_SINCE.
The QBluetoothUuid(quint128) c-tor is a bit more tricky,
because we need to provide a forwarding c-tor to be able to
use QUuid(quint128) c-tor. And at the same time, we need
to keep BC by keeping the constructor that takes custom
struct quint128.
This is achieved by having an unconstrained c-tor declaration
and two implementations:
* an implementation in qbluetoothuuid.cpp is only available
when Qt supports 128-bit ints. It just forwards to the
QUuid c-tor.
* an implementation in removed_api.cpp serves as a backup
implementation to keep BC for the case when Qt supports
128-bit ints. And at the same time it serves as a main
implementation when 128-bit ints are not supported.
Also extend the unit-tests to explicitly check that both
APIs are available on all platforms.
The test additionally makes sure that QUuid::toUInt128() and
QBluetoothUuid::toUInt128() provide the result which is similar to
QUuid::toBytes(). This guarantees compatibility between platforms.
This commit amends 1e903be81f43da4e31385bb7866bb4d3f07e5eba.
Change-Id: I6ba3ff6278e6db11a372b46f001429f4466520a0
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 5d90296f312f72ffa6a5322df7b565c3e5521684)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/bluetooth/qbluetoothuuid.cpp | 31 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothuuid.h | 6 | ||||
-rw-r--r-- | src/bluetooth/removed_api.cpp | 23 |
3 files changed, 48 insertions, 12 deletions
diff --git a/src/bluetooth/qbluetoothuuid.cpp b/src/bluetooth/qbluetoothuuid.cpp index 47761e52..5338c978 100644 --- a/src/bluetooth/qbluetoothuuid.cpp +++ b/src/bluetooth/qbluetoothuuid.cpp @@ -532,6 +532,37 @@ Q_CONSTRUCTOR_FUNCTION(registerQBluetoothUuid) */ /*! + \fn quint128 QBluetoothUuid::toUInt128() const + + Returns the 128 bit representation of this UUID. + + \note The returned value is in big endian order. + + This method is only available when the platform \e {does not} support + native 128 bit integral values. Otherwise, the call will resolve to + \l QUuid::toUInt128(), which also allows to specify the desired endian + order of the returned value. +*/ + +/*! + \fn QBluetoothUuid::QBluetoothUuid(quint128 uuid) + + Constructs a new Bluetooth UUID from a 128 bit \a uuid. + + \note The \a uuid must be in big endian order. +*/ +#ifdef QT_SUPPORTS_INT128 +// This implementation is used only when 128-bit ints are supported. +// The old implementation which uses struct quint128 can be found in +// removed_api.cpp. We need to keep it there, because we need to provide both +// implementations for BC +QBluetoothUuid::QBluetoothUuid(quint128 uuid) + : QUuid(uuid, QSysInfo::BigEndian) +{ +} +#endif + +/*! Creates a QBluetoothUuid object from the string \a uuid, which must be formatted as five hex fields separated by '-', e.g., "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where 'x' is a hex digit. diff --git a/src/bluetooth/qbluetoothuuid.h b/src/bluetooth/qbluetoothuuid.h index 7717410e..d599c573 100644 --- a/src/bluetooth/qbluetoothuuid.h +++ b/src/bluetooth/qbluetoothuuid.h @@ -18,7 +18,7 @@ Q_FORWARD_DECLARE_OBJC_CLASS(CBUUID); QT_BEGIN_NAMESPACE -#if QT_BLUETOOTH_REMOVED_SINCE(6, 6) +#if QT_BLUETOOTH_REMOVED_SINCE(6, 6) || !defined(QT_SUPPORTS_INT128) struct quint128 { quint8 data[16]; @@ -351,6 +351,7 @@ public: explicit constexpr QBluetoothUuid(quint32 uuid) noexcept : QUuid(uuid, 0x0, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb) {}; + explicit QBluetoothUuid(quint128 uuid); explicit QBluetoothUuid(QUuid::Id128Bytes uuid) noexcept : QUuid(uuid) {}; explicit QBluetoothUuid(const QString &uuid); @@ -377,8 +378,7 @@ public: quint16 toUInt16(bool *ok = nullptr) const; quint32 toUInt32(bool *ok = nullptr) const; -#if QT_BLUETOOTH_REMOVED_SINCE(6, 6) - explicit QBluetoothUuid(quint128 uuid); +#if QT_BLUETOOTH_REMOVED_SINCE(6, 6) || !defined(QT_SUPPORTS_INT128) quint128 toUInt128() const; #endif diff --git a/src/bluetooth/removed_api.cpp b/src/bluetooth/removed_api.cpp index 2a346424..e2536be9 100644 --- a/src/bluetooth/removed_api.cpp +++ b/src/bluetooth/removed_api.cpp @@ -2,21 +2,18 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #define QT_BLUETOOTH_BUILD_REMOVED_API -// before we undef __SIZEOF_INT128__ -#include <cstddef> -#include <cstdint> -#ifdef __SIZEOF_INT128__ -// ensure QtCore/qtypes.h doesn't define quint128 -# undef __SIZEOF_INT128__ -#endif +// Undefine Qt 128-bit int types +#define QT_NO_INT128 #include "qtbluetoothglobal.h" QT_USE_NAMESPACE -#if QT_BLUETOOTH_REMOVED_SINCE(6, 6) -#include "qbluetoothaddress.h" // inlined API +// This part is not typical to the removed_api.cpp, because we need to have +// an extra condition. When adding new removed APIs for Qt 6.6, do not put them +// into this section. Instead, add them to the section below. +#if QT_BLUETOOTH_REMOVED_SINCE(6, 6) || !defined(QT_SUPPORTS_INT128) #include "qbluetoothuuid.h" @@ -34,4 +31,12 @@ quint128 QBluetoothUuid::toUInt128() const memcpy(uuid.data, bytes.data, sizeof(uuid.data)); return uuid; } + +#endif // QT_BLUETOOTH_REMOVED_SINCE(6, 6) || !defined(QT_SUPPORTS_INT128) + +// This is a common section for Qt 6.6 removed APIs +#if QT_BLUETOOTH_REMOVED_SINCE(6, 6) + +#include "qbluetoothaddress.h" // inlined API + #endif // QT_BLUETOOTH_REMOVED_SINCE(6, 6) |