summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/bluetooth/darwin/btcentralmanager.mm4
-rw-r--r--src/bluetooth/darwin/btledeviceinquiry.mm13
-rw-r--r--src/bluetooth/darwin/btperipheralmanager.mm43
-rw-r--r--src/bluetooth/darwin/btsdpinquiry.mm19
-rw-r--r--src/bluetooth/darwin/btutility_p.h49
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_macos.mm13
-rw-r--r--src/bluetooth/qbluetoothtransferreply_macos.mm19
7 files changed, 77 insertions, 83 deletions
diff --git a/src/bluetooth/darwin/btcentralmanager.mm b/src/bluetooth/darwin/btcentralmanager.mm
index 894243dc..7e0bdda7 100644
--- a/src/bluetooth/darwin/btcentralmanager.mm
+++ b/src/bluetooth/darwin/btcentralmanager.mm
@@ -362,7 +362,7 @@ QT_USE_NAMESPACE
using namespace DarwinBluetooth;
// Retrieve a peripheral first ...
- ObjCScopedPointer<NSMutableArray> uuids([[NSMutableArray alloc] init]);
+ const ObjCScopedPointer<NSMutableArray> uuids([[NSMutableArray alloc] init], RetainPolicy::noInitialRetain);
if (!uuids) {
qCWarning(QT_BT_DARWIN) << "failed to allocate identifiers";
if (notifier)
@@ -374,7 +374,7 @@ QT_USE_NAMESPACE
const quint128 qtUuidData(deviceUuid.toUInt128());
uuid_t uuidData = {};
std::copy(qtUuidData.data, qtUuidData.data + 16, uuidData);
- const ObjCScopedPointer<NSUUID> nsUuid([[NSUUID alloc] initWithUUIDBytes:uuidData]);
+ const ObjCScopedPointer<NSUUID> nsUuid([[NSUUID alloc] initWithUUIDBytes:uuidData], RetainPolicy::noInitialRetain);
if (!nsUuid) {
qCWarning(QT_BT_DARWIN) << "failed to allocate NSUUID identifier";
if (notifier)
diff --git a/src/bluetooth/darwin/btledeviceinquiry.mm b/src/bluetooth/darwin/btledeviceinquiry.mm
index 0f9f02b8..4ac8f0fb 100644
--- a/src/bluetooth/darwin/btledeviceinquiry.mm
+++ b/src/bluetooth/darwin/btledeviceinquiry.mm
@@ -185,7 +185,8 @@ QT_USE_NAMESPACE
dispatch_queue_t leQueue(DarwinBluetooth::qt_LE_queue());
Q_ASSERT(leQueue);
inquiryTimeoutMS = timeout;
- manager.reset([[CBCentralManager alloc] initWithDelegate:self queue:leQueue]);
+ manager.reset([[CBCentralManager alloc] initWithDelegate:self queue:leQueue],
+ DarwinBluetooth::RetainPolicy::noInitialRetain);
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
@@ -204,11 +205,7 @@ QT_USE_NAMESPACE
using namespace DarwinBluetooth;
const auto state = central.state;
-#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) || QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13)
if (state == CBManagerStatePoweredOn) {
-#else
- if (state == CBCentralManagerStatePoweredOn) {
-#endif
if (internalState == InquiryStarting) {
internalState = InquiryActive;
@@ -285,12 +282,8 @@ QT_USE_NAMESPACE
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
if (internalState == InquiryActive) {
- const auto state = manager.data().state;
- #if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) || QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13)
+ const auto state = manager.get().state;
if (state == CBManagerStatePoweredOn)
- #else
- if (state == CBCentralManagerStatePoweredOn)
- #endif
[manager stopScan];
}
diff --git a/src/bluetooth/darwin/btperipheralmanager.mm b/src/bluetooth/darwin/btperipheralmanager.mm
index d4713ace..f282b0f7 100644
--- a/src/bluetooth/darwin/btperipheralmanager.mm
+++ b/src/bluetooth/darwin/btperipheralmanager.mm
@@ -213,7 +213,8 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
notifier = aNotifier;
state = PeripheralState::idle;
nextServiceToAdd = {};
- connectedCentrals.reset([[NSMutableSet alloc] init]);
+ connectedCentrals.reset([[NSMutableSet alloc] init],
+ DarwinBluetooth::RetainPolicy::noInitialRetain);
maxNotificationValueLength = std::numeric_limits<NSUInteger>::max();
}
@@ -292,7 +293,8 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
QT_BT_MAC_AUTORELEASEPOOL
- advertisementData.reset([[NSMutableDictionary alloc] init]);
+ advertisementData.reset([[NSMutableDictionary alloc] init],
+ DarwinBluetooth::RetainPolicy::noInitialRetain);
if (!advertisementData) {
qCWarning(QT_BT_DARWIN) << "setParameters: failed to allocate "
"NSMutableDictonary (advertisementData)";
@@ -311,7 +313,8 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
if (!data.services().count() && !scanResponse.services().count())
return;
- const ObjCScopedPointer<NSMutableArray> uuids([[NSMutableArray alloc] init]);
+ const ObjCScopedPointer<NSMutableArray> uuids([[NSMutableArray alloc] init],
+ DarwinBluetooth::RetainPolicy::noInitialRetain);
if (!uuids) {
qCWarning(QT_BT_DARWIN) << "setParameters: failed to allocate "
"NSMutableArray (services uuids)";
@@ -340,10 +343,11 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
- (void)startAdvertising
{
state = PeripheralState::waitingForPowerOn;
- if (manager.data())
+ if (manager)
[manager setDelegate:nil];
manager.reset([[CBPeripheralManager alloc] initWithDelegate:self
- queue:DarwinBluetooth::qt_LE_queue()]);
+ queue:DarwinBluetooth::qt_LE_queue()],
+ DarwinBluetooth::RetainPolicy::noInitialRetain);
}
- (void)stopAdvertising
@@ -405,7 +409,7 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
- (void) addServicesToPeripheral
{
- Q_ASSERT(manager.data());
+ Q_ASSERT(manager);
if (nextServiceToAdd < services.size())
[manager addService:services[nextServiceToAdd++]];
@@ -421,11 +425,7 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
if (peripheral != manager || !notifier)
return;
-#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) || QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13)
if (peripheral.state == CBManagerStatePoweredOn) {
-#else
- if (peripheral.state == CBPeripheralManagerStatePoweredOn) {
-#endif
// "Bluetooth is currently powered on and is available to use."
if (state == PeripheralState::waitingForPowerOn) {
[manager removeAllServices];
@@ -456,13 +456,7 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
explicitly added again."
*/
-#if QT_IOS_PLATFORM_SDK_EQUAL_OR_ABOVE(__IPHONE_10_0) || QT_OSX_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_13)
- if (peripheral.state == CBManagerStateUnauthorized ||
- peripheral.state == CBManagerStateUnsupported) {
-#else
- if (peripheral.state == CBPeripheralManagerStateUnauthorized ||
- peripheral.state == CBPeripheralManagerStateUnsupported) {
-#endif
+ if (peripheral.state == CBManagerStateUnauthorized || peripheral.state == CBManagerStateUnsupported) {
emit notifier->LEnotSupported();
state = PeripheralState::idle;
}
@@ -507,7 +501,7 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
}
if (nextServiceToAdd == services.size())
- [manager startAdvertising:[advertisementData count] ? advertisementData.data() : nil];
+ [manager startAdvertising:[advertisementData count] ? advertisementData.get() : nil];
else
[self addServicesToPeripheral];
}
@@ -753,7 +747,8 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
QT_BT_MAC_AUTORELEASEPOOL
- ObjCScopedPointer<NSMutableArray> included([[NSMutableArray alloc] init]);
+ ObjCScopedPointer<NSMutableArray> included([[NSMutableArray alloc] init],
+ DarwinBluetooth::RetainPolicy::noInitialRetain);
if (!included) {
qCWarning(QT_BT_DARWIN) << "addIncludedSerivces: failed "
"to allocate NSMutableArray";
@@ -784,7 +779,8 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
QT_BT_MAC_AUTORELEASEPOOL
- ObjCScopedPointer<NSMutableArray> newCBChars([[NSMutableArray alloc] init]);
+ ObjCScopedPointer<NSMutableArray> newCBChars([[NSMutableArray alloc] init],
+ DarwinBluetooth::RetainPolicy::noInitialRetain);
if (!newCBChars) {
qCWarning(QT_BT_DARWIN) << "addCharacteristicsAndDescritptors: "
"failed to allocate NSMutableArray "
@@ -838,7 +834,8 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
charData.properties = ch.properties();
charData.value = ch.value();
- const ObjCScopedPointer<NSMutableArray> newCBDescs([[NSMutableArray alloc] init]);
+ const ObjCScopedPointer<NSMutableArray> newCBDescs([[NSMutableArray alloc] init],
+ DarwinBluetooth::RetainPolicy::noInitialRetain);
if (!newCBDescs) {
qCWarning(QT_BT_DARWIN) << "addCharacteristicsAndDescritptors: "
"failed to allocate NSMutableArray "
@@ -863,13 +860,13 @@ bool qt_validate_value_range(const QLowEnergyCharacteristicData &data)
}
if ([newCBDescs count])
- cbChar.data().descriptors = newCBDescs.data(); // retains
+ cbChar.data().descriptors = newCBDescs.get();
qtService->characteristicList.insert(declHandle, charData);
}
if ([newCBChars count])
- cbService.characteristics = newCBChars.data();
+ cbService.characteristics = newCBChars.get();
}
- (CBATTError)validateWriteRequest:(CBATTRequest *)request
diff --git a/src/bluetooth/darwin/btsdpinquiry.mm b/src/bluetooth/darwin/btsdpinquiry.mm
index 336d7541..468d5445 100644
--- a/src/bluetooth/darwin/btsdpinquiry.mm
+++ b/src/bluetooth/darwin/btsdpinquiry.mm
@@ -211,7 +211,7 @@ using namespace DarwinBluetooth;
@implementation QT_MANGLE_NAMESPACE(DarwinBTSDPInquiry)
{
QT_PREPEND_NAMESPACE(DarwinBluetooth::SDPInquiryDelegate) *delegate;
- IOBluetoothDevice *device;
+ ObjCScopedPointer<IOBluetoothDevice> device;
bool isActive;
}
@@ -230,7 +230,6 @@ using namespace DarwinBluetooth;
- (void)dealloc
{
//[device closeConnection]; //??? - synchronous, "In the future this API will be changed to allow asynchronous operation."
- [device release];
[super dealloc];
}
@@ -253,7 +252,7 @@ using namespace DarwinBluetooth;
// We first try to allocate "filters":
ObjCScopedPointer<NSMutableArray> array;
if (qtFilters.size()) {
- array.reset([[NSMutableArray alloc] init]);
+ array.reset([[NSMutableArray alloc] init], RetainPolicy::noInitialRetain);
if (!array) {
qCCritical(QT_BT_DARWIN) << "failed to allocate an uuid filter";
return kIOReturnError;
@@ -272,15 +271,12 @@ using namespace DarwinBluetooth;
}
const BluetoothDeviceAddress iobtAddress(iobluetooth_address(address));
- ObjCScopedPointer<IOBluetoothDevice> newDevice([[IOBluetoothDevice deviceWithAddress:&iobtAddress] retain]);
- if (!newDevice) {
+ device.reset([IOBluetoothDevice deviceWithAddress:&iobtAddress], RetainPolicy::doInitialRetain);
+ if (!device) {
qCCritical(QT_BT_DARWIN) << "failed to create an IOBluetoothDevice object";
return kIOReturnError;
}
- ObjCScopedPointer<IOBluetoothDevice> oldDevice(device);
- device = newDevice.data();
-
IOReturn result = kIOReturnSuccess;
if (qtFilters.size())
result = [device performSDPQuery:self uuids:array];
@@ -289,10 +285,9 @@ using namespace DarwinBluetooth;
if (result != kIOReturnSuccess) {
qCCritical(QT_BT_DARWIN) << "failed to start an SDP query";
- device = oldDevice.take();
+ device.reset();
} else {
isActive = true;
- newDevice.take();
}
return result;
@@ -303,9 +298,7 @@ using namespace DarwinBluetooth;
// There is no API to stop it,
// but there is a 'stop' member-function in Qt and
// after it's called sdpQueryComplete must be somehow ignored.
-
- [device release];
- device = nil;
+ device.reset();
}
- (void)sdpQueryComplete:(IOBluetoothDevice *)aDevice status:(IOReturn)status
diff --git a/src/bluetooth/darwin/btutility_p.h b/src/bluetooth/darwin/btutility_p.h
index 85dc37ee..6854522f 100644
--- a/src/bluetooth/darwin/btutility_p.h
+++ b/src/bluetooth/darwin/btutility_p.h
@@ -51,8 +51,9 @@
// We mean it.
//
+#include "btraii_p.h"
+
#include <QtCore/qloggingcategory.h>
-#include <QtCore/qscopedpointer.h>
#include <QtCore/qglobal.h>
#include <QtCore/private/qcore_mac_p.h>
@@ -73,36 +74,40 @@ class QBluetoothUuid;
namespace DarwinBluetooth {
-struct NSObjectDeleter {
- static void cleanup(NSObject *obj)
- {
- [obj release];
- }
-};
-
template<class T>
-class ObjCScopedPointer : public QScopedPointer<NSObject, NSObjectDeleter>
+class ObjCScopedPointer
{
public:
- // TODO: remove default argument, add 'retain' parameter,
- // add a default ctor??? This will make the semantics more
- // transparent + will simplify the future transition to ARC
- // (if it will ever happen).
- explicit ObjCScopedPointer(T *ptr = nullptr) : QScopedPointer(ptr){}
- operator T*() const
+ ObjCScopedPointer() = default;
+ ObjCScopedPointer(T *ptr, RetainPolicy policy)
+ : m_ptr(ptr, policy)
{
- return data();
}
-
- T *data()const
+ void swap(ObjCScopedPointer &other)
{
- return static_cast<T *>(QScopedPointer::data());
+ m_ptr.swap(other.m_ptr);
}
-
- T *take()
+ void reset()
{
- return static_cast<T *>(QScopedPointer::take());
+ m_ptr.reset();
}
+ void reset(T *ptr, RetainPolicy policy)
+ {
+ m_ptr.reset(ptr, policy);
+ }
+ operator T*() const
+ {
+ return m_ptr.getAs<T>();
+ }
+ T *get() const
+ {
+ // operator T * above does not work when accessing
+ // properties using '.' syntax.
+ return m_ptr.getAs<T>();
+ }
+private:
+ // Copy and move disabled by m_ptr:
+ ScopedPointer m_ptr;
};
#define QT_BT_MAC_AUTORELEASEPOOL const QMacAutoReleasePool pool;
diff --git a/src/bluetooth/qbluetoothlocaldevice_macos.mm b/src/bluetooth/qbluetoothlocaldevice_macos.mm
index 805c882a..462453ac 100644
--- a/src/bluetooth/qbluetoothlocaldevice_macos.mm
+++ b/src/bluetooth/qbluetoothlocaldevice_macos.mm
@@ -119,7 +119,10 @@ QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice
QT_BT_MAC_AUTORELEASEPOOL;
- HostController defaultController([[IOBluetoothHostController defaultController] retain]);
+ using namespace DarwinBluetooth;
+
+ ObjCScopedPointer<IOBluetoothHostController> defaultController([IOBluetoothHostController defaultController],
+ RetainPolicy::doInitialRetain);
if (!defaultController) {
qCCritical(QT_BT_DARWIN) << "failed to init a host controller object";
return;
@@ -144,15 +147,15 @@ QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice
}
}
- hostController.reset(defaultController.take());
-
+ defaultController.swap(hostController);
// This one is optional, if it fails to initialize, we do not care at all.
- connectionMonitor.reset([[ObjCConnectionMonitor alloc] initWithMonitor:this]);
+ connectionMonitor.reset([[ObjCConnectionMonitor alloc] initWithMonitor:this],
+ DarwinBluetooth::RetainPolicy::noInitialRetain);
}
bool QBluetoothLocalDevicePrivate::isValid() const
{
- return hostController.data();
+ return hostController;
}
void QBluetoothLocalDevicePrivate::requestPairing(const QBluetoothAddress &address, Pairing pairing)
diff --git a/src/bluetooth/qbluetoothtransferreply_macos.mm b/src/bluetooth/qbluetoothtransferreply_macos.mm
index 986d5e15..d05396b9 100644
--- a/src/bluetooth/qbluetoothtransferreply_macos.mm
+++ b/src/bluetooth/qbluetoothtransferreply_macos.mm
@@ -136,13 +136,13 @@ QBluetoothTransferReplyOSXPrivate::~QBluetoothTransferReplyOSXPrivate()
// The OBEX session will be closed then. If
// somehow IOBluetooth/OBEX still has a reference to our
// session, it will not call any of delegate's callbacks.
- if (session.data())
+ if (session)
[session closeSession];
}
bool QBluetoothTransferReplyOSXPrivate::isActive() const
{
- return agent.data() || (session.data() && [session hasActiveRequest]);
+ return agent || (session && [session hasActiveRequest]);
}
bool QBluetoothTransferReplyOSXPrivate::startOPP(const QBluetoothAddress &device)
@@ -171,6 +171,8 @@ bool QBluetoothTransferReplyOSXPrivate::startOPP(const QBluetoothAddress &device
void QBluetoothTransferReplyOSXPrivate::sendConnect(const QBluetoothAddress &device, quint16 channelID)
{
+ using namespace DarwinBluetooth;
+
Q_ASSERT_X(!session, Q_FUNC_INFO, "session is already active");
error = QBluetoothTransferReply::NoError;
@@ -184,7 +186,8 @@ void QBluetoothTransferReplyOSXPrivate::sendConnect(const QBluetoothAddress &dev
}
OBEXSession newSession([[ObjCOBEXSession alloc] initWithDelegate:this
- remoteDevice:device channelID:channelID]);
+ remoteDevice:device channelID:channelID],
+ RetainPolicy::noInitialRetain);
if (!newSession) {
qCWarning(QT_BT_DARWIN) << "failed to allocate DarwinBTOBEXSession object";
@@ -197,7 +200,7 @@ void QBluetoothTransferReplyOSXPrivate::sendConnect(const QBluetoothAddress &dev
if ((status == kOBEXSuccess || status == kOBEXSessionAlreadyConnectedError)
&& error == QBluetoothTransferReply::NoError) {
- session.reset(newSession.take());
+ session.swap(newSession);
if ([session isConnected])
sendPut();// Connected, send a PUT request.
} else {
@@ -218,7 +221,7 @@ void QBluetoothTransferReplyOSXPrivate::sendConnect(const QBluetoothAddress &dev
void QBluetoothTransferReplyOSXPrivate::sendPut()
{
Q_ASSERT_X(inputStream, Q_FUNC_INFO, "invalid input stream (null)");
- Q_ASSERT_X(session.data(), Q_FUNC_INFO, "invalid OBEX session (nil)");
+ Q_ASSERT_X(session, Q_FUNC_INFO, "invalid OBEX session (nil)");
Q_ASSERT_X([session isConnected], Q_FUNC_INFO, "not connected");
Q_ASSERT_X(![session hasActiveRequest], Q_FUNC_INFO,
"session already has an active request");
@@ -268,7 +271,7 @@ void QBluetoothTransferReplyOSXPrivate::OBEXConnectError(OBEXError errorCode, OB
Q_UNUSED(errorCode)
Q_UNUSED(response)
- if (session.data()) {
+ if (session) {
setReplyError(QBluetoothTransferReply::SessionError,
QCoreApplication::translate(TRANSFER_REPLY, TR_CONNECT_FAILED));
} else {
@@ -283,7 +286,7 @@ void QBluetoothTransferReplyOSXPrivate::OBEXConnectError(OBEXError errorCode, OB
void QBluetoothTransferReplyOSXPrivate::OBEXConnectSuccess()
{
// Now that OBEX connect succeeded, we can send an OBEX put request.
- if (!session.data()) {
+ if (!session) {
// We're still in OBEXConnect(), it'll take care of next steps.
return;
}
@@ -394,7 +397,7 @@ bool QBluetoothTransferReplyOSX::abort()
// Reset a delegate.
[osx_d_ptr->session closeSession];
// Should never be called from an OBEX callback!
- osx_d_ptr->session.reset(nullptr);
+ osx_d_ptr->session.reset();
// Not setReplyError, we emit finished only!
osx_d_ptr->requestComplete = true;