summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/qbluetoothlocaldevice_osx.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/bluetooth/qbluetoothlocaldevice_osx.mm')
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_osx.mm102
1 files changed, 40 insertions, 62 deletions
diff --git a/src/bluetooth/qbluetoothlocaldevice_osx.mm b/src/bluetooth/qbluetoothlocaldevice_osx.mm
index 7e5cb12a..32562e94 100644
--- a/src/bluetooth/qbluetoothlocaldevice_osx.mm
+++ b/src/bluetooth/qbluetoothlocaldevice_osx.mm
@@ -47,18 +47,16 @@
#include <QtCore/qloggingcategory.h>
#include <QtCore/qstring.h>
+#include <QtCore/qglobal.h>
#include <QtCore/qdebug.h>
#include <QtCore/qmap.h>
-#include <IOBluetooth/IOBluetoothUtilities.h>
-// We have to import, not include. Obj-C headers are not protected
-// against a multiple inclusion.
-#import <IOBluetooth/objc/IOBluetoothHostController.h>
-#import <IOBluetooth/objc/IOBluetoothDevice.h>
-#include <algorithm>
+#include <Foundation/Foundation.h>
+// Only after Foundation.h:
+#include "osx/corebluetoothwrapper_p.h"
-// TODO: check how all these things work with threads.
+#include <algorithm>
QT_BEGIN_NAMESPACE
@@ -115,17 +113,13 @@ QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice
const QBluetoothAddress &address) :
q_ptr(q)
{
- Q_ASSERT_X(q, "QBluetoothLocalDevicePrivate", "invalid q_ptr (null)");
+ Q_ASSERT_X(q, Q_FUNC_INFO, "invalid q_ptr (null)");
QT_BT_MAC_AUTORELEASEPOOL;
HostController defaultController([[IOBluetoothHostController defaultController] retain]);
- if (!defaultController || [defaultController powerState] != kBluetoothHCIPowerStateON) {
- // IOBluetooth can return non-null host controller without working adapter.
- // Unfortunately, a local device in such a state is totally useless:
- // you can not access any information like address/name or change the device
- // state to powered on. So it's not valid.
- qCCritical(QT_BT_OSX) << "QBluetoothLocalDevicePrivate(), failed to "
+ if (!defaultController) {
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to "
"init a host controller object";
return;
}
@@ -133,21 +127,21 @@ QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice
if (!address.isNull()) {
NSString *const hciAddress = [defaultController addressAsString];
if (!hciAddress) {
- qCCritical(QT_BT_OSX) << "QBluetoothLocalDevicePrivate(), "
- "failed to obtain an address";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to "
+ "obtain an address";
return;
}
BluetoothDeviceAddress iobtAddress = {};
if (IOBluetoothNSStringToDeviceAddress(hciAddress, &iobtAddress) != kIOReturnSuccess) {
- qCCritical(QT_BT_OSX) << "QBluetoothLocalDevicePrivate(), "
- "invalid local device's address";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "invalid "
+ "local device's address";
return;
}
if (address != OSXBluetooth::qt_address(&iobtAddress)) {
- qCCritical(QT_BT_OSX) << "QBluetoothLocalDevicePrivate(), "
- "invalid local device's address";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "invalid "
+ "local device's address";
return;
}
}
@@ -165,8 +159,8 @@ bool QBluetoothLocalDevicePrivate::isValid() const
void QBluetoothLocalDevicePrivate::requestPairing(const QBluetoothAddress &address, Pairing pairing)
{
- Q_ASSERT_X(isValid(), "requestPairing()", "invalid local device");
- Q_ASSERT_X(!address.isNull(), "requestPairing()", "invalid device address");
+ Q_ASSERT_X(isValid(), Q_FUNC_INFO, "invalid local device");
+ Q_ASSERT_X(!address.isNull(), Q_FUNC_INFO, "invalid device address");
using OSXBluetooth::device_with_address;
using OSXBluetooth::ObjCStrongReference;
@@ -190,8 +184,8 @@ void QBluetoothLocalDevicePrivate::requestPairing(const QBluetoothAddress &addre
if ([device isPaired]) {
emitPairingFinished(address, pairing, true);
} else if ([pos.value() start] != kIOReturnSuccess) {
- qCCritical(QT_BT_OSX) << "QBluetoothLocalDevicePrivate::requestPairing(), "
- "failed to start a new pairing request";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to "
+ "start a new pairing request";
emitError(QBluetoothLocalDevice::PairingError, true);
}
return;
@@ -202,8 +196,8 @@ void QBluetoothLocalDevicePrivate::requestPairing(const QBluetoothAddress &addre
// it'll just finish with success (skipping any intermediate steps).
PairingRequest newRequest([[ObjCPairingRequest alloc] initWithTarget:address delegate:this], false);
if (!newRequest) {
- qCCritical(QT_BT_OSX) << "QBluetoothLocalDevicePrivate::requestPairing(), "
- "failed to allocate a new pairing request";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to "
+ "allocate a new pairing request";
emitError(QBluetoothLocalDevice::PairingError, true);
return;
}
@@ -212,16 +206,16 @@ void QBluetoothLocalDevicePrivate::requestPairing(const QBluetoothAddress &addre
const IOReturn result = [newRequest start];
if (result != kIOReturnSuccess) {
pairingRequests.erase(pos);
- qCCritical(QT_BT_OSX) << "QBluetoothLocalDevicePrivate::requestPairing(), "
- "failed to start a new pairing request";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to "
+ "start a new pairing request";
emitError(QBluetoothLocalDevice::PairingError, true);
}
}
QBluetoothLocalDevice::Pairing QBluetoothLocalDevicePrivate::pairingStatus(const QBluetoothAddress &address)const
{
- Q_ASSERT_X(isValid(), "pairingStatus", "invalid local device");
- Q_ASSERT_X(!address.isNull(), "pairingStatus", "invalid address");
+ Q_ASSERT_X(isValid(), Q_FUNC_INFO, "invalid local device");
+ Q_ASSERT_X(!address.isNull(), Q_FUNC_INFO, "invalid address");
using OSXBluetooth::device_with_address;
using OSXBluetooth::ObjCStrongReference;
@@ -271,18 +265,16 @@ void QBluetoothLocalDevicePrivate::error(ObjCPairingRequest *pair, IOReturn erro
{
Q_UNUSED(pair)
Q_UNUSED(errorCode)
- // TODO: map from IOReturn to QBluetoothLocalDevice::Error.
- // TODO: emit or invokeMethod???
+
emitError(QBluetoothLocalDevice::PairingError, false);
}
void QBluetoothLocalDevicePrivate::pairingFinished(ObjCPairingRequest *pair)
{
- Q_ASSERT_X(pair, "QBluetoothLocalDevicePrivate::pairingFinished()",
- "invalid pairing request (nil)");
+ Q_ASSERT_X(pair, Q_FUNC_INFO, "invalid pairing request (nil)");
const QBluetoothAddress &deviceAddress = [pair targetAddress];
- Q_ASSERT_X(!deviceAddress.isNull(), "pairingFinished()",
+ Q_ASSERT_X(!deviceAddress.isNull(), Q_FUNC_INFO,
"invalid target address");
emitPairingFinished(deviceAddress, QBluetoothLocalDevice::Paired, false);
@@ -290,8 +282,6 @@ void QBluetoothLocalDevicePrivate::pairingFinished(ObjCPairingRequest *pair)
void QBluetoothLocalDevicePrivate::deviceConnected(const QBluetoothAddress &deviceAddress)
{
- Q_ASSERT_X(q_ptr, "deviceConnected()", "invalid q_ptr (null)");
-
if (!discoveredDevices.contains(deviceAddress))
discoveredDevices.append(deviceAddress);
@@ -301,8 +291,6 @@ void QBluetoothLocalDevicePrivate::deviceConnected(const QBluetoothAddress &devi
void QBluetoothLocalDevicePrivate::deviceDisconnected(const QBluetoothAddress &deviceAddress)
{
- Q_ASSERT_X(q_ptr, "deviceDisconnected()", "invalid q_ptr (null)");
-
QList<QBluetoothAddress>::iterator devicePos =std::find(discoveredDevices.begin(),
discoveredDevices.end(),
deviceAddress);
@@ -316,9 +304,6 @@ void QBluetoothLocalDevicePrivate::deviceDisconnected(const QBluetoothAddress &d
void QBluetoothLocalDevicePrivate::emitError(QBluetoothLocalDevice::Error error, bool queued)
{
- Q_ASSERT_X(q_ptr, "QBluetoothLocalDevicePrivate::error()",
- "invalid q_ptr (null)");
-
if (queued) {
QMetaObject::invokeMethod(q_ptr, "error", Qt::QueuedConnection,
Q_ARG(QBluetoothLocalDevice::Error, error));
@@ -330,8 +315,8 @@ void QBluetoothLocalDevicePrivate::emitError(QBluetoothLocalDevice::Error error,
void QBluetoothLocalDevicePrivate::emitPairingFinished(const QBluetoothAddress &deviceAddress,
Pairing pairing, bool queued)
{
- Q_ASSERT_X(!deviceAddress.isNull(), "pairingFinished()", "invalid target device address");
- Q_ASSERT_X(q_ptr, "pairingFinished()", "invalid q_ptr (null)");
+ Q_ASSERT_X(!deviceAddress.isNull(), Q_FUNC_INFO, "invalid target device address");
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
if (queued) {
QMetaObject::invokeMethod(q_ptr, "pairingFinished", Qt::QueuedConnection,
@@ -344,7 +329,7 @@ void QBluetoothLocalDevicePrivate::emitPairingFinished(const QBluetoothAddress &
void QBluetoothLocalDevicePrivate::unpair(const QBluetoothAddress &deviceAddress)
{
- Q_ASSERT_X(!deviceAddress.isNull(), "unpair()",
+ Q_ASSERT_X(!deviceAddress.isNull(), Q_FUNC_INFO,
"invalid target address");
emitPairingFinished(deviceAddress, QBluetoothLocalDevice::Unpaired, true);
@@ -380,8 +365,7 @@ QString QBluetoothLocalDevice::name() const
if (isValid()) {
if (NSString *const nsn = [d_ptr->hostController nameAsString])
return QString::fromNSString(nsn);
- qCCritical(QT_BT_OSX) << "QBluetoothLocalDevice::name(), "
- "failed to obtain a name";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to obtain a name";
}
return QString();
@@ -395,11 +379,9 @@ QBluetoothAddress QBluetoothLocalDevice::address() const
if (NSString *const nsa = [d_ptr->hostController addressAsString])
return QBluetoothAddress(OSXBluetooth::qt_address(nsa));
- qCCritical(QT_BT_OSX) << "QBluetoothLocalDevice::address(), "
- "failed to obtain an address";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to obtain an address";
} else {
- qCWarning(QT_BT_OSX) << "QBluetoothLocalDevice::address(), "
- "invalid local device";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid local device";
}
return QBluetoothAddress();
@@ -407,20 +389,16 @@ QBluetoothAddress QBluetoothLocalDevice::address() const
void QBluetoothLocalDevice::powerOn()
{
- if (!isValid()) {
- qCWarning(QT_BT_OSX) << "QBluetoothLocalDevice::powerOn() "
- "invalid local device";
- }
+ if (!isValid())
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid local device";
}
void QBluetoothLocalDevice::setHostMode(QBluetoothLocalDevice::HostMode mode)
{
Q_UNUSED(mode)
- if (!isValid()) {
- qCWarning(QT_BT_OSX) << "QBluetoothLovalDevice::setHostMode() "
- "invalid local device";
- }
+ if (!isValid())
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid local device";
}
QBluetoothLocalDevice::HostMode QBluetoothLocalDevice::hostMode() const
@@ -465,7 +443,7 @@ QList<QBluetoothHostInfo> QBluetoothLocalDevice::allDevices()
QBluetoothLocalDevice defaultAdapter;
if (!defaultAdapter.isValid() || defaultAdapter.address().isNull()) {
- qCCritical(QT_BT_OSX) << "QBluetoothLocalDevice::allDevices(), no valid device found";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO <<"no valid device found";
return localDevices;
}
@@ -487,7 +465,7 @@ void QBluetoothLocalDevice::pairingConfirmation(bool confirmation)
void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pairing pairing)
{
if (!isValid())
- qCWarning(QT_BT_OSX) << "QBluetoothLocalDevice::requestPairing(), invalid local device";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid local device";
if (!isValid() || address.isNull()) {
d_ptr->emitError(PairingError, true);
@@ -500,7 +478,7 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai
QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluetoothAddress &address) const
{
if (!isValid())
- qCWarning(QT_BT_OSX) << "QBluetoothLocalDevice::pairingStatus(), invalid local device";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid local device";
if (!isValid() || address.isNull())
return Unpaired;