From 2917e641defac2302e8204bb0570a5150b9923d4 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 30 Sep 2014 17:12:02 +0200 Subject: QtBluetooth - enable auto tests on OS X. The first patch to enable tests - does not require any modifications in tests, just enabling the test. Add fix for publishedRecordWithDictioinary - this function is new in 10.9, deprecating withSDPRe..., but it crashed the test on 10.7 (and the same must happen on 10.8). Change-Id: I38e92cbc6f72fcaf8034824ef734148111139e0a Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothserviceinfo_osx.mm | 45 ++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'src/bluetooth/qbluetoothserviceinfo_osx.mm') diff --git a/src/bluetooth/qbluetoothserviceinfo_osx.mm b/src/bluetooth/qbluetoothserviceinfo_osx.mm index 59a631b0..2ab2c9f1 100644 --- a/src/bluetooth/qbluetoothserviceinfo_osx.mm +++ b/src/bluetooth/qbluetoothserviceinfo_osx.mm @@ -57,6 +57,29 @@ QT_BEGIN_NAMESPACE +namespace { + +// This is not in osxbtutility_p, since it's not required +// in general and just fixes the problem with SDK < 10.9, +// where we have to care about about IOBluetoothSDPServiceRecordRef. +class ServiceRecordDeleter +{ +public: + ServiceRecordDeleter(IOBluetoothSDPServiceRecordRef r) + : recordRef(r) + { + } + ~ServiceRecordDeleter() + { + if (recordRef) // Requires non-NULL pointers. + CFRelease(recordRef); + } + + IOBluetoothSDPServiceRecordRef recordRef; +}; + +} + class QBluetoothServiceInfoPrivate { public: @@ -119,8 +142,26 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca return false; } - SDPRecord newRecord([[IOBluetoothSDPServiceRecord - publishedServiceRecordWithDictionary:serviceDict] retain]); + SDPRecord newRecord; + +#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_NA) + newRecord.reset([[IOBluetoothSDPServiceRecord + publishedServiceRecordWithDictionary:serviceDict] retain]); + +#else + IOBluetoothSDPServiceRecordRef recordRef = Q_NULLPTR; + // With ARC this will require a different cast? + const IOReturn status = IOBluetoothAddServiceDict((CFDictionaryRef)serviceDict.data(), &recordRef); + if (status != kIOReturnSuccess) { + qCWarning(QT_BT_OSX) << "QBluetoothServiceInfoPrivate::registerService(), " + "failed to create register a service record"; + return false; + } + + const ServiceRecordDeleter refGuard(recordRef); + newRecord.reset([[IOBluetoothSDPServiceRecord withSDPServiceRecordRef:recordRef] retain]); + // It's weird, but ... it's not possible to release a record ref yet! +#endif if (!newRecord) { qCWarning(QT_BT_OSX) << "QBluetoothServiceInfoPrivate::registerService(), " -- cgit v1.2.3