summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimur Pocheptsov <Timur.Pocheptsov@digia.com>2014-12-17 09:46:39 +0100
committerTimur Pocheptsov <Timur.Pocheptsov@digia.com>2014-12-18 10:55:09 +0100
commita007a6c6b40f14b4ad41130abbb445e45e919759 (patch)
tree81c6c77dc524a08c8fb2ba743d437953b864b2b1
parent6102f74e45ce4cd8792f323a06bdbab5f27fd106 (diff)
QBluetoothDeviceDiscoveryAgent - cleanup (OS X/iOS)
Replace handwritten 'signatures' with Q_FUNC_INFO, remove spurious debug messages. Get rid of 'transient delegate' trick. Change-Id: I2c490271baba7247af11df128964b61d0255ef95 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
-rw-r--r--src/bluetooth/osx/osxbt.pri4
-rw-r--r--src/bluetooth/osx/osxbtcentralmanagerdelegate.mm68
-rw-r--r--src/bluetooth/osx/osxbtcentralmanagerdelegate_p.h68
-rw-r--r--src/bluetooth/osx/osxbtdeviceinquiry.mm45
-rw-r--r--src/bluetooth/osx/osxbtledeviceinquiry.mm65
-rw-r--r--src/bluetooth/osx/osxbtledeviceinquiry_p.h7
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm131
7 files changed, 80 insertions, 308 deletions
diff --git a/src/bluetooth/osx/osxbt.pri b/src/bluetooth/osx/osxbt.pri
index 96ad3905..5f1dddec 100644
--- a/src/bluetooth/osx/osxbt.pri
+++ b/src/bluetooth/osx/osxbt.pri
@@ -12,7 +12,6 @@ CONFIG(osx) {
osx/osxbtobexsession_p.h \
osx/osxbtledeviceinquiry_p.h \
osx/corebluetoothwrapper_p.h \
- osx/osxbtcentralmanagerdelegate_p.h \
osx/osxbtcentralmanager_p.h
OBJECTIVE_SOURCES += osx/osxbtutility.mm \
@@ -27,17 +26,14 @@ CONFIG(osx) {
osx/osxbtsocketlistener.mm \
osx/osxbtobexsession.mm \
osx/osxbtledeviceinquiry.mm \
- osx/osxbtcentralmanagerdelegate.mm \
osx/osxbtcentralmanager.mm
} else {
PRIVATE_HEADERS += osx/osxbtutility_p.h \
osx/osxbtledeviceinquiry_p.h \
osx/corebluetoothwrapper_p.h \
- osx/osxbtcentralmanagerdelegate_p.h \
osx/osxbtcentralmanager_p.h
OBJECTIVE_SOURCES += osx/osxbtutility.mm \
osx/osxbtledeviceinquiry.mm \
- osx/osxbtcentralmanagerdelegate.mm \
osx/osxbtcentralmanager.mm
}
diff --git a/src/bluetooth/osx/osxbtcentralmanagerdelegate.mm b/src/bluetooth/osx/osxbtcentralmanagerdelegate.mm
deleted file mode 100644
index c0735d53..00000000
--- a/src/bluetooth/osx/osxbtcentralmanagerdelegate.mm
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtBluetooth module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "osxbtcentralmanagerdelegate_p.h"
-
-@implementation QT_MANGLE_NAMESPACE(OSXBTCentralManagerTransientDelegate)
-
-- (id)initWithManager:(CBCentralManager *)aManager
-{
- if (self = [super init])
- manager = aManager;
-
- return self;
-}
-
-- (void)centralManagerDidUpdateState:(CBCentralManager *)central
-{
- Q_UNUSED(central)
-
- [self performSelectorOnMainThread:@selector(cleanup) withObject:nil waitUntilDone:NO];
-}
-
-- (void)cleanup
-{
- [manager setDelegate:nil];
- [manager release];
- [self release];
-}
-
-@end
diff --git a/src/bluetooth/osx/osxbtcentralmanagerdelegate_p.h b/src/bluetooth/osx/osxbtcentralmanagerdelegate_p.h
deleted file mode 100644
index 196e14d0..00000000
--- a/src/bluetooth/osx/osxbtcentralmanagerdelegate_p.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtBluetooth module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qglobal.h>
-
-// Foundation _MUST_ be included before 'wrapper' -
-// SDK 10.9 is broken and requires this trick.
-#include <Foundation/Foundation.h>
-
-#include "corebluetoothwrapper_p.h"
-
-// CBCentralManager is quite special: before -centralManagerDidUpdateState: call
-// (which is a callback) - we can not delete it.
-// We usually release a manager in the -dealloc method. If the state was not updated yet,
-// we create a temporary delegate (which also is becoming the owner of this manger),
-// and later in the delegate's -centralManagerDidUpdateState: we are trying to finally release
-// a manager. Otherwise, this thing dies even with ARC.
-
-// TODO: can not reproduce this crash anymore ... probably, this class will be removed soon.
-
-@interface QT_MANGLE_NAMESPACE(OSXBTCentralManagerTransientDelegate) : NSObject<CBCentralManagerDelegate>
-{
- CBCentralManager *manager;
-}
-
-- (id)initWithManager:(CBCentralManager *)aManager;
-- (void)centralManagerDidUpdateState:(CBCentralManager *)central;
-- (void)cleanup;
-
-@end
diff --git a/src/bluetooth/osx/osxbtdeviceinquiry.mm b/src/bluetooth/osx/osxbtdeviceinquiry.mm
index c07a0671..12902e1a 100644
--- a/src/bluetooth/osx/osxbtdeviceinquiry.mm
+++ b/src/bluetooth/osx/osxbtdeviceinquiry.mm
@@ -43,6 +43,7 @@
#include "osxbtutility_p.h"
#include <QtCore/qloggingcategory.h>
+#include <QtCore/qglobal.h>
#include <QtCore/qdebug.h>
@@ -71,17 +72,16 @@ using namespace QT_NAMESPACE;
- (id)initWithDelegate:(OSXBluetooth::DeviceInquiryDelegate *)delegate
{
if (self = [super init]) {
- Q_ASSERT_X(delegate, "-initWithDelegate:", "invalid device inquiry delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid device inquiry delegate (null)");
m_inquiry = [[IOBluetoothDeviceInquiry inquiryWithDelegate:self] retain];
if (m_inquiry) {
- // TODO: something more reasonable required!
[m_inquiry setInquiryLength:15];
[m_inquiry setUpdateNewDeviceNames:NO];//Useless, disable!
m_delegate = delegate;
} else {
- qCCritical(QT_BT_OSX) << "-initWithDelegate:, failed to create "
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to create "
"a device inquiry";
}
@@ -109,27 +109,22 @@ using namespace QT_NAMESPACE;
- (IOReturn)start
{
- if (!m_inquiry) {
- qCWarning(QT_BT_OSX) << "-start, m_inquiry is nil ...";
+ if (!m_inquiry)
return kIOReturnNoPower;
- }
- if (m_active) {
- qCWarning(QT_BT_OSX) << "-start, already active ...";
+ if (m_active)
return kIOReturnBusy;
- }
m_active = true;
- [m_inquiry clearFoundDevices];// TODO: implement update?
+ [m_inquiry clearFoundDevices];
const IOReturn result = [m_inquiry start];
if (result != kIOReturnSuccess) {
- // QtBluetooth will probably convert an error in UnknownError,
- // not really interesting.
- qCWarning(QT_BT_OSX) << "-start, failed with "
+ // QtBluetooth will probably convert an error into UnknownError,
+ // loosing the actual information.
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO <<"failed with "
"IOKit error code: " << result;
m_active = false;
- } else
- qCDebug(QT_BT_OSX) << "-start, device inquiry started";
+ }
return result;
}
@@ -137,9 +132,7 @@ using namespace QT_NAMESPACE;
- (IOReturn)stop
{
if (m_active) {
- Q_ASSERT_X(m_inquiry, "-stop", "active but nil inquiry");
-
- qCDebug(QT_BT_OSX) << "-stop, trying to stop device inquiry";
+ Q_ASSERT_X(m_inquiry, Q_FUNC_INFO, "active but nil inquiry");
m_active = false;
const IOReturn res = [m_inquiry stop];
@@ -162,18 +155,14 @@ using namespace QT_NAMESPACE;
m_active = false;
- Q_ASSERT_X(m_delegate, "-deviceInquiryComplete:error:aborted",
- "invalid device inquiry delegate (null)");
+ Q_ASSERT_X(m_delegate, Q_FUNC_INFO, "invalid device inquiry delegate (null)");
if (error != kIOReturnSuccess) {
- // QtBluetooth has not too many errors, 'UnknownError' is not really
- // useful, report error code here:
- qCWarning(QT_BT_OSX) << "-deviceInquiryComplete:error:aborted:, "
- "IOKit error code: " << error;
+ // QtBluetooth has not too many error codes, 'UnknownError' is not really
+ // useful, report the actual error code here:
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "IOKit error code: " << error;
m_delegate->error(sender, error);
} else {
- qCDebug(QT_BT_OSX) << "-deviceInquiryComplete:error:aborted:, "
- "device inquiry complete";
m_delegate->inquiryFinished(sender);
}
}
@@ -184,9 +173,7 @@ using namespace QT_NAMESPACE;
if (sender != m_inquiry) // Can never happen in the current version.
return;
- Q_ASSERT_X(m_delegate, "-deviceInquiryDeviceFound:device:",
- "invalid device inquiry delegate (null)");
-
+ Q_ASSERT_X(m_delegate, Q_FUNC_INFO, "invalid device inquiry delegate (null)");
m_delegate->deviceFound(sender, device);
}
diff --git a/src/bluetooth/osx/osxbtledeviceinquiry.mm b/src/bluetooth/osx/osxbtledeviceinquiry.mm
index 2f5ec0bb..dd5a5c73 100644
--- a/src/bluetooth/osx/osxbtledeviceinquiry.mm
+++ b/src/bluetooth/osx/osxbtledeviceinquiry.mm
@@ -39,7 +39,6 @@
**
****************************************************************************/
-#include "osxbtcentralmanagerdelegate_p.h"
#include "osxbtledeviceinquiry_p.h"
#include "qbluetoothdeviceinfo.h"
#include "qbluetoothuuid.h"
@@ -48,8 +47,6 @@
#include <QtCore/qloggingcategory.h>
#include <QtCore/qdebug.h>
-// Foundation header is already included by this point
-// (a workaround for a broken 10.9 SDK).
#include "corebluetoothwrapper_p.h"
QT_BEGIN_NAMESPACE
@@ -130,14 +127,14 @@ using namespace QT_NAMESPACE;
+ (NSTimeInterval)inquiryLength
{
- // 10 seconds at the moment. There is no default 'time-out',
- // CBCentralManager startScan does not stop if not asked.
+ // There is no default timeout,
+ // scan does not stop if not asked.
return 10;
}
- (id)initWithDelegate:(OSXBluetooth::LEDeviceInquiryDelegate *)aDelegate
{
- Q_ASSERT_X(aDelegate, "-initWithWithDelegate:", "invalid delegate (null)");
+ Q_ASSERT_X(aDelegate, Q_FUNC_INFO, "invalid delegate (null)");
if (self = [super init]) {
delegate = aDelegate;
@@ -153,24 +150,13 @@ using namespace QT_NAMESPACE;
- (void)dealloc
{
- typedef QT_MANGLE_NAMESPACE(OSXBTCentralManagerTransientDelegate) TransientDelegate;
-
[NSObject cancelPreviousPerformRequestsWithTarget:self];
if (manager) {
- // -start was called.
- if (pendingStart) {
- // State was not updated yet, too early to release.
- TransientDelegate *const transient = [[TransientDelegate alloc] initWithManager:manager];
- // On ARC the lifetime of a transient delegate will become a problem, since delegate itself
- // is a weak reference in a manager.
- [manager setDelegate:transient];
- } else {
- [manager setDelegate:nil];
- if (isActive)
- [manager stopScan];
- [manager release];
- }
+ [manager setDelegate:nil];
+ if (isActive)
+ [manager stopScan];
+ [manager release];
}
[peripherals release];
@@ -180,11 +166,11 @@ using namespace QT_NAMESPACE;
- (void)stopScan
{
// Scan's timeout.
- Q_ASSERT_X(delegate, "-stopScan", "invalid delegate (null)");
- Q_ASSERT_X(manager, "-stopScan", "invalid central (nil)");
- Q_ASSERT_X(!pendingStart, "-stopScan", "invalid state");
- Q_ASSERT_X(!cancelled, "-stopScan", "invalid state");
- Q_ASSERT_X(isActive, "-stopScan", "invalid state");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
+ Q_ASSERT_X(manager, Q_FUNC_INFO, "invalid central (nil)");
+ Q_ASSERT_X(!pendingStart, Q_FUNC_INFO, "invalid state");
+ Q_ASSERT_X(!cancelled, Q_FUNC_INFO, "invalid state");
+ Q_ASSERT_X(isActive, Q_FUNC_INFO, "invalid state");
[manager setDelegate:nil];
[manager stopScan];
@@ -195,11 +181,11 @@ using namespace QT_NAMESPACE;
- (bool)start
{
- Q_ASSERT_X(![self isActive], "-start", "LE device scan is already active");
- Q_ASSERT_X(delegate, "-start", "invalid delegate (null)");
+ Q_ASSERT_X(![self isActive], Q_FUNC_INFO, "LE device scan is already active");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
if (!peripherals) {
- qCCritical(QT_BT_OSX) << "-start, internal error (allocation problem)";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "internal error";
return false;
}
@@ -216,7 +202,7 @@ using namespace QT_NAMESPACE;
manager = [CBCentralManager alloc];
manager = [manager initWithDelegate:self queue:nil];
if (!manager) {
- qCCritical(QT_BT_OSX) << "-start, failed to create a central manager";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to create a central manager";
return false;
}
@@ -225,10 +211,10 @@ using namespace QT_NAMESPACE;
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
- Q_ASSERT_X(delegate, "-centralManagerDidUpdateState:", "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
if (cancelled) {
- Q_ASSERT_X(!isActive, "-centralManagerDidUpdateState:", "isActive is true");
+ Q_ASSERT_X(!isActive, Q_FUNC_INFO, "isActive is true");
pendingStart = false;
delegate->LEdeviceInquiryFinished();
return;
@@ -309,18 +295,14 @@ using namespace QT_NAMESPACE;
using namespace OSXBluetooth;
- Q_ASSERT_X(delegate, "-centralManager:didDiscoverPeripheral:advertisementData:RSSI:",
- "invalid delegate (null)");
- Q_ASSERT_X(isActive, "-centralManager:didDiscoverPeripheral:advertisementData:RSSI:",
- "called while there is no active scan");
- Q_ASSERT_X(!pendingStart, "-centralManager:didDiscoverPeripheral:advertisementData:RSSI:",
- "both pendingStart and isActive are true");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
+ Q_ASSERT_X(isActive,Q_FUNC_INFO, "called while there is no active scan");
+ Q_ASSERT_X(!pendingStart, Q_FUNC_INFO, "both pendingStart and isActive are true");
#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_6_0)
if (!peripheral.identifier) {
- qCWarning(QT_BT_OSX) << "-centramManager:didDiscoverPeripheral:advertisementData:RSSI:, "
- "peripheral without NSUUID";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "peripheral without NSUUID";
return;
}
@@ -331,8 +313,7 @@ using namespace QT_NAMESPACE;
}
#else
if (!peripheral.UUID) {
- qCWarning(QT_BT_OSX) << "-centramManager:didDiscoverPeripheral:advertisementData:RSSI:, "
- "peripheral without UUID";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "peripheral without UUID";
return;
}
diff --git a/src/bluetooth/osx/osxbtledeviceinquiry_p.h b/src/bluetooth/osx/osxbtledeviceinquiry_p.h
index 20004d30..c8b6133e 100644
--- a/src/bluetooth/osx/osxbtledeviceinquiry_p.h
+++ b/src/bluetooth/osx/osxbtledeviceinquiry_p.h
@@ -47,9 +47,6 @@
#include <QtCore/qglobal.h>
#include <QtCore/qlist.h>
-// The Foundation header must be included before
-// corebluetoothwrapper_p.h - a workaround for a broken
-// 10.9 SDK.
#include <Foundation/Foundation.h>
@class QT_MANGLE_NAMESPACE(OSXBTLEDeviceInquiry);
@@ -88,7 +85,7 @@ QT_END_NAMESPACE
@interface QT_MANGLE_NAMESPACE(OSXBTLEDeviceInquiry) : NSObject
{// Protocols are adopted in the mm file.
- QT_PREPEND_NAMESPACE(OSXBluetooth::LEDeviceInquiryDelegate) *delegate;
+ QT_PREPEND_NAMESPACE(OSXBluetooth)::LEDeviceInquiryDelegate *delegate;
// TODO: scoped pointers/shared pointers?
NSMutableDictionary *peripherals; // Found devices.
@@ -101,7 +98,7 @@ QT_END_NAMESPACE
bool isActive;
}
-- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth::LEDeviceInquiryDelegate) *)aDelegate;
+- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth)::LEDeviceInquiryDelegate *)aDelegate;
- (void)dealloc;
// Actual scan can be delayed - we have to wait for a status update first.
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm
index 6ccdd0ff..2c4a7acd 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm
@@ -50,10 +50,13 @@
#include "qbluetoothuuid.h"
#include <QtCore/qloggingcategory.h>
+#include <QtCore/qglobal.h>
#include <QtCore/qstring.h>
#include <QtCore/qdebug.h>
#include <QtCore/qlist.h>
+#include <Foundation/Foundation.h>
+// Only after Foundation.h:
#include "osx/corebluetoothwrapper_p.h"
QT_BEGIN_NAMESPACE
@@ -137,36 +140,32 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(con
lastError(QBluetoothDeviceDiscoveryAgent::NoError),
inquiryType(QBluetoothDeviceDiscoveryAgent::GeneralUnlimitedInquiry)
{
- Q_ASSERT_X(q != Q_NULLPTR, "QBluetoothDeviceDiscoveryAgentPrivate()",
- "invalid q_ptr (null)");
+ Q_ASSERT_X(q != Q_NULLPTR, Q_FUNC_INFO, "invalid q_ptr (null)");
HostController controller([[IOBluetoothHostController defaultController] retain]);
if (!controller || [controller powerState] != kBluetoothHCIPowerStateON) {
- qCCritical(QT_BT_OSX) << "QBluetoothDeviceDiscoveryAgentPrivate() "
- "no default host controller or adapter is off";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "no default host "
+ "controller or adapter is off";
return;
}
DeviceInquiry newInquiry([[DeviceInquiryObjC alloc]initWithDelegate:this]);
if (!newInquiry) { // Obj-C's way of "reporting errors":
- qCCritical(QT_BT_OSX) << "QBluetoothDeviceDiscoveryAgentPrivate() "
- "failed to initialize an inquiry";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to "
+ "initialize an inquiry";
return;
}
// OSXBTLEDeviceInquiry can be constructed even if LE is not supported -
// at this stage it's only a memory allocation of the object itself,
- // if it fails - we have some memory-related problems.
+ // if it fails - we have some memory-related problem.
LEDeviceInquiry newInquiryLE([[LEDeviceInquiryObjC alloc] initWithDelegate:this]);
if (!newInquiryLE) {
- qCWarning(QT_BT_OSX) << "QBluetoothDeviceDiscoveryAgentPrivate() "
- "failed to initialize a LE inquiry";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to "
+ "initialize a LE inquiry";
return;
}
- qCDebug(QT_BT_OSX) << "host controller is in 'on' state, "
- "discovery agent created successfully";
-
hostController.reset(controller.take());
inquiry.reset(newInquiry.take());
inquiryLE.reset(newInquiryLE.take());
@@ -182,41 +181,28 @@ bool QBluetoothDeviceDiscoveryAgentPrivate::isValid() const
// can fail to initialize some important data-members
// (and the error is probably not even related to Bluetooth at all)
// - say, allocation error - this is what meant here by valid/invalid.
-
- const bool valid = hostController && [hostController powerState] == kBluetoothHCIPowerStateON && inquiry;
- qCDebug(QT_BT_OSX) << "private agent is valid state? "<<valid;
-
- if (hostController && [hostController powerState] != kBluetoothHCIPowerStateON)
- qCWarning(QT_BT_OSX) << "adapter is powered off (was on)";
-
return hostController && [hostController powerState] == kBluetoothHCIPowerStateON && inquiry;
}
bool QBluetoothDeviceDiscoveryAgentPrivate::isActive() const
{
- if (startPending) {
- qCDebug(QT_BT_OSX) << "start is pending, isActive == true";
+ if (startPending)
return true;
- }
- if (stopPending) {
- qCDebug(QT_BT_OSX) << "stop is pending, isActive == false";
- return false;
- }
- qCDebug(QT_BT_OSX)<<"isActive? "<< (agentState != NonActive);
+ if (stopPending)
+ return false;
return agentState != NonActive;
}
void QBluetoothDeviceDiscoveryAgentPrivate::start()
{
- Q_ASSERT_X(isValid(), "start()", "called on invalid device discovery agent");
- Q_ASSERT_X(!isActive(), "start()", "called on active device discovery agent");
+ Q_ASSERT_X(isValid(), Q_FUNC_INFO, "called on invalid device discovery agent");
+ Q_ASSERT_X(!isActive(), Q_FUNC_INFO, "called on active device discovery agent");
Q_ASSERT_X(lastError != QBluetoothDeviceDiscoveryAgent::InvalidBluetoothAdapterError,
- "start()", "called with an invalid Bluetooth adapter");
+ Q_FUNC_INFO, "called with an invalid Bluetooth adapter");
if (stopPending) {
- qCDebug(QT_BT_OSX) << "START: stop is pending, set start pending and return";
startPending = true;
return;
}
@@ -228,44 +214,37 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start()
const IOReturn res = [inquiry start];
if (res != kIOReturnSuccess) {
- qCDebug(QT_BT_OSX) << "START: private agent, failed to start";
setError(res, QObject::tr("device discovery agent: failed to start"));
agentState = NonActive;
emit q_ptr->error(lastError);
- } else {
- qCDebug(QT_BT_OSX) << "START: device inquiry started ...";
}
}
void QBluetoothDeviceDiscoveryAgentPrivate::startLE()
{
- Q_ASSERT_X(isValid(), "startLE()", "called on invalid device discovery agent");
+ Q_ASSERT_X(isValid(), Q_FUNC_INFO, "called on invalid device discovery agent");
Q_ASSERT_X(lastError != QBluetoothDeviceDiscoveryAgent::InvalidBluetoothAdapterError,
- "startLE()", "called with an invalid Bluetooth adapter");
+ Q_FUNC_INFO, "called with an invalid Bluetooth adapter");
agentState = LEScan;
if (![inquiryLE start]) {
// We can be here only if we have some kind of resource allocation error, so we
// do not emit finished, we emit error.
- qCDebug(QT_BT_OSX) << "STARTLE: failed to start LE scan ...";
-
setError(QBluetoothDeviceDiscoveryAgent::UnknownError,
QObject::tr("device discovery agent, LE mode: "
"resource allocation error"));
agentState = NonActive;
emit q_ptr->error(lastError);
- } else {
- qCDebug(QT_BT_OSX) << "STARTLE: scan started.";
}
}
void QBluetoothDeviceDiscoveryAgentPrivate::stop()
{
- Q_ASSERT_X(isValid(), "stop()", "called on invalid device discovery agent");
- Q_ASSERT_X(isActive(), "stop()", "called whithout active inquiry");
+ Q_ASSERT_X(isValid(), Q_FUNC_INFO, "called on invalid device discovery agent");
+ Q_ASSERT_X(isActive(), Q_FUNC_INFO, "called whithout active inquiry");
Q_ASSERT_X(lastError != QBluetoothDeviceDiscoveryAgent::InvalidBluetoothAdapterError,
- "stop()", "called with invalid bluetooth adapter");
+ Q_FUNC_INFO, "called with invalid bluetooth adapter");
const bool prevStart = startPending;
startPending = false;
@@ -276,19 +255,15 @@ void QBluetoothDeviceDiscoveryAgentPrivate::stop()
if (agentState == ClassicScan) {
const IOReturn res = [inquiry stop];
if (res != kIOReturnSuccess) {
- qCWarning(QT_BT_OSX) << "QBluetoothDeviceDiscoveryAgentPrivate::stop(), "
- "failed to stop";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to stop";
startPending = prevStart;
stopPending = false;
setError(res, QObject::tr("device discovery agent: failed to stop"));
emit q_ptr->error(lastError);
- } else {
- qCDebug(QT_BT_OSX) << "stop success on a classic device inquiry";
}
} else {
// Can be asynchronous (depending on a status update of CBCentralManager).
// The call itself is always 'success'.
- qCDebug(QT_BT_OSX) << "trying to stop LE scan ...";
[inquiryLE stop];
}
}
@@ -297,19 +272,16 @@ void QBluetoothDeviceDiscoveryAgentPrivate::inquiryFinished(IOBluetoothDeviceInq
{
Q_UNUSED(inq)
- Q_ASSERT_X(isValid(), "inquiryFinished", "invalid device discovery agent"); //We can never be here.
- Q_ASSERT_X(q_ptr, "inquiryFinished", "invalid q_ptr (null)");
+ Q_ASSERT_X(isValid(), Q_FUNC_INFO, "invalid device discovery agent"); //We can never be here.
// The subsequent start(LE) function (if any)
// will (re)set the correct state.
agentState = NonActive;
if (stopPending && !startPending) {
- qCDebug(QT_BT_OSX) << "inquiryFinished, stop pending, no pending start, emit canceled";
stopPending = false;
emit q_ptr->canceled();
} else if (startPending) {
- qCDebug(QT_BT_OSX) << "inquiryFinished, NO stop pending, pending start, re-starting";
startPending = false;
stopPending = false;
start();
@@ -318,7 +290,6 @@ void QBluetoothDeviceDiscoveryAgentPrivate::inquiryFinished(IOBluetoothDeviceInq
// finished in a normal way (not cancelled).
// startLE() will take care of old devices
// not supporting Bluetooth 4.0.
- qCDebug(QT_BT_OSX)<<"CLASSIC inquiryFinished, NO stop pending, starting LE";
startLE();
}
}
@@ -327,16 +298,13 @@ void QBluetoothDeviceDiscoveryAgentPrivate::error(IOBluetoothDeviceInquiry *inq,
{
Q_UNUSED(inq)
- Q_ASSERT_X(isValid(), "error", "invalid device discovery agent");
-
- qCDebug(QT_BT_OSX)<<"ERROR: got a native error code: "<<int(error);
+ Q_ASSERT_X(isValid(), Q_FUNC_INFO, "invalid device discovery agent");
startPending = false;
stopPending = false;
setError(error);
- Q_ASSERT_X(q_ptr, "error", "invalid q_ptr (null)");
emit q_ptr->error(lastError);
}
@@ -344,10 +312,9 @@ void QBluetoothDeviceDiscoveryAgentPrivate::deviceFound(IOBluetoothDeviceInquiry
{
Q_UNUSED(inq)
- Q_ASSERT_X(isValid(), "deviceFound()",
- "invalid device discovery agent");
- Q_ASSERT_X(device, "deviceFound()", "invalid IOBluetoothDevice (nil)");
- Q_ASSERT_X(agentState == ClassicScan, "deviceFound",
+ Q_ASSERT_X(isValid(), Q_FUNC_INFO, "invalid device discovery agent");
+ Q_ASSERT_X(device, Q_FUNC_INFO, "invalid IOBluetoothDevice (nil)");
+ Q_ASSERT_X(agentState == ClassicScan, Q_FUNC_INFO,
"invalid agent state (expected classic scan)");
QT_BT_MAC_AUTORELEASEPOOL;
@@ -355,8 +322,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::deviceFound(IOBluetoothDeviceInquiry
// Let's collect some info about this device:
const QBluetoothAddress deviceAddress(OSXBluetooth::qt_address([device getAddress]));
if (deviceAddress.isNull()) {
- qCWarning(QT_BT_OSX) << "QBluetoothDeviceDiscoveryAgentPrivate::deviceFound(), "
- "invalid Bluetooth address";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid Bluetooth address";
return;
}
@@ -413,7 +379,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::setError(QBluetoothDeviceDiscoveryAg
}
}
- qCDebug(QT_BT_OSX) << "error set: "<<errorString;
+ if (lastError != QBluetoothDeviceDiscoveryAgent::NoError)
+ qCDebug(QT_BT_OSX) << "error set: "<<errorString;
}
void QBluetoothDeviceDiscoveryAgentPrivate::LEdeviceInquiryError(QBluetoothDeviceDiscoveryAgent::Error error)
@@ -421,9 +388,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::LEdeviceInquiryError(QBluetoothDevic
// At the moment the only error reported can be 'powered off' error, it happens
// after the LE scan started (so we have LE support and this is a real PoweredOffError).
Q_ASSERT_X(error == QBluetoothDeviceDiscoveryAgent::PoweredOffError,
- "LEdeviceInquiryError", "unexpected error code");
-
- qCDebug(QT_BT_OSX) << "LEDeviceInquiryError: powered off";
+ Q_FUNC_INFO, "unexpected error code");
agentState = NonActive;
setError(error);
@@ -438,8 +403,6 @@ void QBluetoothDeviceDiscoveryAgentPrivate::LEnotSupported()
// the user can call stop (setting a pending stop).
// So the same rule apply:
- qCDebug(QT_BT_OSX) << "LE not supported.";
-
LEdeviceInquiryFinished();
}
@@ -447,8 +410,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::LEdeviceFound(CBPeripheral *peripher
NSDictionary *advertisementData,
NSNumber *RSSI)
{
- Q_ASSERT_X(peripheral, "LEdeviceFound()", "invalid peripheral (nil)");
- Q_ASSERT_X(agentState == LEScan, "LEdeviceFound",
+ Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)");
+ Q_ASSERT_X(agentState == LEScan, Q_FUNC_INFO,
"invalid agent state, expected LE scan");
Q_UNUSED(advertisementData)
@@ -473,16 +436,13 @@ void QBluetoothDeviceDiscoveryAgentPrivate::LEdeviceInquiryFinished()
agentState = NonActive;
if (stopPending && !startPending) {
- qCDebug(QT_BT_OSX) << "LE scan finished, stop pending, NO start pending, emit canceled";
stopPending = false;
emit q_ptr->canceled();
} else if (startPending) {
- qCDebug(QT_BT_OSX) << "LE scan finished, start pending, NO stop pending, re-start";
startPending = false;
stopPending = false;
start(); //Start from a classic scan again.
} else {
- qCDebug(QT_BT_OSX) << "LE scan finished, emit finished";
emit q_ptr->finished();
}
}
@@ -557,44 +517,31 @@ void QBluetoothDeviceDiscoveryAgent::start()
{
if (d_ptr->lastError != InvalidBluetoothAdapterError) {
if (d_ptr->isValid()) {
- qCDebug(QT_BT_OSX) << "DDA::start?";
- if (!isActive()) {
- qCDebug(QT_BT_OSX) << "DDA::start!";
+ if (!isActive())
d_ptr->start();
- }
} else {
// We previously failed to initialize d_ptr correctly:
// either some memory allocation problem or
// no BT adapter found.
- qCDebug(QT_BT_OSX) << "start failed, invalid d_ptr";
d_ptr->setError(InvalidBluetoothAdapterError);
emit error(InvalidBluetoothAdapterError);
}
- } else
- qCDebug(QT_BT_OSX) << "start failed, invalid adapter";
+ }
}
void QBluetoothDeviceDiscoveryAgent::stop()
{
if (d_ptr->isValid()) {
- qCDebug(QT_BT_OSX) << "DDA::stop, is valid";
- if (isActive() && d_ptr->lastError != InvalidBluetoothAdapterError) {
- qCDebug(QT_BT_OSX) << "DDA::stop, is active and no error...";
+ if (isActive() && d_ptr->lastError != InvalidBluetoothAdapterError)
d_ptr->stop();
- }
- } else {
- qCDebug(QT_BT_OSX) << "DDA::stop, d_ptr is not in valid state, can not stop";
}
}
bool QBluetoothDeviceDiscoveryAgent::isActive() const
{
- qCDebug(QT_BT_OSX) << "DDA::isActive";
- if (d_ptr->isValid()) {
+ if (d_ptr->isValid())
return d_ptr->isActive();
- } else {
- qCDebug(QT_BT_OSX) << "DDA::isActive, d_ptr is invalid";
- }
+
return false;
}