summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothserviceinfo_osx.mm
diff options
context:
space:
mode:
authorTimur Pocheptsov <Timur.Pocheptsov@digia.com>2014-09-30 17:12:02 +0200
committerTimur Pocheptsov <Timur.Pocheptsov@digia.com>2014-10-01 15:07:07 +0200
commit2917e641defac2302e8204bb0570a5150b9923d4 (patch)
treeb6d4b45cb38e560c41ed12d94558b15e4d1f5be6 /src/bluetooth/qbluetoothserviceinfo_osx.mm
parentf835812b24b47f1d5a6766fd227ca32559295129 (diff)
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 <alexander.blasche@digia.com>
Diffstat (limited to 'src/bluetooth/qbluetoothserviceinfo_osx.mm')
-rw-r--r--src/bluetooth/qbluetoothserviceinfo_osx.mm45
1 files changed, 43 insertions, 2 deletions
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(), "