49QBluetoothAddress
qt_address(
const BluetoothDeviceAddress *a)
53 const quint64 qAddress = a->data[5] |
54 qint64(a->data[4]) << 8 |
55 qint64(a->data[3]) << 16 |
56 qint64(a->data[2]) << 24 |
57 qint64(a->data[1]) << 32 |
58 qint64(a->data[0]) << 40;
59 return QBluetoothAddress(qAddress);
62 return QBluetoothAddress();
67 BluetoothDeviceAddress a = {};
68 if (!qAddress.isNull()) {
69 const quint64 val = qAddress.toUInt64();
70 a.data[0] = (val >> 40) & 0xff;
71 a.data[1] = (val >> 32) & 0xff;
72 a.data[2] = (val >> 24) & 0xff;
73 a.data[3] = (val >> 16) & 0xff;
74 a.data[4] = (val >> 8) & 0xff;
75 a.data[5] = val & 0xff;
91QBluetoothUuid qt_uuid(IOBluetoothSDPUUID *uuid)
93 QBluetoothUuid qtUuid;
94 if (!uuid || [uuid length] != 16)
98 QUuid::Id128Bytes uuidVal = {};
99 const quint8 *
const source =
static_cast<
const quint8 *>([uuid bytes]);
100 std::copy(source, source + 16, uuidVal.data);
101 return QBluetoothUuid(uuidVal);
142QBluetoothUuid qt_uuid(CBUUID *uuid)
149 return QBluetoothUuid();
153 if (uuid.data.length == 2) {
156 const uchar *
const src =
static_cast<
const uchar *>(uuid.data.bytes);
157 return QBluetoothUuid(qFromBigEndian<quint16>(src));
158 }
else if (uuid.data.length == 4) {
159 const uchar *
const src =
static_cast<
const uchar *>(uuid.data.bytes);
160 return QBluetoothUuid(qFromBigEndian<quint32>(src));
161 }
else if (uuid.data.length == 16) {
162 QUuid::Id128Bytes qtUuidData = {};
163 const quint8 *
const source =
static_cast<
const quint8 *>(uuid.data.bytes);
164 std::copy(source, source + 16, qtUuidData.data);
166 return QBluetoothUuid(qtUuidData);
169 qCDebug(QT_BT_DARWIN) <<
"qt_uuid, invalid CBUUID, 2, 4, or 16 bytes expected, but got "
170 << uuid.data.length <<
" bytes length";
171 return QBluetoothUuid();
174ObjCStrongReference<CBUUID> cb_uuid(
const QBluetoothUuid &qtUuid)
177 const auto asUInt16 = qToBigEndian(qtUuid.toUInt16(&ok));
178 const auto asUInt128 = qtUuid.toBytes();
180 const NSUInteger length = ok ?
sizeof asUInt16 :
sizeof asUInt128;
181 const void *bytes = &asUInt128;
185 NSData *uuidData = [NSData dataWithBytes:bytes length:length];
186 ObjCStrongReference<CBUUID> cbUuid([CBUUID UUIDWithData:uuidData], RetainPolicy::doInitialRetain);
236QByteArray qt_bytearray(NSObject *obj)
258 if ([obj isKindOfClass:[NSData
class]]) {
259 return qt_bytearray(
static_cast<NSData *>(obj));
260 }
else if ([obj isKindOfClass:[NSString
class]]) {
261 return qt_bytearray(
static_cast<NSString *>(obj));
262 }
else if ([obj isKindOfClass:[NSNumber
class]]) {
263 NSNumber *
const nsNumber =
static_cast<NSNumber *>(obj);
264 return qt_bytearray([nsNumber unsignedShortValue]);
272ObjCStrongReference<NSData> data_from_bytearray(
const QByteArray & qtData)
275 return ObjCStrongReference<NSData>([[NSData alloc] init], RetainPolicy::noInitialRetain);
277 ObjCStrongReference<NSData> result([NSData dataWithBytes:qtData.constData() length:qtData.size()], RetainPolicy::doInitialRetain);
281ObjCStrongReference<NSMutableData> mutable_data_from_bytearray(
const QByteArray &qtData)
283 using MutableData = ObjCStrongReference<NSMutableData>;
286 return MutableData([[NSMutableData alloc] init], RetainPolicy::noInitialRetain);
288 MutableData result([[NSMutableData alloc] initWithLength:qtData.size()], RetainPolicy::noInitialRetain);
289 [result replaceBytesInRange:NSMakeRange(0, qtData.size())
290 withBytes:qtData.constData()];