summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTimur Pocheptsov <Timur.Pocheptsov@digia.com>2014-12-17 09:11:04 +0100
committerTimur Pocheptsov <Timur.Pocheptsov@digia.com>2014-12-18 09:16:25 +0100
commit6102f74e45ce4cd8792f323a06bdbab5f27fd106 (patch)
tree16cddfe3a500d6782018bce44999c01e26e3396b /src
parent1421e4c482430f9cf76ed7ec7bd5e6857ef9407f (diff)
QBluetoothLocalDevice - cleanup (OS X)
Replace hand-written 'function signatures' with Q_FUNC_INFO. Change-Id: I0c05d9fa76d120b5626420cadafb1a9fe1227b95 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/osx/osxbtdevicepair.mm28
-rw-r--r--src/bluetooth/osx/osxbtdevicepair_p.h10
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_osx.mm96
3 files changed, 53 insertions, 81 deletions
diff --git a/src/bluetooth/osx/osxbtdevicepair.mm b/src/bluetooth/osx/osxbtdevicepair.mm
index c9d6de32..ad00bb23 100644
--- a/src/bluetooth/osx/osxbtdevicepair.mm
+++ b/src/bluetooth/osx/osxbtdevicepair.mm
@@ -43,11 +43,9 @@
#include "osxbtutility_p.h"
#include <QtCore/qloggingcategory.h>
+#include <QtCore/qglobal.h>
#include <QtCore/qdebug.h>
-// Import to avoid problems with multiple inclusion (objc headers are not guarded against).
-#import <IOBluetooth/objc/IOBluetoothDevice.h>
-
QT_BEGIN_NAMESPACE
namespace OSXBluetooth {
@@ -82,10 +80,8 @@ using namespace QT_NAMESPACE;
delegate:(OSXBluetooth::PairingDelegate *)object
{
if (self = [super init]) {
- Q_ASSERT_X(!address.isNull(), "-initWithTarget:delegate",
- "invalid target address");
- Q_ASSERT_X(object, "-initWithTarget:delegate:",
- "invalid delegate (null)");
+ Q_ASSERT_X(!address.isNull(), Q_FUNC_INFO, "invalid target address");
+ Q_ASSERT_X(object, Q_FUNC_INFO, "invalid delegate (null)");
m_targetAddress = address;
m_object = object;
@@ -114,7 +110,7 @@ using namespace QT_NAMESPACE;
if (m_active)
return kIOReturnBusy;
- Q_ASSERT_X(!m_targetAddress.isNull(), "-start", "invalid target address");
+ Q_ASSERT_X(!m_targetAddress.isNull(), Q_FUNC_INFO, "invalid target address");
QT_BT_MAC_AUTORELEASEPOOL;
@@ -122,15 +118,15 @@ using namespace QT_NAMESPACE;
// Device is autoreleased.
IOBluetoothDevice *const device = [IOBluetoothDevice deviceWithAddress:&iobtAddress];
if (!device) {
- qCCritical(QT_BT_OSX) << "-start:, failed to create a device "
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to create a device "
"to pair with";
- return kIOReturnInternalError; // TODO: Find something more appropriate.
+ return kIOReturnError;
}
m_pairing = [[IOBluetoothDevicePair pairWithDevice:device] retain];
if (!m_pairing) {
- qCCritical(QT_BT_OSX) << "-start, failed to create pair";
- return kIOReturnInternalError;
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to create pair";
+ return kIOReturnError;
}
[m_pairing setDelegate:self];
@@ -169,7 +165,7 @@ using namespace QT_NAMESPACE;
- (IOBluetoothDevice *)targetDevice
{
- return [m_pairing device];//It's retained/autoreleased by pair (?).
+ return [m_pairing device];//It's retained/autoreleased by pair.
}
// IOBluetoothDevicePairDelegate:
@@ -195,8 +191,7 @@ using namespace QT_NAMESPACE;
if (sender != m_pairing) // Can never happen.
return;
- Q_ASSERT_X(m_object, "-devicePairingUserConfirmationRequest:numericValue:",
- "invalid delegate (null)");
+ Q_ASSERT_X(m_object, Q_FUNC_INFO, "invalid delegate (null)");
m_object->requestUserConfirmation(self, numericValue);
}
@@ -210,8 +205,7 @@ using namespace QT_NAMESPACE;
- (void)devicePairingFinished:(id)sender error:(IOReturn)error
{
- Q_ASSERT_X(m_object, "-devicePairingFinished:",
- "invalid delegate (null)");
+ Q_ASSERT_X(m_object, Q_FUNC_INFO, "invalid delegate (null)");
if (sender != m_pairing) // Can never happen though.
return;
diff --git a/src/bluetooth/osx/osxbtdevicepair_p.h b/src/bluetooth/osx/osxbtdevicepair_p.h
index 843c58f4..334f0896 100644
--- a/src/bluetooth/osx/osxbtdevicepair_p.h
+++ b/src/bluetooth/osx/osxbtdevicepair_p.h
@@ -48,10 +48,8 @@
#include <QtCore/qglobal.h>
#include <Foundation/Foundation.h>
-
-// This header is not guarded agains multiple includes ...
-// We have to "import".
-#import <IOBluetooth/objc/IOBluetoothDevicePair.h>
+// Only after Foundation.h:
+#include "corebluetoothwrapper_p.h"
@class QT_MANGLE_NAMESPACE(OSXBTPairing);
@class IOBluetoothDevice;
@@ -68,7 +66,6 @@ public:
virtual ~PairingDelegate();
- // virtual void pairingStarted(ObjCPairingRequest *pair) = 0;
virtual void connecting(ObjCPairingRequest *pair) = 0;
virtual void requestPIN(ObjCPairingRequest *pair) = 0;
virtual void requestUserConfirmation(ObjCPairingRequest *pair,
@@ -87,12 +84,11 @@ QT_END_NAMESPACE
@interface QT_MANGLE_NAMESPACE(OSXBTPairing) : NSObject<IOBluetoothDevicePairDelegate>
{
- // TODO: check how it works - C++ object as a member
QT_PREPEND_NAMESPACE(QBluetoothAddress) m_targetAddress;
bool m_active;
IOBluetoothDevicePair *m_pairing; // The real pairing request
- QT_PREPEND_NAMESPACE(OSXBluetooth::PairingDelegate) *m_object;
+ QT_PREPEND_NAMESPACE(OSXBluetooth)::PairingDelegate *m_object;
}
- (id)initWithTarget:(const QBluetoothAddress &)address
diff --git a/src/bluetooth/qbluetoothlocaldevice_osx.mm b/src/bluetooth/qbluetoothlocaldevice_osx.mm
index 38f15b8c..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,13 +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) {
- qCCritical(QT_BT_OSX) << "QBluetoothLocalDevicePrivate(), failed to "
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to "
"init a host controller object";
return;
}
@@ -129,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;
}
}
@@ -161,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;
@@ -186,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;
@@ -198,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;
}
@@ -208,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;
@@ -267,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);
@@ -286,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);
@@ -297,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);
@@ -312,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));
@@ -326,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,
@@ -340,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);
@@ -376,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();
@@ -391,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();
@@ -403,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
@@ -461,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;
}
@@ -483,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);
@@ -496,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;