diff options
author | Alex Blasche <alexander.blasche@qt.io> | 2018-10-16 08:34:04 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@qt.io> | 2018-10-16 09:46:17 +0200 |
commit | cfa14f0f2ed4bee62ebcfa1191877086f44deeef (patch) | |
tree | e5622c6422f3de193a3eefc6929e3b4b038585d2 /src/bluetooth/osx | |
parent | 5ac4a2ce452d4ab9b8529a35c266c4323e455f12 (diff) | |
parent | dfee9aa22f2dbaae3476770d0ab65f26494fe451 (diff) |
Merge remote-tracking branch 'gerrit/5.12' into dev
Conflicts:
src/bluetooth/osx/osxbtsdpinquiry.mm
Change-Id: I637adc5a5271e136af7d0ac6380086728ffb15c5
Diffstat (limited to 'src/bluetooth/osx')
-rw-r--r-- | src/bluetooth/osx/osxbtsdpinquiry.mm | 79 |
1 files changed, 74 insertions, 5 deletions
diff --git a/src/bluetooth/osx/osxbtsdpinquiry.mm b/src/bluetooth/osx/osxbtsdpinquiry.mm index 88849872..5b58bc62 100644 --- a/src/bluetooth/osx/osxbtsdpinquiry.mm +++ b/src/bluetooth/osx/osxbtsdpinquiry.mm @@ -53,6 +53,64 @@ SDPInquiryDelegate::~SDPInquiryDelegate() { } +namespace { + +QBluetoothUuid sdp_element_to_uuid(IOBluetoothSDPDataElement *element) +{ + QT_BT_MAC_AUTORELEASEPOOL; + + if (!element || [element getTypeDescriptor] != kBluetoothSDPDataElementTypeUUID) + return {}; + + return qt_uuid([[element getUUIDValue] getUUIDWithLength:16]); +} + +QBluetoothUuid extract_service_ID(IOBluetoothSDPServiceRecord *record) +{ + Q_ASSERT(record); + + QT_BT_MAC_AUTORELEASEPOOL; + + return sdp_element_to_uuid([record getAttributeDataElement:kBluetoothSDPAttributeIdentifierServiceID]); +} + +QVector<QBluetoothUuid> extract_service_class_ID_list(IOBluetoothSDPServiceRecord *record) +{ + Q_ASSERT(record); + + QT_BT_MAC_AUTORELEASEPOOL; + + IOBluetoothSDPDataElement *const idList = [record getAttributeDataElement:kBluetoothSDPAttributeIdentifierServiceClassIDList]; + if (!idList || [idList getTypeDescriptor] != kBluetoothSDPDataElementTypeDataElementSequence) + return {}; + + QVector<QBluetoothUuid> uuids; + NSArray *const arr = [idList getArrayValue]; + for (IOBluetoothSDPDataElement *dataElement in arr) { + const auto qtUuid = sdp_element_to_uuid(dataElement); + if (!qtUuid.isNull()) + uuids.push_back(qtUuid); + } + + return uuids; +} + +QBluetoothServiceInfo::Sequence service_class_ID_list_to_sequence(const QVector<QBluetoothUuid> &uuids) +{ + if (uuids.isEmpty()) + return {}; + + QBluetoothServiceInfo::Sequence sequence; + for (const auto &uuid : uuids) { + Q_ASSERT(!uuid.isNull()); + sequence.append(QVariant::fromValue(uuid)); + } + + return sequence; +} + +} // unnamed namespace + QVariant extract_attribute_value(IOBluetoothSDPDataElement *dataElement) { Q_ASSERT_X(dataElement, Q_FUNC_INFO, "invalid data element (nil)"); @@ -72,7 +130,7 @@ QVariant extract_attribute_value(IOBluetoothSDPDataElement *dataElement) case kBluetoothSDPDataElementTypeSignedInt: return [[dataElement getNumberValue] intValue]; case kBluetoothSDPDataElementTypeUUID: - return QVariant::fromValue(qt_uuid([[dataElement getUUIDValue] getUUIDWithLength:16])); + return QVariant::fromValue(sdp_element_to_uuid(dataElement)); case kBluetoothSDPDataElementTypeString: case kBluetoothSDPDataElementTypeURL: return QString::fromNSString([dataElement getStringValue]); @@ -110,6 +168,15 @@ void extract_service_record(IOBluetoothSDPServiceRecord *record, QBluetoothServi const QVariant attributeValue = OSXBluetooth::extract_attribute_value(element); serviceInfo.setAttribute(attributeID, attributeValue); } + + const QBluetoothUuid serviceUuid = extract_service_ID(record); + if (!serviceUuid.isNull()) + serviceInfo.setServiceUuid(serviceUuid); + + const QVector<QBluetoothUuid> uuids(extract_service_class_ID_list(record)); + const auto sequence = service_class_ID_list_to_sequence(uuids); + if (!sequence.isEmpty()) + serviceInfo.setAttribute(QBluetoothServiceInfo::ServiceClassIds, sequence); } QVector<QBluetoothUuid> extract_services_uuids(IOBluetoothDevice *device) @@ -124,11 +191,13 @@ QVector<QBluetoothUuid> extract_services_uuids(IOBluetoothDevice *device) NSArray * const records = device.services; for (IOBluetoothSDPServiceRecord *record in records) { - IOBluetoothSDPDataElement *const element = - [record getAttributeDataElement:kBluetoothSDPAttributeIdentifierServiceClassIDList]; + const QBluetoothUuid serviceID = extract_service_ID(record); + if (!serviceID.isNull()) + uuids.push_back(serviceID); - if (element && [element getTypeDescriptor] == kBluetoothSDPDataElementTypeUUID) - uuids.append(qt_uuid([[element getUUIDValue] getUUIDWithLength:16])); + const QVector<QBluetoothUuid> idList(extract_service_class_ID_list(record)); + if (idList.size()) + uuids.append(idList); } return uuids; |