diff options
author | Timur Pocheptsov <Timur.Pocheptsov@digia.com> | 2015-02-06 10:17:51 +0100 |
---|---|---|
committer | Timur Pocheptsov <Timur.Pocheptsov@digia.com> | 2015-02-06 11:40:31 +0000 |
commit | 515ccffb8d56b42c89e9c2c04abe0ef2619ece4e (patch) | |
tree | a1f3f714f1d1b6f5047551f34ae96c5617ff37d3 /src/bluetooth/qbluetoothserviceinfo_osx.mm | |
parent | 3a443d269bdb0b5becfe36069bdff40bdff42277 (diff) |
Bluetooth - add runtime OS version check (OS X)
Compile time checks (SDK version) are not sufficient, add runtime checks
also.
Change-Id: I4214d0a32544883d07da06a2ce2db24ea42678cf
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/bluetooth/qbluetoothserviceinfo_osx.mm')
-rw-r--r-- | src/bluetooth/qbluetoothserviceinfo_osx.mm | 76 |
1 files changed, 52 insertions, 24 deletions
diff --git a/src/bluetooth/qbluetoothserviceinfo_osx.mm b/src/bluetooth/qbluetoothserviceinfo_osx.mm index 1240df18..abe3fc75 100644 --- a/src/bluetooth/qbluetoothserviceinfo_osx.mm +++ b/src/bluetooth/qbluetoothserviceinfo_osx.mm @@ -47,6 +47,7 @@ #include <QtCore/qloggingcategory.h> #include <QtCore/qvariant.h> +#include <QtCore/qsysinfo.h> #include <QtCore/qglobal.h> #include <QtCore/qmutex.h> #include <QtCore/qmap.h> @@ -66,7 +67,11 @@ namespace { class ServiceRecordRefGuard { public: - ServiceRecordRefGuard(IOBluetoothSDPServiceRecordRef r) + ServiceRecordRefGuard() + : recordRef(Q_NULLPTR) + { + } + explicit ServiceRecordRefGuard(IOBluetoothSDPServiceRecordRef r) : recordRef(r) { } @@ -76,6 +81,14 @@ public: CFRelease(recordRef); } + void reset(IOBluetoothSDPServiceRecordRef r) + { + if (recordRef) + CFRelease(recordRef); + // Take the ownership: + recordRef = r; + } + private: IOBluetoothSDPServiceRecordRef recordRef; @@ -138,23 +151,28 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca return false; } + ServiceRecordRefGuard refGuard; SDPRecord newRecord; -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_NA) - newRecord.reset([[IOBluetoothSDPServiceRecord - publishedServiceRecordWithDictionary:serviceDict] retain]); +#if QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9) + if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_9) { + newRecord.reset([[IOBluetoothSDPServiceRecord + publishedServiceRecordWithDictionary:serviceDict] retain]); + } else { #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) << Q_FUNC_INFO << "failed to register a service record"; - return false; - } - - const ServiceRecordRefGuard refGuard(recordRef); - newRecord.reset([[IOBluetoothSDPServiceRecord withSDPServiceRecordRef:recordRef] retain]); - // It's weird, but ... it's not possible to release a record ref yet. + { #endif + 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) << Q_FUNC_INFO << "failed to register a service record"; + return false; + } + + refGuard.reset(recordRef); + newRecord.reset([[IOBluetoothSDPServiceRecord withSDPServiceRecordRef:recordRef] retain]); + // It's weird, but ... it's not possible to release a record ref yet. + } if (!newRecord) { qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to register a service record"; @@ -166,8 +184,9 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca BluetoothSDPServiceRecordHandle newRecordHandle = 0; if ([newRecord getServiceRecordHandle:&newRecordHandle] != kIOReturnSuccess) { qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to register a service record"; -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_NA) - [newRecord removeServiceRecord]; +#if QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9) + if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_9) + [newRecord removeServiceRecord]; #endif // With SDK < 10.9 there is no way to unregister at this point ... return false; @@ -195,11 +214,16 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca } if (!configured) { -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_NA) - [newRecord removeServiceRecord]; +#if QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9) + if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_9) { + [newRecord removeServiceRecord]; + } else { #else - IOBluetoothRemoveServiceWithRecordHandle(newRecordHandle); + {// Just to balance braces ... #endif + IOBluetoothRemoveServiceWithRecordHandle(newRecordHandle); + } + qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to register a service record"; return false; } @@ -226,12 +250,16 @@ bool QBluetoothServiceInfoPrivate::unregisterService() Q_ASSERT_X(serviceRecord, Q_FUNC_INFO, "service registered, but serviceRecord is nil"); -#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_NA) - [serviceRecord removeServiceRecord]; +#if QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9) + if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_9) { + [serviceRecord removeServiceRecord]; + } else { #else - // Assert on newRecordHandle? Is 0 a valid/invalid handle? - IOBluetoothRemoveServiceWithRecordHandle(serviceRecordHandle); + { #endif + // Assert on newRecordHandle? Is 0 a valid/invalid handle? + IOBluetoothRemoveServiceWithRecordHandle(serviceRecordHandle); + } serviceRecord.reset(nil); |