summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2015-02-02 11:09:33 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2015-02-02 11:09:33 +0100
commit3add162dddbe0f372a92de200e00b1cdbc177c84 (patch)
treec60113defbac2dfa1aa4e92d00fe26b9e2324e2b /src
parentfd96b0aa5ae37188f63e6bd1503024c1b5b3cf60 (diff)
parent3402cb8695aee2625eee8a4a4a96f81511c820e8 (diff)
Merge branch 'dev' into wip/win
Conflicts: src/bluetooth/bluetooth.pro Change-Id: I13c3e48afcc372395707159e7b2cca49972980ca
Diffstat (limited to 'src')
-rw-r--r--src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java12
-rw-r--r--src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothInputStreamThread.java5
-rw-r--r--src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java45
-rw-r--r--src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothSocketServer.java11
-rw-r--r--src/bluetooth/android/serveracceptancethread.cpp4
-rw-r--r--src/bluetooth/bluetooth.pro12
-rw-r--r--src/bluetooth/doc/src/bluetooth-index.qdoc12
-rw-r--r--src/bluetooth/doc/src/bluetooth-le-overview.qdoc13
-rw-r--r--src/bluetooth/osx/osxbt.pri6
-rw-r--r--src/bluetooth/osx/osxbtcentralmanager.mm462
-rw-r--r--src/bluetooth/osx/osxbtcentralmanager_p.h19
-rw-r--r--src/bluetooth/osx/osxbtcentralmanagerdelegate.mm68
-rw-r--r--src/bluetooth/osx/osxbtcentralmanagerdelegate_p.h68
-rw-r--r--src/bluetooth/osx/osxbtdeviceinquiry.mm46
-rw-r--r--src/bluetooth/osx/osxbtdevicepair.mm27
-rw-r--r--src/bluetooth/osx/osxbtdevicepair_p.h10
-rw-r--r--src/bluetooth/osx/osxbtl2capchannel.mm43
-rw-r--r--src/bluetooth/osx/osxbtl2capchannel_p.h19
-rw-r--r--src/bluetooth/osx/osxbtledeviceinquiry.mm65
-rw-r--r--src/bluetooth/osx/osxbtledeviceinquiry_p.h7
-rw-r--r--src/bluetooth/osx/osxbtobexsession.mm90
-rw-r--r--src/bluetooth/osx/osxbtobexsession_p.h7
-rw-r--r--src/bluetooth/osx/osxbtrfcommchannel.mm47
-rw-r--r--src/bluetooth/osx/osxbtrfcommchannel_p.h13
-rw-r--r--src/bluetooth/osx/osxbtsdpinquiry.mm35
-rw-r--r--src/bluetooth/osx/osxbtservicerecord.mm50
-rw-r--r--src/bluetooth/osx/osxbtsocketlistener.mm20
-rw-r--r--src/bluetooth/osx/osxbtutility.mm58
-rw-r--r--src/bluetooth/osx/osxbtutility_p.h1
-rw-r--r--src/bluetooth/qbluetoothaddress.cpp2
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp2
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_ios.mm45
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_osx.mm131
-rw-r--r--src/bluetooth/qbluetoothdeviceinfo.h5
-rw-r--r--src/bluetooth/qbluetoothlocaldevice.cpp6
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_osx.mm102
-rw-r--r--src/bluetooth/qbluetoothserver_osx.mm71
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent.cpp3
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent.h2
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_android.cpp26
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp4
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_osx.mm53
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp4
-rw-r--r--src/bluetooth/qbluetoothserviceinfo_osx.mm28
-rw-r--r--src/bluetooth/qbluetoothsocket.h3
-rw-r--r--src/bluetooth/qbluetoothsocket_android.cpp5
-rw-r--r--src/bluetooth/qbluetoothsocket_osx.mm48
-rw-r--r--src/bluetooth/qbluetoothtransfermanager.cpp2
-rw-r--r--src/bluetooth/qbluetoothtransferreply.cpp2
-rw-r--r--src/bluetooth/qbluetoothtransferreply_osx.mm37
-rw-r--r--src/bluetooth/qbluetoothuuid.cpp205
-rw-r--r--src/bluetooth/qbluetoothuuid.h97
-rw-r--r--src/bluetooth/qlowenergycharacteristic.cpp8
-rw-r--r--src/bluetooth/qlowenergycontroller_android.cpp20
-rw-r--r--src/bluetooth/qlowenergycontroller_bluez.cpp9
-rw-r--r--src/bluetooth/qlowenergycontroller_osx.mm168
-rw-r--r--src/bluetooth/qlowenergycontroller_osx_p.h1
-rw-r--r--src/bluetooth/qlowenergyservice.cpp28
-rw-r--r--src/bluetooth/qlowenergyservice.h3
-rw-r--r--src/bluetooth/qlowenergyservice_osx.mm17
-rw-r--r--src/imports/bluetooth/plugins.qmltypes3
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp27
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h3
-rw-r--r--src/imports/nfc/qdeclarativenearfield.cpp5
-rw-r--r--src/nfc/doc/src/nfc-overview.qdoc2
-rw-r--r--src/nfc/qndefnfcsmartposterrecord.cpp30
-rw-r--r--src/nfc/qndefnfcsmartposterrecord.h1
-rw-r--r--src/nfc/qnearfieldtarget.cpp6
-rw-r--r--src/nfc/qnearfieldtarget_emulator.cpp2
-rw-r--r--src/nfc/qnearfieldtarget_neard_p.h129
70 files changed, 1374 insertions, 1246 deletions
diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java
index f12e68fa..c8453a0b 100644
--- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java
+++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothBroadcastReceiver.java
@@ -40,7 +40,7 @@ import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
-import android.content.IntentFilter;
+
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashSet;
@@ -49,7 +49,9 @@ import java.util.List;
public class QtBluetoothBroadcastReceiver extends BroadcastReceiver
{
/* Pointer to the Qt object that "owns" the Java object */
+ @SuppressWarnings("WeakerAccess")
long qtObject = 0;
+ @SuppressWarnings("WeakerAccess")
static Activity qtactivity = null;
private static final int TURN_BT_ON = 3330;
@@ -158,11 +160,11 @@ public class QtBluetoothBroadcastReceiver extends BroadcastReceiver
//process found remote connections but avoid duplications
HashSet<String> set = new HashSet<String>();
- for (int i = 0; i < gattConnections.size(); i++)
- set.add(gattConnections.get(i).toString());
+ for (Object gattConnection : gattConnections)
+ set.add(gattConnection.toString());
- for (int i = 0; i < gattServerConnections.size(); i++)
- set.add(gattServerConnections.get(i).toString());
+ for (Object gattServerConnection : gattServerConnections)
+ set.add(gattServerConnection.toString());
return set.toArray(new String[set.size()]);
} catch (Exception ex) {
diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothInputStreamThread.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothInputStreamThread.java
index 30ada8c9..455054a8 100644
--- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothInputStreamThread.java
+++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothInputStreamThread.java
@@ -37,10 +37,13 @@ import java.io.InputStream;
import java.io.IOException;
import android.util.Log;
+@SuppressWarnings("WeakerAccess")
public class QtBluetoothInputStreamThread extends Thread
{
/* Pointer to the Qt object that "owns" the Java object */
+ @SuppressWarnings("CanBeFinal")
long qtObject = 0;
+ @SuppressWarnings("CanBeFinal")
public boolean logEnabled = false;
private static final String TAG = "QtBluetooth";
private InputStream m_inputStream = null;
@@ -68,7 +71,7 @@ public class QtBluetoothInputStreamThread extends Thread
}
byte[] buffer = new byte[1000];
- int bytesRead = 0;
+ int bytesRead;
try {
while (!isInterrupted()) {
diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java
index ea5d6ce6..10aaf9ca 100644
--- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java
+++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java
@@ -45,7 +45,6 @@ import android.bluetooth.BluetoothProfile;
import android.util.Log;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
@@ -58,7 +57,7 @@ public class QtBluetoothLE {
private BluetoothGatt mBluetoothGatt = null;
private String mRemoteGattAddress;
- final UUID clientCharacteristicUuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
+ private final UUID clientCharacteristicUuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
/* Pointer to the Qt object that "owns" the Java object */
@@ -67,6 +66,7 @@ public class QtBluetoothLE {
@SuppressWarnings("WeakerAccess")
Activity qtactivity = null;
+ @SuppressWarnings("WeakerAccess")
public QtBluetoothLE() {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
}
@@ -347,6 +347,24 @@ public class QtBluetoothLE {
leDescriptorRead(qtObject, descriptor.getCharacteristic().getService().getUuid().toString(),
descriptor.getCharacteristic().getUuid().toString(), runningHandle+1,
descriptor.getUuid().toString(), descriptor.getValue());
+
+ /* Some devices preset ClientCharacteristicConfiguration descriptors
+ * to enable notifications out of the box. However the additional
+ * BluetoothGatt.setCharacteristicNotification call prevents
+ * automatic notifications from coming through. Hence we manually set them
+ * up here.
+ */
+
+ if (descriptor.getUuid().compareTo(clientCharacteristicUuid) == 0) {
+ final int value = descriptor.getValue()[0];
+ // notification or indication bit set?
+ if ((value & 0x03) > 0) {
+ Log.d(TAG, "Found descriptor with automatic notifications.");
+ mBluetoothGatt.setCharacteristicNotification(
+ descriptor.getCharacteristic(), true);
+ }
+ }
+
performServiceDetailDiscoveryForHandle(runningHandle + 1, false);
}
@@ -432,6 +450,7 @@ public class QtBluetoothLE {
{
public GattEntry entry;
public byte[] newValue;
+ public int requestedWriteType;
}
private final Hashtable<UUID, List<Integer>> uuidToEntry = new Hashtable<UUID, List<Integer>>(100);
@@ -787,7 +806,8 @@ public class QtBluetoothLE {
/* Write Characteristics */
/*************************************************************/
- public boolean writeCharacteristic(int charHandle, byte[] newValue)
+ public boolean writeCharacteristic(int charHandle, byte[] newValue,
+ int writeMode)
{
if (mBluetoothGatt == null)
return false;
@@ -804,6 +824,17 @@ public class QtBluetoothLE {
newJob.newValue = newValue;
newJob.entry = entry;
+ // writeMode must be in sync with QLowEnergyService::WriteMode
+ // For now we ignore SignedWriteType as Qt doesn't support it yet.
+ switch (writeMode) {
+ case 1: //WriteWithoutResponse
+ newJob.requestedWriteType = BluetoothGattCharacteristic. WRITE_TYPE_NO_RESPONSE;
+ break;
+ default:
+ newJob.requestedWriteType = BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT;
+ break;
+ }
+
boolean result;
synchronized (writeQueue) {
result = writeQueue.add(newJob);
@@ -838,6 +869,7 @@ public class QtBluetoothLE {
WriteJob newJob = new WriteJob();
newJob.newValue = newValue;
newJob.entry = entry;
+ newJob.requestedWriteType = BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT;
boolean result;
synchronized (writeQueue) {
@@ -873,6 +905,9 @@ public class QtBluetoothLE {
boolean result;
switch (nextJob.entry.type) {
case Characteristic:
+ if (nextJob.entry.characteristic.getWriteType() != nextJob.requestedWriteType) {
+ nextJob.entry.characteristic.setWriteType(nextJob.requestedWriteType);
+ }
result = nextJob.entry.characteristic.setValue(nextJob.newValue);
if (!result || !mBluetoothGatt.writeCharacteristic(nextJob.entry.characteristic))
skip = true;
@@ -882,9 +917,9 @@ public class QtBluetoothLE {
/*
For some reason, Android splits characteristic notifications
into two operations. BluetoothGatt.enableCharacteristicNotification
- ensures the local Blueooth stack forwards the notifications. In addition,
+ ensures the local Bluetooth stack forwards the notifications. In addition,
BluetoothGattDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)
- must be written to the peripheral
+ must be written to the peripheral.
*/
diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothSocketServer.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothSocketServer.java
index ae0a03a5..1b1aaac9 100644
--- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothSocketServer.java
+++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothSocketServer.java
@@ -40,11 +40,14 @@ import android.util.Log;
import java.io.IOException;
import java.util.UUID;
+@SuppressWarnings("WeakerAccess")
public class QtBluetoothSocketServer extends Thread
{
/* Pointer to the Qt object that "owns" the Java object */
+ @SuppressWarnings({"WeakerAccess", "CanBeFinal"})
long qtObject = 0;
+ @SuppressWarnings({"WeakerAccess", "CanBeFinal"})
public boolean logEnabled = false;
private static final String TAG = "QtBluetooth";
@@ -54,9 +57,9 @@ public class QtBluetoothSocketServer extends Thread
private BluetoothServerSocket m_serverSocket = null;
//error codes
- public static final int QT_NO_BLUETOOTH_SUPPORTED = 0;
- public static final int QT_LISTEN_FAILED = 1;
- public static final int QT_ACCEPT_FAILED = 2;
+ private static final int QT_NO_BLUETOOTH_SUPPORTED = 0;
+ private static final int QT_LISTEN_FAILED = 1;
+ private static final int QT_ACCEPT_FAILED = 2;
public QtBluetoothSocketServer()
{
@@ -97,7 +100,7 @@ public class QtBluetoothSocketServer extends Thread
return;
}
- BluetoothSocket s = null;
+ BluetoothSocket s;
if (m_serverSocket != null) {
try {
while (!isInterrupted()) {
diff --git a/src/bluetooth/android/serveracceptancethread.cpp b/src/bluetooth/android/serveracceptancethread.cpp
index cc639135..185cfa54 100644
--- a/src/bluetooth/android/serveracceptancethread.cpp
+++ b/src/bluetooth/android/serveracceptancethread.cpp
@@ -38,10 +38,12 @@
Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
+Q_DECLARE_METATYPE(QBluetoothServer::Error)
+
ServerAcceptanceThread::ServerAcceptanceThread(QObject *parent) :
QObject(parent), maxPendingConnections(1)
{
- qRegisterMetaType<QBluetoothServer::Error>("QBluetoothServer::Error");
+ qRegisterMetaType<QBluetoothServer::Error>();
}
ServerAcceptanceThread::~ServerAcceptanceThread()
diff --git a/src/bluetooth/bluetooth.pro b/src/bluetooth/bluetooth.pro
index 334ff600..a7cd50e5 100644
--- a/src/bluetooth/bluetooth.pro
+++ b/src/bluetooth/bluetooth.pro
@@ -177,13 +177,16 @@ config_bluez:qtHaveModule(dbus) {
SOURCES -= qlowenergycontroller.cpp
SOURCES -= qlowenergycontroller_p.cpp
} else:ios {
- message("iOS is currently an unsupported Bluetooth platform, WIP.")
-
DEFINES += QT_IOS_BLUETOOTH
LIBS += -framework Foundation -framework CoreBluetooth
OBJECTIVE_SOURCES += \
- qbluetoothdevicediscoveryagent_ios.mm
+ qbluetoothdevicediscoveryagent_ios.mm \
+ qlowenergycontroller_osx.mm \
+ qlowenergyservice_osx.mm
+
+ PRIVATE_HEADERS += \
+ qlowenergycontroller_osx_p.h
include(osx/osxbt.pri)
SOURCES += \
@@ -196,6 +199,9 @@ config_bluez:qtHaveModule(dbus) {
qlowenergycontroller_p.cpp
SOURCES -= qbluetoothdevicediscoveryagent.cpp
+ SOURCES -= qlowenergycontroller_p.cpp
+ SOURCES -= qlowenergyservice.cpp
+ SOURCES -= qlowenergycontroller.cpp
} else:win32:!winrt:!wince {
include(windows/windows.pri)
diff --git a/src/bluetooth/doc/src/bluetooth-index.qdoc b/src/bluetooth/doc/src/bluetooth-index.qdoc
index 112444a8..af2c2421 100644
--- a/src/bluetooth/doc/src/bluetooth-index.qdoc
+++ b/src/bluetooth/doc/src/bluetooth-index.qdoc
@@ -33,11 +33,9 @@
The Bluetooth API provides connectivity between Bluetooth enabled devices.
-Currently the API is supported on \l{Qt for Android}{Android},
-\l{Qt for BlackBerry}{BlackBerry 10} and
-\l{Qt for Linux/X11}{Linux} (\l{http://www.bluez.org}{BlueZ 4.x/5.x}).
-
-
+Currently, the API is supported on the following platforms: \l{Qt for Android}{Android},
+\l{Qt for BlackBerry}{BlackBerry 10}, \l{Qt for iOS}{iOS}, \l{Qt for Linux/X11}{Linux}
+(\l{http://www.bluez.org}{BlueZ 4.x/5.x}) and \l{Qt for OS X}{OS X}.
\section1 Overview
@@ -47,11 +45,9 @@ for transferring data between devices. Bluetooth connectivity is based on
basic device management, such as scanning for devices, gathering information
about them, and exchanging data between them.
-This Qt release contains a Technology Preview of the new Qt Bluetooth
+Qt 5.5 contains the first full release of the new Qt Bluetooth
Low Energy API. Further details can be found in the
\l {Bluetooth Low Energy Overview}{Bluetooth Low Energy Overview} section.
-The Tech Preview supports BlueZ 4 & 5 based Linux systems. Support for
-further platforms is being planned.
\section1 Getting Started
diff --git a/src/bluetooth/doc/src/bluetooth-le-overview.qdoc b/src/bluetooth/doc/src/bluetooth-le-overview.qdoc
index 029171f4..a56e43fc 100644
--- a/src/bluetooth/doc/src/bluetooth-le-overview.qdoc
+++ b/src/bluetooth/doc/src/bluetooth-le-overview.qdoc
@@ -36,15 +36,10 @@ Low Energy devices.
\section1 Technology Preview
- The Qt Bluetooth Low Energy API has been introduced in Qt 5.4.
- The API is considered to be a preview of the technology and currently only works
- on BlueZ 4 & 5 based Linux systems. Support for further platforms, for example Android,
- is currently being worked on and will be added by later Qt releases. In addition,
- Qt only supports the central role. For more details on this limitation see below.
-
- While the API is not yet frozen it is close to its final stage.
- We would like to encourage you to send us feedback and bug reports related to
- this new feature.
+ The Qt Bluetooth Low Energy API was introduced by Qt 5.4. Since Qt 5.5 the API
+ is frozen and a compatibility guarantee is given for future releases.
+ At the moment, Qt only supports the Bluetooth Low Energy central role.
+ For more details on this limitation see below.
\section1 What Is Bluetooth Low Energy
diff --git a/src/bluetooth/osx/osxbt.pri b/src/bluetooth/osx/osxbt.pri
index 1eddcf4c..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,15 +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/osxbtcentralmanager.mm b/src/bluetooth/osx/osxbtcentralmanager.mm
index 73d9d5bc..2fc74e36 100644
--- a/src/bluetooth/osx/osxbtcentralmanager.mm
+++ b/src/bluetooth/osx/osxbtcentralmanager.mm
@@ -65,7 +65,7 @@ NSUInteger qt_countGATTEntries(CBService *service)
// No checks if NSUInteger is big enough :)
// Let's assume such number of entries is not possible :)
- Q_ASSERT_X(service, "qt_countGATTEntries", "invalid service (nil)");
+ Q_ASSERT_X(service, Q_FUNC_INFO, "invalid service (nil)");
QT_BT_MAC_AUTORELEASEPOOL;
@@ -112,7 +112,7 @@ using namespace QT_NAMESPACE;
startingFrom:(CBDescriptor *)descriptor;
- (CBDescriptor *)descriptor:(const QBluetoothUuid &)dUuid
forCharacteristic:(CBCharacteristic *)ch;
-// TODO: check _what_ exactly I have to reset ...
+- (bool)cacheWriteValue:(const QByteArray &)value for:(NSObject *)obj;
- (void)reset;
@end
@@ -121,7 +121,7 @@ using namespace QT_NAMESPACE;
- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth)::CentralManagerDelegate *)aDelegate
{
- Q_ASSERT_X(aDelegate, "-initWithDelegate:", "invalid delegate (null)");
+ Q_ASSERT_X(aDelegate, Q_FUNC_INFO, "invalid delegate (null)");
if (self = [super init]) {
manager = nil;
@@ -159,8 +159,8 @@ using namespace QT_NAMESPACE;
- (QLowEnergyController::Error)connectToDevice:(const QBluetoothUuid &)aDeviceUuid
{
- Q_ASSERT_X(managerState == OSXBluetooth::CentralManagerIdle, "-connectToDevice",
- "invalid state"); // QLowEnergyController connects only if in UnconnectedState.
+ Q_ASSERT_X(managerState == OSXBluetooth::CentralManagerIdle,
+ Q_FUNC_INFO, "invalid state");
deviceUuid = aDeviceUuid;
@@ -169,7 +169,7 @@ using namespace QT_NAMESPACE;
manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
if (!manager) {
managerState = OSXBluetooth::CentralManagerIdle;
- qCWarning(QT_BT_OSX) << "-connectToDevice:, failed to allocate a "
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to allocate a "
"central manager";
return QLowEnergyController::ConnectionError;
}
@@ -181,12 +181,12 @@ using namespace QT_NAMESPACE;
- (QLowEnergyController::Error)connectToDevice
{
- Q_ASSERT_X(manager, "-connectToDevice", "invalid central manager (nil)");
+ Q_ASSERT_X(manager, Q_FUNC_INFO, "invalid central manager (nil)");
Q_ASSERT_X(managerState == OSXBluetooth::CentralManagerIdle,
- "-connectToDevice", "invalid state");
+ Q_FUNC_INFO, "invalid state");
if ([self isConnected]) {
- qCDebug(QT_BT_OSX) << "-connectToDevice, already connected";
+ qCDebug(QT_BT_OSX) << Q_FUNC_INFO << "already connected";
delegate->connectSuccess();
return QLowEnergyController::NoError;
} else if (peripheral) {
@@ -201,7 +201,7 @@ using namespace QT_NAMESPACE;
// Retrieve a peripheral first ...
ObjCScopedPointer<NSMutableArray> uuids([[NSMutableArray alloc] init]);
if (!uuids) {
- qCWarning(QT_BT_OSX) << "-connectToDevice, failed to allocate identifiers";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to allocate identifiers";
return QLowEnergyController::ConnectionError;
}
@@ -212,7 +212,7 @@ using namespace QT_NAMESPACE;
std::copy(qtUuidData.data, qtUuidData.data + 16, uuidData);
const ObjCScopedPointer<NSUUID> nsUuid([[NSUUID alloc] initWithUUIDBytes:uuidData]);
if (!nsUuid) {
- qCWarning(QT_BT_OSX) << "-connectToDevice, failed to allocate NSUUID identifier";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to allocate NSUUID identifier";
return QLowEnergyController::ConnectionError;
}
@@ -222,7 +222,7 @@ using namespace QT_NAMESPACE;
QT_BT_MAC_AUTORELEASEPOOL;
NSArray *const peripherals = [manager retrievePeripheralsWithIdentifiers:uuids];
if (!peripherals || peripherals.count != 1) {
- qCWarning(QT_BT_OSX) << "-connectToDevice, failed to retrive a peripheral";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to retrive a peripheral";
return QLowEnergyController::UnknownRemoteDeviceError;
}
@@ -233,7 +233,7 @@ using namespace QT_NAMESPACE;
#else
OSXBluetooth::CFStrongReference<CFUUIDRef> cfUuid(OSXBluetooth::cf_uuid(deviceUuid));
if (!cfUuid) {
- qCWarning(QT_BT_OSX) << "-connectToDevice:, failed to create CFUUID object";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to create CFUUID object";
return QLowEnergyController::ConnectionError;
}
// TODO: With ARC this cast will be illegal:
@@ -248,17 +248,17 @@ using namespace QT_NAMESPACE;
- (void)connectToPeripheral
{
- Q_ASSERT_X(manager, "-connectToPeripheral", "invalid central manager (nil)");
- Q_ASSERT_X(peripheral, "-connectToPeripheral", "invalid peripheral (nil)");
+ Q_ASSERT_X(manager, Q_FUNC_INFO, "invalid central manager (nil)");
+ Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)");
Q_ASSERT_X(managerState == OSXBluetooth::CentralManagerIdle,
- "-connectToPeripheral", "invalid state");
+ Q_FUNC_INFO, "invalid state");
// The state is still the same - connecting.
if ([self isConnected]) {
- qCDebug(QT_BT_OSX) << "-connectToPeripheral, already connected";
+ qCDebug(QT_BT_OSX) << Q_FUNC_INFO << "already connected";
delegate->connectSuccess();
} else {
- qCDebug(QT_BT_OSX) << "-connectToPeripheral, trying to connect";
+ qCDebug(QT_BT_OSX) << Q_FUNC_INFO << "trying to connect";
managerState = OSXBluetooth::CentralManagerConnecting;
[manager connectPeripheral:peripheral options:nil];
}
@@ -300,9 +300,9 @@ using namespace QT_NAMESPACE;
- (void)discoverServices
{
- Q_ASSERT_X(peripheral, "-discoverServices", "invalid peripheral (nil)");
+ Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)");
Q_ASSERT_X(managerState == OSXBluetooth::CentralManagerIdle,
- "-discoverServices", "invalid state");
+ Q_FUNC_INFO, "invalid state");
// From Apple's docs:
//
@@ -321,17 +321,17 @@ using namespace QT_NAMESPACE;
{
using namespace OSXBluetooth;
- Q_ASSERT_X(managerState == CentralManagerIdle, "-discoverIncludedServices",
+ Q_ASSERT_X(managerState == CentralManagerIdle, Q_FUNC_INFO,
"invalid state");
- Q_ASSERT_X(manager, "-discoverIncludedServices", "invalid manager (nil)");
- Q_ASSERT_X(peripheral, "-discoverIncludedServices", "invalid peripheral (nil)");
+ Q_ASSERT_X(manager, Q_FUNC_INFO, "invalid manager (nil)");
+ Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)");
QT_BT_MAC_AUTORELEASEPOOL;
NSArray *const services = peripheral.services;
if (!services || !services.count) { // Actually, !services.count works in both cases, but ...
// A peripheral without any services at all.
- Q_ASSERT_X(delegate, "-discoverIncludedServices",
+ Q_ASSERT_X(delegate, Q_FUNC_INFO,
"invalid delegate (null)");
delegate->serviceDiscoveryFinished(ObjCStrongReference<NSArray>());
} else {
@@ -356,16 +356,13 @@ using namespace QT_NAMESPACE;
using namespace OSXBluetooth;
- Q_ASSERT_X(managerState != CentralManagerUpdating, "-discoverServiceDetails:",
- "invalid state");
- Q_ASSERT_X(!serviceUuid.isNull(), "-discoverServiceDetails:",
- "invalid service UUID");
- Q_ASSERT_X(peripheral, "-discoverServiceDetailsl:",
- "invalid peripheral (nil)");
+ Q_ASSERT_X(managerState != CentralManagerUpdating, Q_FUNC_INFO, "invalid state");
+ Q_ASSERT_X(!serviceUuid.isNull(), Q_FUNC_INFO, "invalid service UUID");
+ Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)");
if (servicesToDiscoverDetails.contains(serviceUuid)) {
- qCWarning(QT_BT_OSX) << "-discoverServiceDetails: "
- "already discovering for " << serviceUuid;
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO <<"already discovering for "
+ << serviceUuid;
return true;
}
@@ -377,8 +374,8 @@ using namespace QT_NAMESPACE;
return true;
}
- qCWarning(QT_BT_OSX) << "-discoverServiceDetails:, invalid service - "
- "unknown uuid " << serviceUuid;
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "unknown service uuid "
+ << serviceUuid;
return false;
}
@@ -387,17 +384,17 @@ using namespace QT_NAMESPACE;
{
// This method does not change 'managerState', we can
// have several 'detail discoveries' active.
- Q_ASSERT_X(service, "-readCharacteristics:", "invalid service (nil)");
+ Q_ASSERT_X(service, Q_FUNC_INFO, "invalid service (nil)");
using namespace OSXBluetooth;
QT_BT_MAC_AUTORELEASEPOOL;
- Q_ASSERT_X(managerState != CentralManagerUpdating, "-readCharacteristics:",
+ Q_ASSERT_X(managerState != CentralManagerUpdating, Q_FUNC_INFO,
"invalid state");
- Q_ASSERT_X(manager, "-readCharacteristics:", "invalid manager (nil)");
- Q_ASSERT_X(peripheral, "-readCharacteristics:", "invalid peripheral (nil)");
- Q_ASSERT_X(delegate, "-readCharacteristics:", "invalid delegate (null)");
+ Q_ASSERT_X(manager, Q_FUNC_INFO, "invalid manager (nil)");
+ Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
if (!service.characteristics || !service.characteristics.count)
return [self serviceDetailsDiscoveryFinished:service];
@@ -416,16 +413,16 @@ using namespace QT_NAMESPACE;
{
// This method does not change 'managerState', we can have
// several discoveries active.
- Q_ASSERT_X(service, "-discoverDescriptors:", "invalid service (nil)");
+ Q_ASSERT_X(service, Q_FUNC_INFO, "invalid service (nil)");
using namespace OSXBluetooth;
QT_BT_MAC_AUTORELEASEPOOL;
- Q_ASSERT_X(managerState != CentralManagerUpdating, "-discoverDescriptors",
- "invalid state");
- Q_ASSERT_X(manager, "-discoverDescriptors:", "invalid manager (nil)");
- Q_ASSERT_X(peripheral, "-discoverDescriptors:", "invalid peripheral (nil)");
+ Q_ASSERT_X(managerState != CentralManagerUpdating,
+ Q_FUNC_INFO, "invalid state");
+ Q_ASSERT_X(manager, Q_FUNC_INFO, "invalid manager (nil)");
+ Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)");
if (!service.characteristics || !service.characteristics.count) {
[self serviceDetailsDiscoveryFinished:service];
@@ -463,10 +460,8 @@ using namespace QT_NAMESPACE;
- (void)serviceDetailsDiscoveryFinished:(CBService *)service
{
//
- Q_ASSERT_X(service, "-serviceDetailsDiscoveryFinished:",
- "invalid service (nil)");
- Q_ASSERT_X(delegate, "-serviceDetailsDiscoveryFinished:",
- "invalid delegate (null)");
+ Q_ASSERT_X(service, Q_FUNC_INFO, "invalid service (nil)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
using namespace OSXBluetooth;
@@ -476,16 +471,13 @@ using namespace QT_NAMESPACE;
servicesToDiscoverDetails.removeAll(serviceUuid);
const NSUInteger nHandles = qt_countGATTEntries(service);
- Q_ASSERT_X(nHandles, "-serviceDetailsDiscoveryFinished:",
- "unexpected number of GATT entires");
+ Q_ASSERT_X(nHandles, Q_FUNC_INFO, "unexpected number of GATT entires");
const QLowEnergyHandle maxHandle = std::numeric_limits<QLowEnergyHandle>::max();
if (nHandles >= maxHandle || lastValidHandle > maxHandle - nHandles) {
// Well, that's unlikely :) But we must be sure.
- qCWarning(QT_BT_OSX) << "-serviceDetailsDiscoveryFinished:",
- "can not allocate more handles";
- // TODO: add more 'error' functions not to use fake handles (0)?
- delegate->error(serviceUuid, 0, QLowEnergyService::OperationError);
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "can not allocate more handles";
+ delegate->error(serviceUuid, QLowEnergyService::OperationError);
return;
}
@@ -530,6 +522,11 @@ using namespace QT_NAMESPACE;
newDesc.uuid = qt_uuid(d.UUID);
newDesc.value = qt_bytearray(static_cast<NSObject *>(d.value));
descList[lastValidHandle] = newDesc;
+ // Check, if it's client characteristic configuration descriptor:
+ if (newDesc.uuid == QBluetoothUuid::ClientCharacteristicConfiguration) {
+ if (newDesc.value.size() && (newDesc.value[0] & 3))
+ [peripheral setNotifyValue:YES forCharacteristic:c];
+ }
}
newChar.descriptorList = descList;
@@ -551,8 +548,7 @@ using namespace QT_NAMESPACE;
{
using namespace OSXBluetooth;
- Q_ASSERT_X(peripheral, "-performNextWriteRequest",
- "invalid peripheral (nil)");
+ Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)");
if (writePending || !writeQueue.size())
return;
@@ -561,59 +557,67 @@ using namespace QT_NAMESPACE;
if (request.isDescriptor) {
if (!descMap.contains(request.handle)) {
- qCWarning(QT_BT_OSX) << "-performNextWriteRequest, descriptor with "
- "handle: " << request.handle << " not found";
- [self performNextWriteRequest];
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "handle: "
+ << request.handle << " not found";
+ return [self performNextWriteRequest];
}
- CBDescriptor *const d = descMap[request.handle];
+ CBDescriptor *const descriptor = descMap[request.handle];
ObjCStrongReference<NSData> data(data_from_bytearray(request.value));
if (!data) {
// Even if qtData.size() == 0, we still need NSData object.
- qCWarning(QT_BT_OSX) << "-write:descHandle:, failed "
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed "
"to allocate an NSData object";
- [self performNextWriteRequest];
+ return [self performNextWriteRequest];
}
+ if (![self cacheWriteValue:request.value for:descriptor])
+ return [self performNextWriteRequest];
+
writePending = true;
- return [peripheral writeValue:data.data() forDescriptor:d];
+ return [peripheral writeValue:data.data() forDescriptor:descriptor];
} else {
- CBCharacteristic *const ch = charMap[request.handle];
- Q_ASSERT_X(ch, "-performNextWriteRequest", "invalid characteristic (nil)");
+ if (!charMap.contains(request.handle)) {
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "characteristic with "
+ "handle: " << request.handle << " not found";
+ return [self performNextWriteRequest];
+ }
+
+ CBCharacteristic *const characteristic = charMap[request.handle];
if (request.isClientConfiguration) {
- if (valuesToWrite.remove(request.handle)) {
- // It can happen if something went wrong - we
- // tried to set notification value and never received
- // a callback.
- qCDebug(QT_BT_OSX) << "-performNextWriteRequest:, "
- "valuesToWrite already contains "
- "a value for a given client configuration "
- "descriptor, replacing it";
- }
- // We save the original value to report it later ...
- valuesToWrite[request.handle] = request.value;
- const bool enable = request.value[0] & 3;
+ const QBluetoothUuid qtUuid(QBluetoothUuid::ClientCharacteristicConfiguration);
+ CBDescriptor *const descriptor = [self descriptor:qtUuid forCharacteristic:characteristic];
+ Q_ASSERT_X(descriptor, Q_FUNC_INFO, "no client characteristic "
+ "configuration descriptor found");
+
+ if (![self cacheWriteValue:request.value for:descriptor])
+ return [self performNextWriteRequest];
+
+ bool enable = false;
+ if (request.value.size())
+ enable = request.value[0] & 3;
+
writePending = true;
- [peripheral setNotifyValue:enable forCharacteristic:ch];
+ [peripheral setNotifyValue:enable forCharacteristic:characteristic];
} else {
ObjCStrongReference<NSData> data(data_from_bytearray(request.value));
if (!data) {
// Even if qtData.size() == 0, we still need NSData object.
- qCWarning(QT_BT_OSX) << "-performNextWriteRequest, "
- "failed to allocate NSData object";
- [self performNextWriteRequest];
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to allocate NSData object";
+ return [self performNextWriteRequest];
}
// TODO: check what happens if I'm using NSData with length 0.
if (request.withResponse) {
- NSLog(@"trying to write %@", data.data());
- NSLog(@"initial value: %@", ch.value);
+ if (![self cacheWriteValue:request.value for:characteristic])
+ return [self performNextWriteRequest];
+
writePending = true;
- [peripheral writeValue:data.data() forCharacteristic:ch
+ [peripheral writeValue:data.data() forCharacteristic:characteristic
type:CBCharacteristicWriteWithResponse];
} else {
- [peripheral writeValue:data.data() forCharacteristic:ch
+ [peripheral writeValue:data.data() forCharacteristic:characteristic
type:CBCharacteristicWriteWithoutResponse];
[self performNextWriteRequest];
}
@@ -624,12 +628,22 @@ using namespace QT_NAMESPACE;
- (bool)setNotifyValue:(const QByteArray &)value
forCharacteristic:(QT_PREPEND_NAMESPACE(QLowEnergyHandle))charHandle
{
- Q_ASSERT_X(charHandle, "-setNotifyValue:forCharacteristic:",
- "invalid characteristic handle (0)");
+ Q_ASSERT_X(charHandle, Q_FUNC_INFO, "invalid characteristic handle (0)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
if (!charMap.contains(charHandle)) {
- qCWarning(QT_BT_OSX) << "-setNotifyValue:forCharacteristic:, "
- "unknown characteristic handle " << charHandle;
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO
+ << "unknown characteristic handle " << charHandle;
+ return false;
+ }
+
+ // At the moment we call setNotifyValue _only_ from 'writeDescriptor';
+ // from Qt's API POV it's a descriptor write oprtation and we must report
+ // it back, so check _now_ that we really have this descriptor.
+ const QBluetoothUuid qtUuid(QBluetoothUuid::ClientCharacteristicConfiguration);
+ if (![self descriptor:qtUuid forCharacteristic:charMap[charHandle]]) {
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO
+ << "no client characteristic configuration found";
return false;
}
@@ -653,13 +667,12 @@ using namespace QT_NAMESPACE;
{
using namespace OSXBluetooth;
- Q_ASSERT_X(charHandle, "-write:charHandle:withResponse:", "invalid characteristic handle (0)");
+ Q_ASSERT_X(charHandle, Q_FUNC_INFO, "invalid characteristic handle (0)");
QT_BT_MAC_AUTORELEASEPOOL;
if (!charMap.contains(charHandle)) {
- qCWarning(QT_BT_OSX) << "-write:charHandle:withResponse:, "
- "characteristic: " << charHandle << " not found";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "characteristic: " << charHandle << " not found";
return false;
}
@@ -675,39 +688,17 @@ using namespace QT_NAMESPACE;
// write actually. If I have any problems with the order later,
// I'll use performSelector afterDelay with some delay.
return true;
-/*
- // Write without responce is not serialized - no way I can
- // know about the write operation success/failure - and
- // I will never perform the next write.
- CBCharacteristic *const ch = charMap[charHandle];
- Q_ASSERT_X(ch, "-write:charHandle:withResponse:", "invalid characteristic (nil) for a give handle");
- Q_ASSERT_X(peripheral, "-write:charHandle:withResponse:", "invalid peripheral (nil)");
-
- ObjCStrongReference<NSData> data(data_from_bytearray(value));
- if (!data) {
- // Even if qtData.size() == 0, we still need NSData object.
- qCWarning(QT_BT_OSX) << "-write:charHandle:withResponse:, "
- "failed to allocate NSData object";
- return false;
- }
-
- // TODO: check what happens if I'm using NSData with length 0.
- [peripheral writeValue:data.data() forCharacteristic:ch
- type:CBCharacteristicWriteWithoutResponse];
-
- return true;*/
}
- (bool)write:(const QByteArray &)value descHandle:(QLowEnergyHandle)descHandle
{
using namespace OSXBluetooth;
- Q_ASSERT_X(descHandle, "-write:descHandle:",
- "invalid descriptor handle (0)");
+ Q_ASSERT_X(descHandle, Q_FUNC_INFO, "invalid descriptor handle (0)");
if (!descMap.contains(descHandle)) {
- qCWarning(QT_BT_OSX) << "-write:descHandle:, descriptor with "
- "handle: " << descHandle << " not found";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "handle: "
+ << descHandle << " not found";
return false;
}
@@ -730,10 +721,8 @@ using namespace QT_NAMESPACE;
{
using namespace OSXBluetooth;
- Q_ASSERT_X(!qtUuid.isNull(), "-serviceForUUID:",
- "invalid uuid");
- Q_ASSERT_X(peripheral, "-serviceForUUID:",
- "invalid peripherla (nil)");
+ Q_ASSERT_X(!qtUuid.isNull(), Q_FUNC_INFO, "invalid uuid");
+ Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)");
ObjCStrongReference<NSMutableArray> toVisit([NSMutableArray arrayWithArray:peripheral.services], true);
ObjCStrongReference<NSMutableArray> toVisitNext([[NSMutableArray alloc] init], false);
@@ -763,14 +752,10 @@ using namespace QT_NAMESPACE;
- (CBCharacteristic *)nextCharacteristicForService:(CBService*)service
startingFrom:(CBCharacteristic *)characteristic
{
- Q_ASSERT_X(service, "-nextCharacteristicForService:startingFrom:",
- "invalid service (nil)");
- Q_ASSERT_X(characteristic, "-nextCharacteristicForService:startingFrom:",
- "invalid characteristic (nil)");
- Q_ASSERT_X(service.characteristics, "-nextCharacteristicForService:startingFrom:",
- "invalid service");
- Q_ASSERT_X(service.characteristics.count, "-nextCharacteristicForService:startingFrom:",
- "invalid service");
+ Q_ASSERT_X(service, Q_FUNC_INFO, "invalid service (nil)");
+ Q_ASSERT_X(characteristic, Q_FUNC_INFO, "invalid characteristic (nil)");
+ Q_ASSERT_X(service.characteristics, Q_FUNC_INFO, "invalid service");
+ Q_ASSERT_X(service.characteristics.count, Q_FUNC_INFO, "invalid service");
QT_BT_MAC_AUTORELEASEPOOL;
@@ -790,8 +775,7 @@ using namespace QT_NAMESPACE;
}
}
- Q_ASSERT_X([cs objectAtIndex:0] == characteristic,
- "-nextCharacteristicForService:startingFrom:",
+ Q_ASSERT_X([cs objectAtIndex:0] == characteristic, Q_FUNC_INFO,
"characteristic was not found in service.characteristics");
return [cs objectAtIndex:1];
@@ -801,14 +785,10 @@ using namespace QT_NAMESPACE;
startingFrom:(CBCharacteristic *)characteristic
properties:(CBCharacteristicProperties)properties
{
- Q_ASSERT_X(service, "-nextCharacteristicForService:startingFrom:properties:",
- "invalid service (nil)");
- Q_ASSERT_X(characteristic, "-nextCharacteristicForService:startingFrom:properties:",
- "invalid characteristic (nil)");
- Q_ASSERT_X(service.characteristics, "-nextCharacteristicForService:startingFrom:properties:",
- "invalid service");
- Q_ASSERT_X(service.characteristics.count, "-nextCharacteristicForService:startingFrom:properties:",
- "invalid service");
+ Q_ASSERT_X(service, Q_FUNC_INFO, "invalid service (nil)");
+ Q_ASSERT_X(characteristic, Q_FUNC_INFO, "invalid characteristic (nil)");
+ Q_ASSERT_X(service.characteristics, Q_FUNC_INFO, "invalid service");
+ Q_ASSERT_X(service.characteristics.count, Q_FUNC_INFO, "invalid service");
QT_BT_MAC_AUTORELEASEPOOL;
@@ -832,8 +812,7 @@ using namespace QT_NAMESPACE;
}
if (!index) {
- Q_ASSERT_X([cs objectAtIndex:0] == characteristic,
- "-nextCharacteristicForService:startingFrom:properties:",
+ Q_ASSERT_X([cs objectAtIndex:0] == characteristic, Q_FUNC_INFO,
"characteristic not found in service.characteristics");
index = 1;
}
@@ -850,16 +829,10 @@ using namespace QT_NAMESPACE;
- (CBDescriptor *)nextDescriptorForCharacteristic:(CBCharacteristic *)characteristic
startingFrom:(CBDescriptor *)descriptor
{
- Q_ASSERT_X(characteristic, "-nextDescriptorForCharacteristic:startingFrom:",
- "invalid characteristic (nil)");
- Q_ASSERT_X(descriptor, "-nextDescriptorForCharacteristic:startingFrom:",
- "invalid descriptor (nil)");
- Q_ASSERT_X(characteristic.descriptors,
- "-nextDescriptorForCharacteristic:startingFrom:",
- "invalid characteristic");
- Q_ASSERT_X(characteristic.descriptors.count,
- "-nextDescriptorForCharacteristic:startingFrom:",
- "invalid characteristic");
+ Q_ASSERT_X(characteristic, Q_FUNC_INFO, "invalid characteristic (nil)");
+ Q_ASSERT_X(descriptor, Q_FUNC_INFO, "invalid descriptor (nil)");
+ Q_ASSERT_X(characteristic.descriptors, Q_FUNC_INFO, "invalid characteristic");
+ Q_ASSERT_X(characteristic.descriptors.count, Q_FUNC_INFO, "invalid characteristic");
QT_BT_MAC_AUTORELEASEPOOL;
@@ -876,8 +849,7 @@ using namespace QT_NAMESPACE;
}
}
- Q_ASSERT_X([ds objectAtIndex:0] == descriptor,
- "-nextDescriptorForCharacteristic:startingFrom:",
+ Q_ASSERT_X([ds objectAtIndex:0] == descriptor, Q_FUNC_INFO,
"descriptor was not found in characteristic.descriptors");
return [ds objectAtIndex:1];
@@ -905,6 +877,41 @@ using namespace QT_NAMESPACE;
return descriptor;
}
+- (bool)cacheWriteValue:(const QByteArray &)value for:(NSObject *)obj
+{
+ Q_ASSERT_X(obj, Q_FUNC_INFO, "invalid object (nil)");
+
+ if ([obj isKindOfClass:[CBCharacteristic class]]) {
+ CBCharacteristic *const ch = static_cast<CBCharacteristic *>(obj);
+ if (!charMap.key(ch)) {
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "unexpected "
+ "characteristic, no handle found";
+ return false;
+ }
+ } else if ([obj isKindOfClass:[CBDescriptor class]]) {
+ CBDescriptor *const d = static_cast<CBDescriptor *>(obj);
+ if (!descMap.key(d)) {
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "unexpected "
+ "descriptor, no handle found";
+ return false;
+ }
+ } else {
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid object, "
+ "characteristic or descriptor required";
+ return false;
+ }
+
+ if (valuesToWrite.contains(obj)) {
+ // It can be a result of some previous errors - for example,
+ // we never got a callback from a previous write.
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "already has a cached value for this "
+ "object, the value will be replaced";
+ }
+
+ valuesToWrite[obj] = value;
+ return true;
+}
+
- (void)reset
{
writePending = false;
@@ -923,7 +930,7 @@ 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)");
using namespace OSXBluetooth;
@@ -983,7 +990,7 @@ using namespace QT_NAMESPACE;
}
} else {
// We actually handled all known states, but .. Core Bluetooth can change?
- Q_ASSERT_X(0, "-centralManagerDidUpdateState:", "invalid centra's state");
+ Q_ASSERT_X(0, Q_FUNC_INFO, "invalid centra's state");
}
}
@@ -992,7 +999,7 @@ using namespace QT_NAMESPACE;
Q_UNUSED(central)
// This method is required for iOS before 7.0 and OS X below 10.9.
- Q_ASSERT_X(manager, "-centralManager:didRetrivePeripherals:", "invalid central manager (nil)");
+ Q_ASSERT_X(manager, Q_FUNC_INFO, "invalid central manager (nil)");
if (managerState != OSXBluetooth::CentralManagerConnecting) {
// Canceled by calling -disconnectFromDevice method.
@@ -1002,11 +1009,10 @@ using namespace QT_NAMESPACE;
managerState = OSXBluetooth::CentralManagerIdle;
if (!peripherals || peripherals.count != 1) {
- Q_ASSERT_X(delegate, "-centralManager:didRetrievePeripherals:",
+ Q_ASSERT_X(delegate, Q_FUNC_INFO,
"invalid delegate (null)");
- qCDebug(QT_BT_OSX) << "-centralManager:didRetrievePeripherals:, "
- "unexpected number of peripherals (!= 1)";
+ qCDebug(QT_BT_OSX) << Q_FUNC_INFO <<"unexpected number of peripherals (!= 1)";
delegate->error(QLowEnergyController::UnknownRemoteDeviceError);
} else {
@@ -1020,8 +1026,7 @@ using namespace QT_NAMESPACE;
Q_UNUSED(central)
Q_UNUSED(aPeripheral)
- Q_ASSERT_X(delegate, "-centralManager:didConnectPeripheral:",
- "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
if (managerState != OSXBluetooth::CentralManagerConnecting) {
// We called cancel but before disconnected, managed to connect?
@@ -1039,8 +1044,7 @@ using namespace QT_NAMESPACE;
Q_UNUSED(aPeripheral)
Q_UNUSED(error)
- Q_ASSERT_X(delegate, "-centralManager:didFailToConnectPeripheral:",
- "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
if (managerState != OSXBluetooth::CentralManagerConnecting) {
// Canceled already.
@@ -1058,16 +1062,14 @@ using namespace QT_NAMESPACE;
Q_UNUSED(central)
Q_UNUSED(aPeripheral)
- Q_ASSERT_X(delegate, "-centralManager:didDisconnectPeripheral:error:",
- "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
// Clear internal caches/data.
[self reset];
if (error && managerState == OSXBluetooth::CentralManagerDisconnecting) {
managerState = OSXBluetooth::CentralManagerIdle;
- qCWarning(QT_BT_OSX) << "-centralManager:didDisconnectPeripheral:, "
- "failed to disconnect";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to disconnect";
// TODO: instead of 'unknown' - .. ?
delegate->error(QLowEnergyController::UnknownRemoteDeviceError);
} else {
@@ -1091,7 +1093,7 @@ using namespace QT_NAMESPACE;
if (error) {
// NSLog, not qCDebug/Warning - to print the error.
- NSLog(@"-peripheral:didDiscoverServices:, failed with error %@", error);
+ NSLog(@"%s failed with error %@", Q_FUNC_INFO, error);
// TODO: better error mapping required.
delegate->error(QLowEnergyController::UnknownError);
} else {
@@ -1114,18 +1116,16 @@ using namespace QT_NAMESPACE;
QT_BT_MAC_AUTORELEASEPOOL;
- Q_ASSERT_X(delegate, "-peripheral:didDiscoverIncludedServicesForService:",
- "invalid delegate (null)");
- Q_ASSERT_X(peripheral, "-peripheral:didDiscoverIncludedServicesForService:",
- "invalid peripheral (nil)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
+ Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)");
// TODO: asserts on other "pointers" ...
managerState = CentralManagerIdle;
if (error) {
// NSLog, not qCWarning/Critical - to log the actual NSError and service UUID.
- NSLog(@"-peripheral:didDiscoverIncludedServicesForService:, finished with error %@ for service %@",
- error, service.UUID);
+ NSLog(@"%s: finished with error %@ for service %@",
+ Q_FUNC_INFO, error, service.UUID);
} else if (service.includedServices && service.includedServices.count) {
// Now we have even more services to do included services discovery ...
if (!servicesToVisitNext)
@@ -1186,15 +1186,13 @@ using namespace QT_NAMESPACE;
using namespace OSXBluetooth;
Q_ASSERT_X(managerState != CentralManagerUpdating,
- "-peripheral:didDiscoverCharacteristicsForService:",
- "invalid state");
- Q_ASSERT_X(delegate, "-peripheral:didDiscoverCharacteristicsForService:",
+ Q_FUNC_INFO, "invalid state");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO,
"invalid delegate (null)");
if (error) {
// NSLog to show the actual NSError (can contain something interesting).
- NSLog(@"-peripheral:didDiscoverCharacteristicsForService:error, failed with error: %@",
- error);
+ NSLog(@"%s failed with error: %@", Q_FUNC_INFO, error);
// We did not discover any characteristics and can not discover descriptors,
// inform our delegate (it will set a service state also).
delegate->error(qt_uuid(service.UUID), QLowEnergyController::UnknownError);
@@ -1210,11 +1208,8 @@ using namespace QT_NAMESPACE;
using namespace OSXBluetooth;
- Q_ASSERT_X(managerState != CentralManagerUpdating,
- "-peripheral:didUpdateValueForCharacteristic:error:",
- "invalid state");
- Q_ASSERT_X(peripheral, "-peripheral:didUpdateValueForCharacteristic:error:",
- "invalid peripheral (nil)");
+ Q_ASSERT_X(managerState != CentralManagerUpdating, Q_FUNC_INFO, "invalid state");
+ Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)");
QT_BT_MAC_AUTORELEASEPOOL;
// First, let's check if we're discovering a service details now.
@@ -1224,9 +1219,7 @@ using namespace QT_NAMESPACE;
if (error) {
// Use NSLog, not qCDebug/qCWarning to log the actual error.
- NSLog(@"-peripheral:didUpdateValueForCharacteristic:error:, failed with error %@",
- error);
-
+ NSLog(@"%s failed with error %@", Q_FUNC_INFO, error);
if (!isDetailsDiscovery) {
// TODO: this can be something else in a future (if needed at all).
return;
@@ -1250,13 +1243,12 @@ using namespace QT_NAMESPACE;
// updated values ...
// TODO: this must be properly tested.
if (!chHandle) {
- qCCritical(QT_BT_OSX) << "-peripheral:didUpdateValueForCharacteristic:error:, "
- "unexpected update notification, no characteristic handle found";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "unexpected update notification, "
+ "no characteristic handle found";
return;
}
- Q_ASSERT_X(delegate, "-peripheral:didUpdateValueForCharacteristic:error:",
- "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
delegate->characteristicUpdateNotification(chHandle,
qt_bytearray(characteristic.value));
}
@@ -1276,8 +1268,7 @@ using namespace QT_NAMESPACE;
if (error) {
// Log the error using NSLog:
- NSLog(@"-peripheral:didDiscoverDescriptorsForCharacteristic:error:, failed with error %@",
- error);
+ NSLog(@"%s failed with error %@", Q_FUNC_INFO, error);
// Probably, we can continue though ...
}
@@ -1296,8 +1287,7 @@ using namespace QT_NAMESPACE;
{
Q_UNUSED(aPeripheral)
- Q_ASSERT_X(peripheral, "-peripheral:didUpdateValueForDescriptor:error:",
- "invalid peripheral (nil)");
+ Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)");
QT_BT_MAC_AUTORELEASEPOOL;
@@ -1309,8 +1299,7 @@ using namespace QT_NAMESPACE;
if (error) {
// NSLog to log the actual error ...
- NSLog(@"-peripheral:didUpdateValueForDescriptor:error:, failed with error %@",
- error);
+ NSLog(@"%s failed with error %@", Q_FUNC_INFO, error);
if (!isDetailsDiscovery) {
// TODO: probably will be required in a future.
return;
@@ -1365,24 +1354,26 @@ using namespace QT_NAMESPACE;
writePending = false;
- Q_ASSERT_X(delegate, "-peripheral:didWriteValueForCharacteristic:error",
- "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
+
+
+ // Error or not, but the cached value has to be deleted ...
+ const QByteArray valueToReport(valuesToWrite.value(characteristic, QByteArray()));
+ if (!valuesToWrite.remove(characteristic)) {
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "no updated value found"
+ " for characteristic";
+ }
if (error) {
// Use NSLog to log the actual error:
- NSLog(@"-peripheral:didWriteValueForCharacteristic:error:, failed with error: %@",
- error);
- // TODO: no char handle at the moment, have to change to char index instead
- // and calculate the right handle in the LE controller.
- delegate->error(qt_uuid(characteristic.service.UUID), 0,
+ NSLog(@"%s failed with error %@", Q_FUNC_INFO, error);
+ delegate->error(qt_uuid(characteristic.service.UUID),
QLowEnergyService::CharacteristicWriteError);
} else {
// Keys are unique.
const QLowEnergyHandle cHandle = charMap.key(characteristic);
- Q_ASSERT_X(cHandle, "-peripheral:didWriteValueForCharacteristic:error",
- "invalid handle, not found in the characteristics map");
- NSLog(@"characteristic written, the value is %@", characteristic.value);
- delegate->characteristicWriteNotification(cHandle, qt_bytearray(characteristic.value));
+ Q_ASSERT_X(cHandle, Q_FUNC_INFO, "invalid handle, not found in the characteristics map");
+ delegate->characteristicWriteNotification(cHandle, valueToReport);
}
[self performNextWriteRequest];
@@ -1394,6 +1385,8 @@ using namespace QT_NAMESPACE;
{
Q_UNUSED(aPeripheral)
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
+
using namespace OSXBluetooth;
QT_BT_MAC_AUTORELEASEPOOL;
@@ -1402,21 +1395,21 @@ using namespace QT_NAMESPACE;
using namespace OSXBluetooth;
+ // Error or not, a value (if any) must be removed.
+ const QByteArray valueToReport(valuesToWrite.value(descriptor, QByteArray()));
+ if (!valuesToWrite.remove(descriptor))
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "no updated value found";
+
if (error) {
// NSLog to log the actual NSError:
- NSLog(@"-peripheral:didWriteValueForDescriptor:error:, failed with error %@",
- error);
- // TODO: this error function is not good at all - it takes charHandle,
- // which is noop at the moment and ... we actually work with a descriptor handle
- // here.
- delegate->error(qt_uuid(descriptor.characteristic.service.UUID), 0,
+ NSLog(@"%s failed with error %@", Q_FUNC_INFO, error);
+ delegate->error(qt_uuid(descriptor.characteristic.service.UUID),
QLowEnergyService::DescriptorWriteError);
} else {
- // We know that keys are unique, so we can find a key for a given descriptor.
const QLowEnergyHandle dHandle = descMap.key(descriptor);
- Q_ASSERT_X(dHandle, "-peripheral:didWriteValueForDescriptor:error:",
- "invalid descriptor, not found in the descriptors map");
- delegate->descriptorWriteNotification(dHandle, qt_bytearray(static_cast<NSObject *>(descriptor.value)));
+ Q_ASSERT_X(dHandle, Q_FUNC_INFO,
+ "descriptor not found in the descriptors map");
+ delegate->descriptorWriteNotification(dHandle, valueToReport);
}
[self performNextWriteRequest];
@@ -1434,39 +1427,30 @@ using namespace QT_NAMESPACE;
writePending = false;
- Q_ASSERT_X(delegate, "-peripheral:didUpdateNotificationStateForCharacteristic:",
- "invalid delegate (nil)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (nil)");
const QBluetoothUuid qtUuid(QBluetoothUuid::ClientCharacteristicConfiguration);
CBDescriptor *const descriptor = [self descriptor:qtUuid forCharacteristic:characteristic];
- const QLowEnergyHandle dHandle = descMap.key(descriptor);// 0 if descriptor is nil or unknown.
- const QByteArray valueToReport(valuesToWrite.value(dHandle, QByteArray()));
-
- if (!valuesToWrite.remove(dHandle)) {
- // In future it can be a special case: we can, in principle,
- // set notify value on a characteristic without 'writeDescriptor'.
- // It can also be some error. Right now we report it as error, can change.
- qCWarning(QT_BT_OSX) << "-peripheral:didUpdateNotificationStateForCharacteristic:, "
- "setNotifyValue called, but no client characteristic descriptor "
- "found or no writeDescriptor call";
- }
+ const QByteArray valueToReport(valuesToWrite.value(descriptor, QByteArray()));
+ const int nRemoved = valuesToWrite.remove(descriptor);
if (error) {
// NSLog to log the actual NSError:
- NSLog(@"-peripheral:didUpdateNotificationStateForCharacteristic:, failed with error %@",
- error);
- delegate->error(qt_uuid(characteristic.service.UUID), 0,
+ NSLog(@"%s failed with error %@", Q_FUNC_INFO, error);
+ delegate->error(qt_uuid(characteristic.service.UUID),
// In Qt's API it's a descriptor write actually.
QLowEnergyService::DescriptorWriteError);
} else {
- if (!valueToReport.isNull()) {
+ if (nRemoved) {
+ const QLowEnergyHandle dHandle = descMap.key(descriptor);
delegate->descriptorWriteNotification(dHandle, valueToReport);
} else {
- // TODO: can we in future have another way to set notify value without writeDescriptor?
- qCWarning(QT_BT_OSX) << "-peripheral:didUpdateNotificationStateForCharacteristic:, "
- "notification value set to " << int(characteristic.isNotifying)
+ /*
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << ": notification value set to "
+ << int(characteristic.isNotifying)
<< " but no client characteristic configuration descriptor found"
- "or no previous writeDescriptor request found";
+ " or no previous writeDescriptor request found";
+ */
}
}
diff --git a/src/bluetooth/osx/osxbtcentralmanager_p.h b/src/bluetooth/osx/osxbtcentralmanager_p.h
index 6d93816f..ff08c14a 100644
--- a/src/bluetooth/osx/osxbtcentralmanager_p.h
+++ b/src/bluetooth/osx/osxbtcentralmanager_p.h
@@ -93,9 +93,8 @@ public:
// Service related errors.
virtual void error(const QBluetoothUuid &serviceUuid,
QLowEnergyController::Error error) = 0;
- // Characteristics related errors.
+ // Characteristics/descriptors related errors.
virtual void error(const QBluetoothUuid &serviceUuid,
- QLowEnergyHandle charHandle,
QLowEnergyService::ServiceError error) = 0;
};
@@ -138,15 +137,13 @@ struct LEWriteRequest
typedef QQueue<LEWriteRequest> WriteQueue;
-// It can happen that Qt's API wants to write something
-// and expects the confirmation about this value written,
-// but under the hood (Core Bluetooth) we have something like
-// a special method without any values at all.
-// To report our user a successful write, we have this map:
-// handle -> value for a write operation.
-// Since write operations are serialized, the key is guaranteed
-// to be unique.
-typedef QHash<QLowEnergyHandle, QByteArray> ValueHash;
+// Core Bluetooth's write confirmation does not provide
+// the updated value (characteristic or descriptor).
+// But the Qt's Bluetooth API ('write with response')
+// expects this updated value as a response, so we have
+// to cache this write value and report it back.
+// 'NSObject *' will require '__weak' with ARC.
+typedef QHash<NSObject *, QByteArray> ValueHash;
}
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 61ab116c..4f67b726 100644
--- a/src/bluetooth/osx/osxbtdeviceinquiry.mm
+++ b/src/bluetooth/osx/osxbtdeviceinquiry.mm
@@ -71,17 +71,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:20];
+ [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 +108,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 +131,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 +154,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 +172,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/osxbtdevicepair.mm b/src/bluetooth/osx/osxbtdevicepair.mm
index c9d6de32..fdb95522 100644
--- a/src/bluetooth/osx/osxbtdevicepair.mm
+++ b/src/bluetooth/osx/osxbtdevicepair.mm
@@ -45,9 +45,6 @@
#include <QtCore/qloggingcategory.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 +79,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 +109,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 +117,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 +164,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 +190,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 +204,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/osx/osxbtl2capchannel.mm b/src/bluetooth/osx/osxbtl2capchannel.mm
index e0b38dfe..c62efc50 100644
--- a/src/bluetooth/osx/osxbtl2capchannel.mm
+++ b/src/bluetooth/osx/osxbtl2capchannel.mm
@@ -55,7 +55,7 @@ using namespace QT_NAMESPACE;
- (id)initWithDelegate:(OSXBluetooth::ChannelDelegate *)aDelegate
{
- Q_ASSERT_X(aDelegate, "-initWithDelegate:", "invalid delegate (null)");
+ Q_ASSERT_X(aDelegate, Q_FUNC_INFO, "invalid delegate (null)");
if (self = [super init]) {
delegate = aDelegate;
@@ -72,8 +72,8 @@ using namespace QT_NAMESPACE;
{
// This type of channel does not require connect, it's created with
// already open channel.
- Q_ASSERT_X(aDelegate, "-initWithDelegate:channel:", "invalid delegate (null)");
- Q_ASSERT_X(channel, "-initWithDelegate:channel:", "invalid channel (nil)");
+ Q_ASSERT_X(aDelegate, Q_FUNC_INFO, "invalid delegate (null)");
+ Q_ASSERT_X(channel, Q_FUNC_INFO, "invalid channel (nil)");
if (self = [super init]) {
delegate = aDelegate;
@@ -108,15 +108,13 @@ using namespace QT_NAMESPACE;
withPSM:(BluetoothL2CAPChannelID)psm
{
if (address.isNull()) {
- qCCritical(QT_BT_OSX) << "-connectAsyncToDevice:withPSM:, "
- "invalid peer address";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "invalid peer address";
return kIOReturnNoDevice;
}
// Can never be called twice.
if (connected || device || channel) {
- qCCritical(QT_BT_OSX) << "-connectAsyncToDevice:withPSM:, "
- "connection is already active";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "connection is already active";
return kIOReturnStillOpen;
}
@@ -125,15 +123,13 @@ using namespace QT_NAMESPACE;
const BluetoothDeviceAddress iobtAddress = OSXBluetooth::iobluetooth_address(address);
device = [IOBluetoothDevice deviceWithAddress:&iobtAddress];
if (!device) {
- qCCritical(QT_BT_OSX) << "-connectAsyncToDevice:withPSM:, "
- "failed to create a device";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to create a device";
return kIOReturnNoDevice;
}
const IOReturn status = [device openL2CAPChannelAsync:&channel withPSM:psm delegate:self];
if (status != kIOReturnSuccess) {
- qCCritical(QT_BT_OSX) << "-connectAsyncToDevice:withPSM:, "
- "failed to open L2CAP channel";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to open L2CAP channel";
// device is still autoreleased.
device = nil;
return status;
@@ -152,8 +148,7 @@ using namespace QT_NAMESPACE;
{
Q_UNUSED(l2capChannel)
- Q_ASSERT_X(delegate, "-l2capChannelData:data:length",
- "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
if (dataPointer && dataLength)
delegate->readChannelData(dataPointer, dataLength);
@@ -164,8 +159,7 @@ using namespace QT_NAMESPACE;
{
Q_UNUSED(l2capChannel)
- Q_ASSERT_X(delegate, "-l2capChannelOpenComplete:status:",
- "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
if (error != kIOReturnSuccess) {
delegate->setChannelError(error);
@@ -179,7 +173,7 @@ using namespace QT_NAMESPACE;
{
Q_UNUSED(l2capChannel)
- Q_ASSERT_X(delegate, "-l2capChannelClosed:", "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
delegate->channelClosed();
connected = false;
}
@@ -195,8 +189,7 @@ using namespace QT_NAMESPACE;
Q_UNUSED(l2capChannel)
Q_UNUSED(refcon)
- Q_ASSERT_X(delegate, "-l2capChannelWriteComplete:refcon:status",
- "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
if (error != kIOReturnSuccess)
delegate->setChannelError(error);
@@ -243,20 +236,18 @@ using namespace QT_NAMESPACE;
- (IOReturn) writeSync:(void*)data length:(UInt16)length
{
- Q_ASSERT_X(data, "-writeSync:length:", "invalid data (null)");
- Q_ASSERT_X(length, "-writeSync:length:", "invalid data size");
- Q_ASSERT_X(connected && channel, "-writeSync:",
- "invalid L2CAP channel");
+ Q_ASSERT_X(data, Q_FUNC_INFO, "invalid data (null)");
+ Q_ASSERT_X(length, Q_FUNC_INFO, "invalid data size");
+ Q_ASSERT_X(connected && channel, Q_FUNC_INFO, "invalid L2CAP channel");
return [channel writeSync:data length:length];
}
- (IOReturn) writeAsync:(void*)data length:(UInt16)length
{
- Q_ASSERT_X(data, "-writeAsync:length:", "invalid data (null)");
- Q_ASSERT_X(length, "-writeAync:length:", "invalid data size");
- Q_ASSERT_X(connected && channel, "-writeAsync:length:",
- "invalid L2CAP channel");
+ Q_ASSERT_X(data, Q_FUNC_INFO, "invalid data (null)");
+ Q_ASSERT_X(length, Q_FUNC_INFO, "invalid data size");
+ Q_ASSERT_X(connected && channel, Q_FUNC_INFO, "invalid L2CAP channel");
return [channel writeAsync:data length:length refcon:Q_NULLPTR];
}
diff --git a/src/bluetooth/osx/osxbtl2capchannel_p.h b/src/bluetooth/osx/osxbtl2capchannel_p.h
index 96ea985e..4888be56 100644
--- a/src/bluetooth/osx/osxbtl2capchannel_p.h
+++ b/src/bluetooth/osx/osxbtl2capchannel_p.h
@@ -44,10 +44,9 @@
#include <QtCore/qglobal.h>
-// Must be imported (Obj-C header, no inclusion guards).
-#import <IOBluetooth/objc/IOBluetoothL2CAPChannel.h>
-
#include <Foundation/Foundation.h>
+// Only after Foundation.h:
+#include "corebluetoothwrapper_p.h"
#include <cstddef>
@@ -67,20 +66,20 @@ QT_END_NAMESPACE
@interface QT_MANGLE_NAMESPACE(OSXBTL2CAPChannel) : NSObject<IOBluetoothL2CAPChannelDelegate>
{
- QT_PREPEND_NAMESPACE(OSXBluetooth::ChannelDelegate) *delegate;
+ QT_PREPEND_NAMESPACE(OSXBluetooth)::ChannelDelegate *delegate;
IOBluetoothDevice *device;
IOBluetoothL2CAPChannel *channel;
bool connected;
}
-- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth::ChannelDelegate) *)aDelegate;
-- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth::ChannelDelegate) *)aDelegate
+- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth)::ChannelDelegate *)aDelegate;
+- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth)::ChannelDelegate *)aDelegate
channel:(IOBluetoothL2CAPChannel *)aChannel;
- (void)dealloc;
-// A single async connection (connect can be called only once).
-- (IOReturn)connectAsyncToDevice:(const QBluetoothAddress &)address
+// Async. connection (connect can be called only once).
+- (IOReturn)connectAsyncToDevice:(const QT_PREPEND_NAMESPACE(QBluetoothAddress) &)address
withPSM:(BluetoothL2CAPChannelID)psm;
// IOBluetoothL2CAPChannelDelegate:
@@ -102,12 +101,12 @@ QT_END_NAMESPACE
// Writes the given data synchronously over the target L2CAP channel to the remote
// device.
-// The length of the data may not exceed the L2CAP channel's ougoing MTU.
+// The length of the data may not exceed the L2CAP channel's outgoing MTU.
// This method will block until the data has been successfully sent to the
// hardware for transmission (or an error occurs).
- (IOReturn) writeSync:(void*)data length:(UInt16)length;
-// The length of the data may not exceed the L2CAP channel's ougoing MTU.
+// The length of the data may not exceed the L2CAP channel's outgoing MTU.
// When the data has been successfully passed to the hardware to be transmitted,
// the delegate method -l2capChannelWriteComplete:refcon:status: will be called.
// Returns kIOReturnSuccess if the data was buffered successfully.
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/osx/osxbtobexsession.mm b/src/bluetooth/osx/osxbtobexsession.mm
index 8a5feb32..0bed6af2 100644
--- a/src/bluetooth/osx/osxbtobexsession.mm
+++ b/src/bluetooth/osx/osxbtobexsession.mm
@@ -48,10 +48,6 @@
#include <QtCore/qdebug.h>
#include <QtCore/qlist.h>
-// Import, since it's Obj-C headers:
-#import <IOBluetooth/objc/IOBluetoothOBEXSession.h>
-#import <IOBluetooth/objc/IOBluetoothDevice.h>
-
#include <algorithm>
#include <cstddef>
#include <limits>
@@ -91,7 +87,7 @@ enum {
quint32 extract_uint32(const uint8_t *bytes)
{
// Four byte value, high byte first.
- Q_ASSERT_X(bytes, "extract_uint32", "invalid input data (null)");
+ Q_ASSERT_X(bytes, Q_FUNC_INFO, "invalid input data (null)");
uint32_t value = uint32_t();
std::copy(bytes, bytes + sizeof value, reinterpret_cast<uint8_t *>(&value));
@@ -102,7 +98,7 @@ quint32 extract_uint32(const uint8_t *bytes)
quint16 extract_uint16(const uint8_t *bytes)
{
// Two byte value, high byte first.
- Q_ASSERT_X(bytes, "extract_uint16", "invalid input data (null)");
+ Q_ASSERT_X(bytes, Q_FUNC_INFO, "invalid input data (null)");
uint16_t value = uint16_t();
std::copy(bytes, bytes + sizeof value, reinterpret_cast<uint8_t *>(&value));
@@ -140,8 +136,8 @@ QList<OBEXHeader> qt_bluetooth_headers(const uint8_t *data, std::size_t length)
// 3. 10 A single byte value.
// 4. 11 A four byte value, sent high byte first.
- Q_ASSERT_X(data, "qt_bluetooth_headers", "invalid data (null)");
- Q_ASSERT_X(length >= 2, "qt_bluetooth_headers", "invalid data length");
+ Q_ASSERT_X(data, Q_FUNC_INFO, "invalid data (null)");
+ Q_ASSERT_X(length >= 2, Q_FUNC_INFO, "invalid data length");
Q_UNUSED(data)
Q_UNUSED(length)
@@ -209,7 +205,7 @@ QList<OBEXHeader> qt_bluetooth_headers(const uint8_t *data, std::size_t length)
break;
}
default:
- qCWarning(QT_BT_OSX) << "qt_bluetooth_headers(), invalid header format";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid header format";
return empty;
}
@@ -315,7 +311,7 @@ ObjCStrongReference<NSMutableData> next_data_chunk(QIODevice &inputStream, IOBlu
NSUInteger headersLength, bool &isLast)
{
// Work only for OBEX put (we request a specific payload length).
- Q_ASSERT_X(session, "next_data_chunk", "invalid OBEX session (nil)");
+ Q_ASSERT_X(session, Q_FUNC_INFO, "invalid OBEX session (nil)");
const OBEXMaxPacketLength packetSize = [session getAvailableCommandPayloadLength:kOBEXOpCodePut];
if (!packetSize || headersLength >= packetSize)
@@ -345,7 +341,7 @@ ObjCStrongReference<NSMutableData> next_data_chunk(QIODevice &inputStream, IOBlu
bool check_connect_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode &response)
{
- Q_ASSERT_X(e, "check_connect_event", "invalid event (null)");
+ Q_ASSERT_X(e, Q_FUNC_INFO, "invalid event (null)");
// This function tries to extract either an error code or a
// server response code. "Good" event has type connect command respond
@@ -364,7 +360,7 @@ bool check_connect_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode
response = e->u.connectCommandResponseData.serverResponseOpCode;
return response == kOBEXResponseCodeSuccessWithFinalBit;
} else {
- qCWarning(QT_BT_OSX) << "check_connect_event, unexpected event type";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "unexpected event type";
error = kOBEXGeneralError;
return false;
}
@@ -372,7 +368,7 @@ bool check_connect_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode
bool check_put_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode &response)
{
- Q_ASSERT_X(e, "check_put_event", "invalid event (null)");
+ Q_ASSERT_X(e, Q_FUNC_INFO, "invalid event (null)");
// See the comments above.
@@ -384,7 +380,7 @@ bool check_put_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode &re
return response == kOBEXResponseCodeContinueWithFinalBit ||
response == kOBEXResponseCodeSuccessWithFinalBit;
} else {
- qCWarning(QT_BT_OSX) << "check_put_event, unexpected event type";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "unexpected event type";
error = kOBEXGeneralError;
return false;
}
@@ -392,7 +388,7 @@ bool check_put_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode &re
bool check_abort_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode &response)
{
- Q_ASSERT_X(e, "check_abort_event", "invalid event (null)");
+ Q_ASSERT_X(e, Q_FUNC_INFO, "invalid event (null)");
if (e->type == kOBEXSessionEventTypeError) {
error = e->u.errorData.error;
@@ -401,7 +397,7 @@ bool check_abort_event(const OBEXSessionEvent *e, OBEXError &error, OBEXOpCode &
response = e->u.abortCommandResponseData.serverResponseOpCode;
return response == kOBEXResponseCodeSuccessWithFinalBit;
} else {
- qCWarning(QT_BT_OSX) << "check_abort_event, unexpected event type";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "unexpected event type";
return false;
}
}
@@ -440,12 +436,9 @@ using namespace QT_NAMESPACE;
- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth::OBEXSessionDelegate) *)aDelegate
remoteDevice:(const QBluetoothAddress &)deviceAddress channelID:(quint16)port
{
- Q_ASSERT_X(aDelegate, "-initWithDelegate:remoteDevice:channelID:",
- "invalid delegate (null)");
- Q_ASSERT_X(!deviceAddress.isNull(), "-initWithDelegate:remoteDevice:channelID:",
- "invalid remote device address");
- Q_ASSERT_X(port, "-initWithDelegate:remoteDevice:channelID:",
- "invalid port (0)");
+ Q_ASSERT_X(aDelegate, Q_FUNC_INFO, "invalid delegate (null)");
+ Q_ASSERT_X(!deviceAddress.isNull(), Q_FUNC_INFO, "invalid remote device address");
+ Q_ASSERT_X(port, Q_FUNC_INFO, "invalid port (0)");
if (self = [super init]) {
connected = false;
@@ -456,15 +449,13 @@ using namespace QT_NAMESPACE;
const BluetoothDeviceAddress addr(OSXBluetooth::iobluetooth_address(deviceAddress));
device = [[IOBluetoothDevice deviceWithAddress:&addr] retain];
if (!device) {
- qCWarning(QT_BT_OSX) << "-initWithDelegate:remoteDevice:channelID:, "
- "failed to create an IOBluetoothDevice";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to create an IOBluetoothDevice";
return self;
}
session = [[IOBluetoothOBEXSession alloc] initWithDevice:device channelID:port];
if (!session) {
- qCWarning(QT_BT_OSX) << "-initWithDelegate:remoteDevice:channelID:, "
- "failed to create an OBEX session";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to create an OBEX session";
return self;
}
@@ -489,12 +480,12 @@ using namespace QT_NAMESPACE;
- (OBEXError)OBEXConnect
{
if (!session) {
- qCWarning(QT_BT_OSX) << "-OBEXConnect, invalid session (nil)";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid session (nil)";
return kOBEXGeneralError;
}
// That's a "single-shot" operation:
- Q_ASSERT_X(currentRequest == OSXBluetooth::OBEXNoop, "-connect",
+ Q_ASSERT_X(currentRequest == OSXBluetooth::OBEXNoop, Q_FUNC_INFO,
"can not connect in this state (another request is active)");
connected = false;
@@ -523,7 +514,7 @@ using namespace QT_NAMESPACE;
{
using namespace OSXBluetooth;
- Q_ASSERT_X(session, "-OBEXConnectHandler:", "invalid session (nil)");
+ Q_ASSERT_X(session, Q_FUNC_INFO, "invalid session (nil)");
if (pendingAbort) {
currentRequest = OBEXNoop;
@@ -532,7 +523,7 @@ using namespace QT_NAMESPACE;
}
if (currentRequest != OBEXConnect) {
- qCWarning(QT_BT_OSX) << "-OBEXConnectHandler:, called while there is no"
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "called while there is no "
"active connect request";
return;
}
@@ -578,7 +569,7 @@ using namespace QT_NAMESPACE;
{
using namespace OSXBluetooth;
- Q_ASSERT_X(session, "-OBEXAbort", "invalid OBEX session (nil)");
+ Q_ASSERT_X(session, Q_FUNC_INFO, "invalid OBEX session (nil)");
if (currentRequest == OBEXNoop) {
pendingAbort = false;
@@ -608,10 +599,10 @@ using namespace QT_NAMESPACE;
{
using namespace OSXBluetooth;
- Q_ASSERT_X(session, "-OBEXAbortHandler:", "invalid OBEX session (nil)");
+ Q_ASSERT_X(session, Q_FUNC_INFO, "invalid OBEX session (nil)");
if (currentRequest != OBEXAbort) {
- qCWarning(QT_BT_OSX) << "-OBEXAbortHandler:, called while there "
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "called while there "
"is no ABORT request";
return;
}
@@ -634,23 +625,22 @@ using namespace QT_NAMESPACE;
if (!session || ![self isConnected])
return kOBEXSessionNotConnectedError;
- Q_ASSERT_X(currentRequest == OBEXNoop, "-OBEXPutFile:withName:",
+ Q_ASSERT_X(currentRequest == OBEXNoop, Q_FUNC_INFO,
"the current session has an active request already");
- Q_ASSERT_X(input, "-OBEXPutFile:withName:", "invalid input stream (null)");
- Q_ASSERT_X(input->isReadable(), "-OBEXPutFile:withName:",
- "invalid input stream (not readable)");
+ Q_ASSERT_X(input, Q_FUNC_INFO, "invalid input stream (null)");
+ Q_ASSERT_X(input->isReadable(), Q_FUNC_INFO, "invalid input stream (not readable)");
// We send a put request with a couple of headers (size/file name/may be connection ID) +
// a payload.
const qint64 fileSize = input->size();
if (fileSize <= 0 || fileSize >= std::numeric_limits<uint32_t>::max()) {
- qCWarning(QT_BT_OSX) << "-OBEXPutFile:withName:, invalid input file size";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid input file size";
return kOBEXBadArgumentError;
}
ObjCStrongReference<NSMutableData> headers([[NSMutableData alloc] init], false);
if (!headers) {
- qCWarning(QT_BT_OSX) << "-OBEXPutFile:withName:, failed to allocate headers";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to allocate headers";
return kOBEXNoResourcesError;
}
@@ -660,16 +650,16 @@ using namespace QT_NAMESPACE;
if (connectionIDFound) {
if (!append_four_byte_header(headers, kOBEXHeaderIDConnectionID, connectionID)) {
- qCWarning(QT_BT_OSX) << "-OBEXPutFile:withName:, "
- "failed to append connection ID header";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to "
+ "append connection ID header";
return kOBEXNoResourcesError;
}
}
if (name.length()) {
if (!append_unicode_header(headers, kOBEXHeaderIDName, name)) {
- qCWarning(QT_BT_OSX) << "-OBEXPutFile:withName:, "
- "failed to append a unicode string";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to append "
+ "a unicode string";
return kOBEXNoResourcesError;
}
}
@@ -682,7 +672,7 @@ using namespace QT_NAMESPACE;
if (!chunk || ![chunk length]) {
// We do not support PUT-DELETE (?)
// At least the first chunk is expected to be non-empty.
- qCWarning(QT_BT_OSX) << "-OBEXPutFile:withName:, invalid input stream";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid input stream";
return kOBEXBadArgumentError;
}
@@ -720,7 +710,7 @@ using namespace QT_NAMESPACE;
{
using namespace OSXBluetooth;
- Q_ASSERT_X(session, "-OBEXPutHandler:", "invalid OBEX session (nil)");
+ Q_ASSERT_X(session, Q_FUNC_INFO, "invalid OBEX session (nil)");
if (pendingAbort) {
currentRequest = OBEXNoop;
@@ -729,7 +719,7 @@ using namespace QT_NAMESPACE;
}
if (currentRequest != OBEXPut) {
- qCWarning(QT_BT_OSX) << "-OBEXPutHandler:, called while the current "
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "called while the current "
"request is not a put request";
return;
}
@@ -751,7 +741,7 @@ using namespace QT_NAMESPACE;
// 0 for the headers length, no more headers.
ObjCStrongReference<NSMutableData> chunk(next_data_chunk(*inputStream, session, 0, lastChunk));
if (!chunk && !lastChunk) {
- qCWarning(QT_BT_OSX) << "-OBEXPutHandler:, failed to "
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to "
"allocate the next memory chunk";
return;
}
@@ -768,7 +758,7 @@ using namespace QT_NAMESPACE;
refCon:Q_NULLPTR];
if (status != kOBEXSuccess) {
- qCWarning(QT_BT_OSX) << "-OBEXPutHandler:, failed to "
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to "
"send the next memory chunk";
currentRequest = OBEXNoop;
if (delegate) // Response code is not important here.
@@ -794,7 +784,7 @@ using namespace QT_NAMESPACE;
- (void)OBEXDisconnect
{
- Q_ASSERT_X(session, "-OBEXDisconnect", "invalid session (nil)");
+ Q_ASSERT_X(session, Q_FUNC_INFO, "invalid session (nil)");
currentRequest = OSXBluetooth::OBEXDisconnect;
@@ -809,7 +799,7 @@ using namespace QT_NAMESPACE;
{
Q_UNUSED(event)
- Q_ASSERT_X(session, "-OBEXDisconnectHandler:", "invalid session (nil)");
+ Q_ASSERT_X(session, Q_FUNC_INFO, "invalid session (nil)");
// Event can have an error type, but there's nothing
// we can do - even "cleanup" failed.
diff --git a/src/bluetooth/osx/osxbtobexsession_p.h b/src/bluetooth/osx/osxbtobexsession_p.h
index aa142b5a..9449ebf0 100644
--- a/src/bluetooth/osx/osxbtobexsession_p.h
+++ b/src/bluetooth/osx/osxbtobexsession_p.h
@@ -43,9 +43,8 @@
#include <QtCore/qglobal.h>
#include <Foundation/Foundation.h>
-
-// Import - Obj-C headers do not have inclusion guards:
-#import <IOBluetooth/objc/OBEXSession.h>
+// Only after Foundation.h:
+#include "corebluetoothwrapper_p.h"
@class IOBluetoothOBEXSession;
@class IOBluetoothDevice;
@@ -97,7 +96,7 @@ QT_END_NAMESPACE
// It either succeeds or fails and tries to cleanup in any case.
@interface QT_MANGLE_NAMESPACE(OSXBTOBEXSession) : NSObject
{
- QT_PREPEND_NAMESPACE(OSXBluetooth::OBEXSessionDelegate) *delegate;
+ QT_PREPEND_NAMESPACE(OSXBluetooth)::OBEXSessionDelegate *delegate;
IOBluetoothDevice *device;
quint16 channelID;
IOBluetoothOBEXSession *session;
diff --git a/src/bluetooth/osx/osxbtrfcommchannel.mm b/src/bluetooth/osx/osxbtrfcommchannel.mm
index 996b4ebf..df1fd433 100644
--- a/src/bluetooth/osx/osxbtrfcommchannel.mm
+++ b/src/bluetooth/osx/osxbtrfcommchannel.mm
@@ -44,10 +44,6 @@
#include "qbluetoothaddress.h"
#include "osxbtutility_p.h"
-// Import, it's Obj-C header.
-#import <IOBluetooth/objc/IOBluetoothDevice.h>
-
-
#ifdef QT_NAMESPACE
using namespace QT_NAMESPACE;
#endif
@@ -56,7 +52,7 @@ using namespace QT_NAMESPACE;
- (id)initWithDelegate:(OSXBluetooth::ChannelDelegate *)aDelegate
{
- Q_ASSERT_X(aDelegate, "-initWithDelegate:", "invalid delegate (null)");
+ Q_ASSERT_X(aDelegate, Q_FUNC_INFO, "invalid delegate (null)");
if (self = [super init]) {
delegate = aDelegate;
@@ -73,8 +69,8 @@ using namespace QT_NAMESPACE;
{
// This type of channel does not require connect, it's created with
// already open channel.
- Q_ASSERT_X(aDelegate, "-initWithDelegate:channel:", "invalid delegate (null)");
- Q_ASSERT_X(aChannel, "-initWithDelegate:channel:", "invalid channel (nil)");
+ Q_ASSERT_X(aDelegate, Q_FUNC_INFO, "invalid delegate (null)");
+ Q_ASSERT_X(aChannel, Q_FUNC_INFO, "invalid channel (nil)");
if (self = [super init]) {
delegate = aDelegate;
@@ -105,15 +101,13 @@ using namespace QT_NAMESPACE;
withChannelID:(BluetoothRFCOMMChannelID)channelID
{
if (address.isNull()) {
- qCCritical(QT_BT_OSX) << "-connectAsyncToDevice:withChannelID:, "
- "invalid peer address";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "invalid peer address";
return kIOReturnNoDevice;
}
// Can never be called twice.
if (connected || device || channel) {
- qCCritical(QT_BT_OSX) << "-connectAsyncToDevice:withChannelID:, "
- "connection is already active";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "connection is already active";
return kIOReturnStillOpen;
}
@@ -122,16 +116,14 @@ using namespace QT_NAMESPACE;
const BluetoothDeviceAddress iobtAddress = OSXBluetooth::iobluetooth_address(address);
device = [IOBluetoothDevice deviceWithAddress:&iobtAddress];
if (!device) { // TODO: do I always check this BTW??? Apple's docs say nothing about nil.
- qCCritical(QT_BT_OSX) << "-connectAsyncToDevice:withChannelID:, "
- "failed to create a device";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to create a device";
return kIOReturnNoDevice;
}
const IOReturn status = [device openRFCOMMChannelAsync:&channel
withChannelID:channelID delegate:self];
if (status != kIOReturnSuccess) {
- qCCritical(QT_BT_OSX) << "-connectAsyncToDevice:withChannelID:, "
- "failed to open L2CAP channel";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to open L2CAP channel";
// device is still autoreleased.
device = nil;
return status;
@@ -148,8 +140,7 @@ using namespace QT_NAMESPACE;
{
Q_UNUSED(rfcommChannel)
- Q_ASSERT_X(delegate, "-rfcommChannelData:data:length:",
- "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
// Not sure if it can ever happen and if
// assert is better.
@@ -164,8 +155,7 @@ using namespace QT_NAMESPACE;
{
Q_UNUSED(rfcommChannel)
- Q_ASSERT_X(delegate, "-rfcommChannelOpenComplete:status:",
- "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
if (error != kIOReturnSuccess) {
delegate->setChannelError(error);
@@ -179,7 +169,7 @@ using namespace QT_NAMESPACE;
{
Q_UNUSED(rfcommChannel)
- Q_ASSERT_X(delegate, "rfcommChannelClosed:", "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
delegate->channelClosed();
connected = false;
}
@@ -200,8 +190,7 @@ using namespace QT_NAMESPACE;
Q_UNUSED(rfcommChannel)
Q_UNUSED(refcon)
- Q_ASSERT_X(delegate, "-rfcommChannelWriteComplete:refcon:status:",
- "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
if (error != kIOReturnSuccess)
delegate->setChannelError(error);
@@ -250,20 +239,18 @@ using namespace QT_NAMESPACE;
- (IOReturn) writeSync:(void*)data length:(UInt16)length
{
- Q_ASSERT_X(data, "-writeSync:length:", "invalid data (null)");
- Q_ASSERT_X(length, "-writeSync:length:", "invalid data size");
- Q_ASSERT_X(connected && channel, "-writeSync:",
- "invalid RFCOMM channel");
+ Q_ASSERT_X(data, Q_FUNC_INFO, "invalid data (null)");
+ Q_ASSERT_X(length, Q_FUNC_INFO, "invalid data size");
+ Q_ASSERT_X(connected && channel, Q_FUNC_INFO, "invalid RFCOMM channel");
return [channel writeSync:data length:length];
}
- (IOReturn) writeAsync:(void*)data length:(UInt16)length
{
- Q_ASSERT_X(data, "-writeAsync:length:", "invalid data (null)");
- Q_ASSERT_X(length, "-writeAync:length:", "invalid data size");
- Q_ASSERT_X(connected && channel, "-writeAsync:length:",
- "invalid RFCOMM channel");
+ Q_ASSERT_X(data, Q_FUNC_INFO, "invalid data (null)");
+ Q_ASSERT_X(length, Q_FUNC_INFO, "invalid data size");
+ Q_ASSERT_X(connected && channel, Q_FUNC_INFO, "invalid RFCOMM channel");
return [channel writeAsync:data length:length refcon:Q_NULLPTR];
}
diff --git a/src/bluetooth/osx/osxbtrfcommchannel_p.h b/src/bluetooth/osx/osxbtrfcommchannel_p.h
index 869c9fb3..21c1711c 100644
--- a/src/bluetooth/osx/osxbtrfcommchannel_p.h
+++ b/src/bluetooth/osx/osxbtrfcommchannel_p.h
@@ -44,10 +44,9 @@
#include <QtCore/qglobal.h>
-// Has to be imported, Obj-C header, no inclusion guards.
-#import <IOBluetooth/objc/IOBluetoothRFCOMMChannel.h>
-
#include <Foundation/Foundation.h>
+// Only after Foundation.h:
+#include "corebluetoothwrapper_p.h"
@class QT_MANGLE_NAMESPACE(OSXBTRFCOMMChannel);
@class IOBluetoothDevice;
@@ -66,20 +65,20 @@ QT_END_NAMESPACE
@interface QT_MANGLE_NAMESPACE(OSXBTRFCOMMChannel) : NSObject<IOBluetoothRFCOMMChannelDelegate>
{
- QT_PREPEND_NAMESPACE(OSXBluetooth::ChannelDelegate) *delegate;
+ QT_PREPEND_NAMESPACE(OSXBluetooth)::ChannelDelegate *delegate;
IOBluetoothDevice *device;
IOBluetoothRFCOMMChannel *channel;
bool connected;
}
-- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth::ChannelDelegate) *)aDelegate;
-- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth::ChannelDelegate) *)aDelegate
+- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth)::ChannelDelegate *)aDelegate;
+- (id)initWithDelegate:(QT_PREPEND_NAMESPACE(OSXBluetooth)::ChannelDelegate *)aDelegate
channel:(IOBluetoothRFCOMMChannel *)aChannel;
- (void)dealloc;
// A single async connection (can connect only once).
-- (IOReturn)connectAsyncToDevice:(const QBluetoothAddress &)address
+- (IOReturn)connectAsyncToDevice:(const QT_PREPEND_NAMESPACE(QBluetoothAddress) &)address
withChannelID:(BluetoothRFCOMMChannelID)channelID;
- (void)rfcommChannelData:(IOBluetoothRFCOMMChannel*)rfcommChannel
diff --git a/src/bluetooth/osx/osxbtsdpinquiry.mm b/src/bluetooth/osx/osxbtsdpinquiry.mm
index 9cafd572..b460f929 100644
--- a/src/bluetooth/osx/osxbtsdpinquiry.mm
+++ b/src/bluetooth/osx/osxbtsdpinquiry.mm
@@ -48,11 +48,7 @@
#include <QtCore/qvariant.h>
#include <QtCore/qstring.h>
-// We have to import - objc header files, no inclusion guards.
-#import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h>
-#import <IOBluetooth/objc/IOBluetoothSDPDataElement.h>
-#import <IOBluetooth/objc/IOBluetoothSDPUUID.h>
-#import <IOBluetooth/objc/IOBluetoothDevice.h>
+#include "corebluetoothwrapper_p.h"
QT_BEGIN_NAMESPACE
@@ -64,7 +60,7 @@ SDPInquiryDelegate::~SDPInquiryDelegate()
QVariant extract_attribute_value(IOBluetoothSDPDataElement *dataElement)
{
- Q_ASSERT_X(dataElement, "extractAttributeValue()", "invalid data element (nil)");
+ Q_ASSERT_X(dataElement, Q_FUNC_INFO, "invalid data element (nil)");
// TODO: error handling and diagnostic messages.
@@ -158,7 +154,7 @@ using namespace OSXBluetooth;
- (id)initWithDelegate:(SDPInquiryDelegate *)aDelegate
{
- Q_ASSERT_X(aDelegate, "-initWithDelegate:", "invalid delegate (null)");
+ Q_ASSERT_X(aDelegate, Q_FUNC_INFO, "invalid delegate (null)");
if (self = [super init]) {
delegate = aDelegate;
@@ -177,8 +173,7 @@ using namespace OSXBluetooth;
- (IOReturn)performSDPQueryWithDevice:(const QBluetoothAddress &)address
{
- Q_ASSERT_X(!isActive, "-performSDPQueryWithDevice",
- "SDP query in process");
+ Q_ASSERT_X(!isActive, Q_FUNC_INFO, "SDP query in progress");
QList<QBluetoothUuid> emptyFilter;
return [self performSDPQueryWithDevice:address filters:emptyFilter];
@@ -187,10 +182,8 @@ using namespace OSXBluetooth;
- (IOReturn)performSDPQueryWithDevice:(const QBluetoothAddress &)address
filters:(const QList<QBluetoothUuid> &)qtFilters
{
- Q_ASSERT_X(!isActive, "-performSDPQueryWithDevice:filters:",
- "SDP query in progress");
- Q_ASSERT_X(!address.isNull(), "-performSDPQueryWithDevice:filters:",
- "invalid target device address");
+ Q_ASSERT_X(!isActive, Q_FUNC_INFO, "SDP query in progress");
+ Q_ASSERT_X(!address.isNull(), Q_FUNC_INFO, "invalid target device address");
QT_BT_MAC_AUTORELEASEPOOL;
@@ -199,8 +192,7 @@ using namespace OSXBluetooth;
if (qtFilters.size()) {
array.reset([[NSMutableArray alloc] init]);
if (!array) {
- qCCritical(QT_BT_OSX) << "-performSDPQueryWithDevices:filters:, "
- "failed to allocate an uuid filter";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to allocate an uuid filter";
return kIOReturnError;
}
@@ -211,8 +203,7 @@ using namespace OSXBluetooth;
}
if (int([array count]) != qtFilters.size()) {
- qCCritical(QT_BT_OSX) << "-performSDPQueryWithDevices:filters:, "
- << "failed to create an uuid filter";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to create an uuid filter";
return kIOReturnError;
}
}
@@ -220,8 +211,7 @@ using namespace OSXBluetooth;
const BluetoothDeviceAddress iobtAddress(iobluetooth_address(address));
ObjCScopedPointer<IOBluetoothDevice> newDevice([[IOBluetoothDevice deviceWithAddress:&iobtAddress] retain]);
if (!newDevice) {
- qCCritical(QT_BT_OSX) << "-performSDPQueryWithDevices:filters:, "
- << "failed to create an IOBluetoothDevice object";
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to create an IOBluetoothDevice object";
return kIOReturnError;
}
@@ -235,9 +225,7 @@ using namespace OSXBluetooth;
result = [device performSDPQuery:self];
if (result != kIOReturnSuccess) {
- qCCritical(QT_BT_OSX) << "-preformSDPQueryWithDevices:filters:, "
- "failed to start an SDP query";
-
+ qCCritical(QT_BT_OSX) << Q_FUNC_INFO << "failed to start an SDP query";
device = oldDevice.take();
} else {
isActive = true;
@@ -265,8 +253,7 @@ using namespace OSXBluetooth;
if (device != aDevice)
return;
- Q_ASSERT_X(delegate, "-sdpQueryComplete:status:",
- "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
isActive = false;
diff --git a/src/bluetooth/osx/osxbtservicerecord.mm b/src/bluetooth/osx/osxbtservicerecord.mm
index 84e60f75..a0930ae9 100644
--- a/src/bluetooth/osx/osxbtservicerecord.mm
+++ b/src/bluetooth/osx/osxbtservicerecord.mm
@@ -47,10 +47,7 @@
#include <QtCore/qmap.h>
#include <QtCore/qurl.h>
-#include <IOBluetooth/BluetoothAssignedNumbers.h>
-
-// Import, since it's Objective-C header (no inclusion guards).
-#import <IOBluetooth/objc/IOBluetoothSDPUUID.h>
+#include "corebluetoothwrapper_p.h"
QT_BEGIN_NAMESPACE
@@ -146,7 +143,7 @@ Number variant_to_nsnumber<int>(const QVariant &var)
template<class ValueType>
void add_attribute(const QVariant &var, AttributeId key, Dictionary dict)
{
- Q_ASSERT_X(dict, "add_attribute", "invalid dictionary (nil)");
+ Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dictionary (nil)");
if (!var.canConvert<ValueType>())
return;
@@ -158,7 +155,7 @@ void add_attribute(const QVariant &var, AttributeId key, Dictionary dict)
template<>
void add_attribute<QString>(const QVariant &var, AttributeId key, Dictionary dict)
{
- Q_ASSERT_X(dict, "add_attribute", "invalid dictionary (nil)");
+ Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dictionary (nil)");
if (!var.canConvert<QString>())
return;
@@ -173,7 +170,7 @@ void add_attribute<QString>(const QVariant &var, AttributeId key, Dictionary dic
template<>
void add_attribute<QBluetoothUuid>(const QVariant &var, AttributeId key, Dictionary dict)
{
- Q_ASSERT_X(dict, "add_attribute", "invalid dictionary (nil)");
+ Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dictionary (nil)");
if (!var.canConvert<QBluetoothUuid>())
return;
@@ -185,7 +182,7 @@ void add_attribute<QBluetoothUuid>(const QVariant &var, AttributeId key, Diction
template<>
void add_attribute<QUrl>(const QVariant &var, AttributeId key, Dictionary dict)
{
- Q_ASSERT_X(dict, "add_attribute", "invalid dictionary (nil)");
+ Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dictionary (nil)");
if (!var.canConvert<QUrl>())
return;
@@ -203,7 +200,7 @@ void add_attribute(const QVariant &var, NSMutableArray *list);
template<class ValueType>
void add_attribute(const QVariant &var, NSMutableArray *list)
{
- Q_ASSERT_X(list, "add_attribute", "invalid list (nil)");
+ Q_ASSERT_X(list, Q_FUNC_INFO, "invalid list (nil)");
if (!var.canConvert<ValueType>())
return;
@@ -215,7 +212,7 @@ void add_attribute(const QVariant &var, NSMutableArray *list)
template<>
void add_attribute<QString>(const QVariant &var, NSMutableArray *list)
{
- Q_ASSERT_X(list, "add_attribute", "invalid list (nil)");
+ Q_ASSERT_X(list, Q_FUNC_INFO, "invalid list (nil)");
if (!var.canConvert<QString>())
return;
@@ -230,7 +227,7 @@ void add_attribute<QString>(const QVariant &var, NSMutableArray *list)
template<>
void add_attribute<QBluetoothUuid>(const QVariant &var, NSMutableArray *list)
{
- Q_ASSERT_X(list, "add_attribute", "invalid list (nil)");
+ Q_ASSERT_X(list, Q_FUNC_INFO, "invalid list (nil)");
if (!var.canConvert<QBluetoothUuid>())
return;
@@ -242,7 +239,7 @@ void add_attribute<QBluetoothUuid>(const QVariant &var, NSMutableArray *list)
template<>
void add_attribute<QUrl>(const QVariant &var, NSMutableArray *list)
{
- Q_ASSERT_X(list, "add_attribute", "invalid list (nil)");
+ Q_ASSERT_X(list, Q_FUNC_INFO, "invalid list (nil)");
if (!var.canConvert<QUrl>())
return;
@@ -254,13 +251,10 @@ void add_attribute<QUrl>(const QVariant &var, NSMutableArray *list)
void add_rfcomm_protocol_descriptor_list(uint16 channelID, Dictionary dict)
{
- Q_ASSERT_X(dict, "add_rfcomm_protocol_descriptor_list",
- "invalid dictionary (nil)");
+ Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dictionary (nil)");
QT_BT_MAC_AUTORELEASEPOOL;
- // TODO: error handling?
-
// Objective-C has literals (for arrays and dictionaries), but it will not compile
// on 10.7 or below, so quite a lot of code here.
@@ -288,13 +282,10 @@ void add_rfcomm_protocol_descriptor_list(uint16 channelID, Dictionary dict)
void add_l2cap_protocol_descriptor_list(uint16 psm, Dictionary dict)
{
- Q_ASSERT_X(dict, "add_l2cap_protocol_descriptor_list",
- "invalid dictionary (nil)");
+ Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dictionary (nil)");
QT_BT_MAC_AUTORELEASEPOOL;
- // TODO: error handling?
-
// Objective-C has literals (for arrays and dictionaries), but it will not compile
// on 10.7 or below, so quite a lot of code here.
@@ -317,10 +308,7 @@ void add_l2cap_protocol_descriptor_list(uint16 psm, Dictionary dict)
bool add_attribute(const QVariant &var, AttributeId key, NSMutableArray *list)
{
- Q_ASSERT_X(list, "add_attribute", "invalid list (nil)");
-
- // TODO: test if it works at all - add an attribute
- // (some NSObject) into the sequence.
+ Q_ASSERT_X(list, Q_FUNC_INFO, "invalid list (nil)");
if (var.canConvert<Sequence>())
return false;
@@ -333,7 +321,7 @@ bool add_attribute(const QVariant &var, AttributeId key, NSMutableArray *list)
} else {
// Here we need 'key' to understand the type.
// We can have different integer types actually, so I have to check
- // the 'key' to be sure conversion is reasonable.
+ // the 'key' to be sure the conversion is reasonable.
switch (key) {
case QSInfo::ServiceRecordHandle:
case QSInfo::ServiceRecordState:
@@ -357,7 +345,7 @@ bool add_attribute(const QVariant &var, AttributeId key, NSMutableArray *list)
bool add_attribute(const QBluetoothServiceInfo &serviceInfo, AttributeId key, Dictionary dict)
{
- Q_ASSERT_X(dict, "add_attribute", "invalid dict (nil)");
+ Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dict (nil)");
const QVariant var(serviceInfo.attribute(key));
if (var.canConvert<Sequence>())
@@ -370,7 +358,7 @@ bool add_attribute(const QBluetoothServiceInfo &serviceInfo, AttributeId key, Di
add_attribute<QBluetoothUuid>(serviceInfo.attribute(key), key, dict);
} else {
// We can have different integer types actually, so I have to check
- // the 'key' to be sure conversion is reasonable.
+ // the 'key' to be sure the conversion is reasonable.
switch (key) {
case QSInfo::ServiceRecordHandle:
case QSInfo::ServiceRecordState:
@@ -395,7 +383,7 @@ bool add_attribute(const QBluetoothServiceInfo &serviceInfo, AttributeId key, Di
bool add_sequence_attribute(const QVariant &var, AttributeId key, NSMutableArray *list)
{
// Add a "nested" sequence.
- Q_ASSERT_X(list, "add_sequence_attribute", "invalid list (nil)");
+ Q_ASSERT_X(list, Q_FUNC_INFO, "invalid list (nil)");
if (var.isNull() || !var.canConvert<Sequence>())
return false;
@@ -416,7 +404,7 @@ bool add_sequence_attribute(const QVariant &var, AttributeId key, NSMutableArray
bool add_sequence_attribute(const QBluetoothServiceInfo &serviceInfo, AttributeId key, Dictionary dict)
{
- Q_ASSERT_X(dict, "add_sequence_attribute", "invalid dictionary (nil)");
+ Q_ASSERT_X(dict, Q_FUNC_INFO, "invalid dictionary (nil)");
const QVariant &var(serviceInfo.attribute(key));
if (var.isNull() || !var.canConvert<Sequence>())
@@ -451,8 +439,6 @@ Dictionary iobluetooth_service_dictionary(const QBluetoothServiceInfo &serviceIn
foreach (quint16 key, attributeIds) {
if (key == QSInfo::ProtocolDescriptorList) // We handle it in a special way.
continue;
- //if (key == QSInfo::BluetoothProfileDescriptorList)
- // continue;
// TODO: check if non-sequence QVariant still must be
// converted into NSArray for some attribute ID.
if (!add_sequence_attribute(serviceInfo, AttributeId(key), dict))
@@ -466,8 +452,6 @@ Dictionary iobluetooth_service_dictionary(const QBluetoothServiceInfo &serviceIn
add_rfcomm_protocol_descriptor_list(serviceInfo.serverChannel(), dict);
}
- // BluetoothProfileDescriptorList.
-
return dict;
}
diff --git a/src/bluetooth/osx/osxbtsocketlistener.mm b/src/bluetooth/osx/osxbtsocketlistener.mm
index 125f910a..ab7affbe 100644
--- a/src/bluetooth/osx/osxbtsocketlistener.mm
+++ b/src/bluetooth/osx/osxbtsocketlistener.mm
@@ -34,13 +34,9 @@
#include "osxbtsocketlistener_p.h"
#include "osxbtutility_p.h"
-#include <QtCore/qloggingcategory.h>
#include <QtCore/qdebug.h>
-// Imports, since these are Objective-C headers and
-// they do not have inclusion guards.
-#import <IOBluetooth/objc/IOBluetoothRFCOMMChannel.h>
-#import <IOBluetooth/objc/IOBluetoothL2CAPChannel.h>
+#include "corebluetoothwrapper_p.h"
QT_BEGIN_NAMESPACE
@@ -64,7 +60,7 @@ using namespace QT_NAMESPACE;
- (id)initWithListener:(OSXBluetooth::SocketListener *)aDelegate
{
- Q_ASSERT_X(aDelegate, "-initWithListener:", "invalid delegate (null)");
+ Q_ASSERT_X(aDelegate, Q_FUNC_INFO, "invalid delegate (null)");
if (self = [super init]) {
connectionNotification = nil;
delegate = aDelegate;
@@ -84,8 +80,7 @@ using namespace QT_NAMESPACE;
- (bool)listenRFCOMMConnectionsWithChannelID:(BluetoothRFCOMMChannelID)channelID
{
- Q_ASSERT_X(!connectionNotification, "-listenRFCOMMConnectionsWithChannelID",
- "already listening");
+ Q_ASSERT_X(!connectionNotification, Q_FUNC_INFO, "already listening");
connectionNotification = [IOBluetoothRFCOMMChannel registerForChannelOpenNotifications:self
selector:@selector(rfcommOpenNotification:channel:)
@@ -100,8 +95,7 @@ using namespace QT_NAMESPACE;
- (bool)listenL2CAPConnectionsWithPSM:(BluetoothL2CAPPSM)psm
{
- Q_ASSERT_X(!connectionNotification, "-listenL2CAPConnectionsWithPSM:",
- "already listening");
+ Q_ASSERT_X(!connectionNotification, Q_FUNC_INFO, "already listening");
connectionNotification = [IOBluetoothL2CAPChannel registerForChannelOpenNotifications:self
selector:@selector(l2capOpenNotification:channel:)
@@ -119,8 +113,7 @@ using namespace QT_NAMESPACE;
{
Q_UNUSED(notification)
- Q_ASSERT_X(delegate, "-rfcommOpenNotification:channel:",
- "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
delegate->openNotify(newChannel);
}
@@ -129,8 +122,7 @@ using namespace QT_NAMESPACE;
{
Q_UNUSED(notification)
- Q_ASSERT_X(delegate, "-l2capOpenNotification:channel:",
- "invalid delegate (null)");
+ Q_ASSERT_X(delegate, Q_FUNC_INFO, "invalid delegate (null)");
delegate->openNotify(newChannel);
}
diff --git a/src/bluetooth/osx/osxbtutility.mm b/src/bluetooth/osx/osxbtutility.mm
index 26f33e6e..ae4bae77 100644
--- a/src/bluetooth/osx/osxbtutility.mm
+++ b/src/bluetooth/osx/osxbtutility.mm
@@ -246,6 +246,64 @@ QByteArray qt_bytearray(NSData *data)
return value;
}
+template<class Integer>
+QByteArray qt_bytearray(Integer n)
+{
+ QByteArray value;
+ value.resize(sizeof n);
+ const char *const src = reinterpret_cast<char *>(&n);
+ std::copy(src, src + sizeof n, value.data());
+
+ return value;
+}
+
+QByteArray qt_bytearray(NSString *string)
+{
+ if (!string)
+ return QByteArray();
+
+ QT_BT_MAC_AUTORELEASEPOOL;
+ NSData *const utf8Data = [string dataUsingEncoding:NSUTF8StringEncoding];
+
+ return qt_bytearray(utf8Data);
+}
+
+QByteArray qt_bytearray(NSObject *obj)
+{
+ // descriptor.value has type 'id'.
+ // While the Apple's docs say this about descriptors:
+ //
+ // - CBUUIDCharacteristicExtendedPropertiesString
+ // The string representation of the UUID for the extended properties descriptor.
+ // The corresponding value for this descriptor is an NSNumber object.
+ //
+ // - CBUUIDCharacteristicUserDescriptionString
+ // The string representation of the UUID for the user description descriptor.
+ // The corresponding value for this descriptor is an NSString object.
+ //
+ // ... etc.
+ //
+ // This is not true. On OS X, they all seem to be NSData (or derived from NSData),
+ // and they can be something else on iOS (NSNumber, NSString, etc.)
+ if (!obj)
+ return QByteArray();
+
+ QT_BT_MAC_AUTORELEASEPOOL;
+
+ if ([obj isKindOfClass:[NSData class]]) {
+ return qt_bytearray(static_cast<NSData *>(obj));
+ } else if ([obj isKindOfClass:[NSString class]]) {
+ return qt_bytearray(static_cast<NSString *>(obj));
+ } else if ([obj isKindOfClass:[NSNumber class]]) {
+ NSNumber *const nsNumber = static_cast<NSNumber *>(obj);
+ return qt_bytearray([nsNumber unsignedShortValue]);
+ }
+ // TODO: Where can be more types, but Core Bluetooth does not support them,
+ // or at least it's not documented.
+
+ return QByteArray();
+}
+
ObjCStrongReference<NSData> data_from_bytearray(const QByteArray & qtData)
{
if (!qtData.size())
diff --git a/src/bluetooth/osx/osxbtutility_p.h b/src/bluetooth/osx/osxbtutility_p.h
index d30ee93c..cc80d25a 100644
--- a/src/bluetooth/osx/osxbtutility_p.h
+++ b/src/bluetooth/osx/osxbtutility_p.h
@@ -288,6 +288,7 @@ ObjCStrongReference<CBUUID> cb_uuid(const QBluetoothUuid &qtUuid);
bool equal_uuids(const QBluetoothUuid &qtUuid, CBUUID *cbUuid);
bool equal_uuids(CBUUID *cbUuid, const QBluetoothUuid &qtUuid);
QByteArray qt_bytearray(NSData *data);
+QByteArray qt_bytearray(NSObject *data);
ObjCStrongReference<NSData> data_from_bytearray(const QByteArray & qtData);
} // namespace OSXBluetooth
diff --git a/src/bluetooth/qbluetoothaddress.cpp b/src/bluetooth/qbluetoothaddress.cpp
index 53ac7881..481bcc0d 100644
--- a/src/bluetooth/qbluetoothaddress.cpp
+++ b/src/bluetooth/qbluetoothaddress.cpp
@@ -65,7 +65,7 @@ class BluetoothAddressRegisterMetaTypes
public:
BluetoothAddressRegisterMetaTypes()
{
- qRegisterMetaType<QBluetoothAddress>("QBluetoothAddress");
+ qRegisterMetaType<QBluetoothAddress>();
}
} _registerBluetoothAddressMetaTypes;
}
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
index 93b7c7d4..d2fba203 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
@@ -126,7 +126,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start()
if (!receiver) {
// SDP based device discovery
receiver = new DeviceDiscoveryBroadcastReceiver();
- qRegisterMetaType<QBluetoothDeviceInfo>("QBluetoothDeviceInfo");
+ qRegisterMetaType<QBluetoothDeviceInfo>();
QObject::connect(receiver, SIGNAL(deviceDiscovered(QBluetoothDeviceInfo,bool)),
this, SLOT(processDiscoveredDevices(QBluetoothDeviceInfo,bool)));
QObject::connect(receiver, SIGNAL(finished()), this, SLOT(processSdpDiscoveryFinished()));
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_ios.mm b/src/bluetooth/qbluetoothdevicediscoveryagent_ios.mm
index 20304d99..f1e7945c 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_ios.mm
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_ios.mm
@@ -47,6 +47,7 @@
#include "qbluetoothuuid.h"
#include <QtCore/qloggingcategory.h>
+#include <QtCore/qglobal.h>
#include <QtCore/qstring.h>
#include <QtCore/qdebug.h>
#include <QtCore/qlist.h>
@@ -108,16 +109,14 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(con
{
Q_UNUSED(adapter);
- Q_ASSERT_X(q != Q_NULLPTR, "QBluetoothDeviceDiscoveryAgentPrivate()",
- "invalid q_ptr (null)");
+ Q_ASSERT_X(q != Q_NULLPTR, Q_FUNC_INFO, "invalid q_ptr (null)");
// 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.
LEDeviceInquiry newInquiryLE([[LEDeviceInquiryObjC alloc] initWithDelegate:this]);
if (!newInquiryLE) {
- qCWarning(QT_BT_OSX) << "QBluetoothDeviceDiscoveryAgentPrivate() "
- "failed to initialize a device inquiry object";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to initialize a device inquiry object";
return;
}
@@ -148,10 +147,10 @@ bool QBluetoothDeviceDiscoveryAgentPrivate::isActive() const
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,
- "startLE()", "called with an invalid Bluetooth adapter");
+ Q_FUNC_INFO, "called with an invalid Bluetooth adapter");
if (stopPending) {
startPending = true;
@@ -173,10 +172,10 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start()
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");
startPending = false;
stopPending = true;
@@ -194,7 +193,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::LEdeviceInquiryError(QBluetoothDevic
// 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");
+ Q_FUNC_INFO, "unexpected error");
startPending = false;
stopPending = false;
@@ -214,7 +213,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::LEdeviceFound(CBPeripheral *peripher
NSDictionary *advertisementData,
NSNumber *RSSI)
{
- Q_ASSERT_X(peripheral, "LEdeviceFound", "invalid peripheral (nil)");
+ Q_ASSERT_X(peripheral, Q_FUNC_INFO, "invalid peripheral (nil)");
QT_BT_MAC_AUTORELEASEPOOL;
@@ -252,7 +251,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::LEdeviceFound(CBPeripheral *peripher
void QBluetoothDeviceDiscoveryAgentPrivate::LEdeviceInquiryFinished()
{
- Q_ASSERT_X(isValid(), "LEdeviceInquiryFinished", "invalid device discovery agent");
+ Q_ASSERT_X(isValid(), Q_FUNC_INFO, "invalid device discovery agent");
if (stopPending && !startPending) {
stopPending = false;
@@ -309,8 +308,8 @@ QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(
d_ptr(new QBluetoothDeviceDiscoveryAgentPrivate(deviceAdapter, this))
{
if (!deviceAdapter.isNull()) {
- qCWarning(QT_BT_OSX) << "QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(), "
- "local device address is not available, provided address is ignored";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "local device address is "
+ "not available, provided address is ignored";
d_ptr->setError(InvalidBluetoothAdapterError);
}
}
@@ -339,12 +338,10 @@ void QBluetoothDeviceDiscoveryAgent::start()
{
if (d_ptr->lastError != InvalidBluetoothAdapterError) {
if (d_ptr->isValid()) {
- if (!isActive()) {
+ if (!isActive())
d_ptr->start();
- } else {
- qCDebug(QT_BT_OSX) << "QBluetoothDeviceDiscoveryAgent::start(), "
- "already started";
- }
+ else
+ qCDebug(QT_BT_OSX) << Q_FUNC_INFO << "already started";
} else {
// We previously failed to initialize
// private object correctly.
@@ -357,12 +354,10 @@ void QBluetoothDeviceDiscoveryAgent::start()
void QBluetoothDeviceDiscoveryAgent::stop()
{
if (d_ptr->isValid()) {
- if (isActive() && d_ptr->lastError != InvalidBluetoothAdapterError) {
+ if (isActive() && d_ptr->lastError != InvalidBluetoothAdapterError)
d_ptr->stop();
- } else {
- qCDebug(QT_BT_OSX) << "QBluetoothDeviceDiscoveryAgent::stop(), "
- "failed to stop";
- }
+ else
+ qCDebug(QT_BT_OSX) << Q_FUNC_INFO << "failed to stop";
}
}
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;
}
diff --git a/src/bluetooth/qbluetoothdeviceinfo.h b/src/bluetooth/qbluetoothdeviceinfo.h
index e86ea62e..c9822193 100644
--- a/src/bluetooth/qbluetoothdeviceinfo.h
+++ b/src/bluetooth/qbluetoothdeviceinfo.h
@@ -36,7 +36,8 @@
#include <QtBluetooth/qbluetoothglobal.h>
-#include <QString>
+#include <QtCore/qstring.h>
+#include <QtCore/qmetatype.h>
QT_BEGIN_NAMESPACE
@@ -242,4 +243,6 @@ private:
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(QBluetoothDeviceInfo)
+
#endif
diff --git a/src/bluetooth/qbluetoothlocaldevice.cpp b/src/bluetooth/qbluetoothlocaldevice.cpp
index c76ace95..87e1e521 100644
--- a/src/bluetooth/qbluetoothlocaldevice.cpp
+++ b/src/bluetooth/qbluetoothlocaldevice.cpp
@@ -103,9 +103,9 @@ class LocalDeviceRegisterMetaTypes
public:
LocalDeviceRegisterMetaTypes()
{
- qRegisterMetaType<QBluetoothLocalDevice::HostMode>("QBluetoothLocalDevice::HostMode");
- qRegisterMetaType<QBluetoothLocalDevice::Pairing>("QBluetoothLocalDevice::Pairing");
- qRegisterMetaType<QBluetoothLocalDevice::Error>("QBluetoothLocalDevice::Error");
+ qRegisterMetaType<QBluetoothLocalDevice::HostMode>();
+ qRegisterMetaType<QBluetoothLocalDevice::Pairing>();
+ qRegisterMetaType<QBluetoothLocalDevice::Error>();
}
} _registerLocalDeviceMetaTypes;
}
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;
diff --git a/src/bluetooth/qbluetoothserver_osx.mm b/src/bluetooth/qbluetoothserver_osx.mm
index 894209ba..46e8f750 100644
--- a/src/bluetooth/qbluetoothserver_osx.mm
+++ b/src/bluetooth/qbluetoothserver_osx.mm
@@ -60,8 +60,9 @@
#include <QtCore/qmutex.h>
// Import, since Obj-C headers do not have inclusion guards.
-#import <IOBluetooth/objc/IOBluetoothRFCOMMChannel.h>
-#import <IOBluetooth/objc/IOBluetoothL2CAPChannel.h>
+#include <Foundation/Foundation.h>
+// Only after Foundation.h
+#include "osx/corebluetoothwrapper_p.h"
#include <limits>
@@ -95,11 +96,9 @@ QBluetoothServerPrivate::QBluetoothServerPrivate(QSInfo::Protocol type, QBluetoo
port(0),
maxPendingConnections(1)
{
- Q_ASSERT_X(q_ptr, "QBluetoothServerPrivate", "invalid q_ptr (null)");
- if (serverType == QSInfo::UnknownProtocol) {
- qCWarning(QT_BT_OSX) << "QBluetoothServerPrivate::QBluetoothServerPrivate(), "
- "unknown protocol";
- }
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
+ if (serverType == QSInfo::UnknownProtocol)
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "unknown protocol";
}
QBluetoothServerPrivate::~QBluetoothServerPrivate()
@@ -117,11 +116,10 @@ void QBluetoothServerPrivate::_q_newConnection()
bool QBluetoothServerPrivate::startListener(quint16 realPort)
{
- Q_ASSERT_X(realPort, "startListener", "invalid port");
+ Q_ASSERT_X(realPort, Q_FUNC_INFO, "invalid port");
if (serverType == QSInfo::UnknownProtocol) {
- qCWarning(QT_BT_OSX) << "QBluetoothServerPrivate::startListener(), "
- "invalid protocol";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid protocol";
return false;
}
@@ -147,9 +145,9 @@ void QBluetoothServerPrivate::stopListener()
void QBluetoothServerPrivate::openNotify(IOBluetoothRFCOMMChannel *channel)
{
- Q_ASSERT_X(listener, "openNotify", "invalid listener (nil)");
- Q_ASSERT_X(channel, "openNotify", "invalid channel (nil)");
- Q_ASSERT_X(q_ptr, "openNotify", "invalid q_ptr (null)");
+ Q_ASSERT_X(listener, Q_FUNC_INFO, "invalid listener (nil)");
+ Q_ASSERT_X(channel, Q_FUNC_INFO, "invalid channel (nil)");
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
PendingConnection newConnection(channel, true);
pendingConnections.append(newConnection);
@@ -159,9 +157,9 @@ void QBluetoothServerPrivate::openNotify(IOBluetoothRFCOMMChannel *channel)
void QBluetoothServerPrivate::openNotify(IOBluetoothL2CAPChannel *channel)
{
- Q_ASSERT_X(listener, "openNotify", "invalid listener (nil)");
- Q_ASSERT_X(channel, "openNotify", "invalid channel (nil)");
- Q_ASSERT_X(q_ptr, "openNotify", "invalid q_ptr (null)");
+ Q_ASSERT_X(listener, Q_FUNC_INFO, "invalid listener (nil)");
+ Q_ASSERT_X(channel, Q_FUNC_INFO, "invalid channel (nil)");
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
PendingConnection newConnection(channel, true);
pendingConnections.append(newConnection);
@@ -212,20 +210,18 @@ quint16 QBluetoothServerPrivate::findFreePSM()
void QBluetoothServerPrivate::registerServer(QBluetoothServerPrivate *server, quint16 port)
{
// External lock is required + port must be free.
- Q_ASSERT_X(server, "registerServer", "invalid server (null)");
+ Q_ASSERT_X(server, Q_FUNC_INFO, "invalid server (null)");
const QSInfo::Protocol type = server->serverType;
if (type == QSInfo::RfcommProtocol) {
- Q_ASSERT_X(!channelIsBusy(port), "registerServer",
- "port is busy");
+ Q_ASSERT_X(!channelIsBusy(port), Q_FUNC_INFO, "port is busy");
busyChannels()[port] = server;
} else if (type == QSInfo::L2capProtocol) {
- Q_ASSERT_X(!psmIsBusy(port), "registerServer",
- "port is busy");
+ Q_ASSERT_X(!psmIsBusy(port), Q_FUNC_INFO, "port is busy");
busyPSMs()[port] = server;
} else {
- qCWarning(QT_BT_OSX) << "can not register a server with unknown "
- "protocol type";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "can not register a server "
+ "with unknown protocol type";
}
}
@@ -241,8 +237,7 @@ QBluetoothServerPrivate *QBluetoothServerPrivate::registeredServer(quint16 port,
if (it != busyPSMs().end())
return it.value();
} else {
- qCWarning(QT_BT_OSX) << "QBluetoothServerPrivate::registeredServer(), "
- "invalid protocol";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid protocol";
}
return Q_NULLPTR;
@@ -259,20 +254,17 @@ void QBluetoothServerPrivate::unregisterServer(QBluetoothServerPrivate *server)
if (it != busyChannels().end()) {
busyChannels().erase(it);
} else {
- qCWarning(QT_BT_OSX) << "QBluetoothServerPrivate::unregisterServer(), "
- "server is not registered";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "server is not registered";
}
} else if (type == QSInfo::L2capProtocol) {
ServerMapIterator it = busyPSMs().find(port);
if (it != busyPSMs().end()) {
busyPSMs().erase(it);
} else {
- qCWarning(QT_BT_OSX) << "QBluetoothServerPrivate::unregisterServer(), "
- "server is not registered";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "server is not registered";
}
} else {
- qCWarning(QT_BT_OSX) << "QBluetoothServerPrivate::unregisterServer(), "
- "invalid protocol";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid protocol";
}
}
@@ -303,15 +295,14 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
typedef QBluetoothServerPrivate::ObjCListener ObjCListener;
if (d_ptr->listener) {
- qCWarning(QT_BT_OSX) << "QBluetoothServer::listen() ",
- "already in listen mode, "
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "already in listen mode, "
"close server first";
return false;
}
const QBluetoothLocalDevice device(address);
if (!device.isValid()) {
- qCWarning(QT_BT_OSX) << "QBluetoothServer::listen(), device does not support Bluetooth or "
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "device does not support Bluetooth or "
<< address.toString()
<< " is not a valid local adapter";
d_ptr->lastError = UnknownError;
@@ -321,8 +312,7 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
const QBluetoothLocalDevice::HostMode hostMode = device.hostMode();
if (hostMode == QBluetoothLocalDevice::HostPoweredOff) {
- qCWarning(QT_BT_OSX) << "QBluetoothServer::listen(), "
- "bluetooth device is powered off";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "Bluetooth device is powered off";
d_ptr->lastError = PoweredOffError;
emit error(PoweredOffError);
return false;
@@ -331,8 +321,7 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
const QSInfo::Protocol type = d_ptr->serverType;
if (type == QSInfo::UnknownProtocol) {
- qCWarning(QT_BT_OSX) << "QBluetoothServer::listen(), "
- "invalid protocol";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid protocol";
d_ptr->lastError = UnsupportedProtocolError;
emit error(d_ptr->lastError);
return false;
@@ -346,13 +335,13 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
if (port) {
if (type == QSInfo::RfcommProtocol) {
if (d_ptr->channelIsBusy(port)) {
- qCWarning(QT_BT_OSX) << "QBluetoothServer::listen(), server port: "
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO <<"server port: "
<< port << "already registered";
d_ptr->lastError = ServiceAlreadyRegisteredError;
}
} else {
if (d_ptr->psmIsBusy(port)) {
- qCWarning(QT_BT_OSX) << "QBluetoothServer::listen(), server port: "
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "server port: "
<< port << "already registered";
d_ptr->lastError = ServiceAlreadyRegisteredError;
}
@@ -368,7 +357,7 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
}
if (!port) {
- qCWarning(QT_BT_OSX) << "QBluetoothServer::listen(), all ports are busy";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "all ports are busy";
d_ptr->lastError = ServiceAlreadyRegisteredError;
emit error(d_ptr->lastError);
return false;
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
index c800dc6d..ef28ef82 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
@@ -91,7 +91,8 @@ QT_BEGIN_NAMESPACE
\value PoweredOffError The Bluetooth adaptor is powered off, power it on before doing discovery.
\value InputOutputError Writing or reading from the device resulted in an error.
\value InvalidBluetoothAdapterError The passed local adapter address does not match the physical
- adapter address of any local Bluetooth device.
+ adapter address of any local Bluetooth device. This value
+ was introduced by Qt 5.3.
\value UnknownError An unknown error has occurred.
*/
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.h b/src/bluetooth/qbluetoothservicediscoveryagent.h
index 02be2f5b..787d58e3 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent.h
+++ b/src/bluetooth/qbluetoothservicediscoveryagent.h
@@ -120,4 +120,6 @@ private:
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(QBluetoothServiceDiscoveryAgent::Error)
+
#endif
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
index 01993f25..92a67caa 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
@@ -48,19 +48,20 @@ QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
QBluetoothServiceDiscoveryAgentPrivate::QBluetoothServiceDiscoveryAgentPrivate(
- const QBluetoothAddress &deviceAdapter)
+ const QBluetoothAddress &/*deviceAdapter*/)
: error(QBluetoothServiceDiscoveryAgent::NoError),
state(Inactive), deviceDiscoveryAgent(0),
mode(QBluetoothServiceDiscoveryAgent::MinimalDiscovery),
singleDevice(false), receiver(0), localDeviceReceiver(0)
{
QList<QBluetoothHostInfo> devices = QBluetoothLocalDevice::allDevices();
- Q_ASSERT(devices.count() == 1); //Android only supports one device at the moment
+ Q_ASSERT(devices.count() <= 1); //Android only supports one device at the moment
- if (deviceAdapter.isNull() && devices.count() > 0 )
- m_deviceAdapterAddress = devices.at(0).address();
- else
- m_deviceAdapterAddress = deviceAdapter;
+ if (devices.isEmpty()) {
+ error = QBluetoothServiceDiscoveryAgent::InvalidBluetoothAdapterError;
+ errorString = QBluetoothServiceDiscoveryAgent::tr("Invalid Bluetooth adapter address");
+ return;
+ }
if (QtAndroidPrivate::androidSdkVersion() < 15)
qCWarning(QT_BT_ANDROID)
@@ -69,13 +70,10 @@ QBluetoothServiceDiscoveryAgentPrivate::QBluetoothServiceDiscoveryAgentPrivate(
<< "Service discovery will return empty list.";
- /* We assume that the current local adapter has been passed.
- Android only supports one adapter at the moment. If m_deviceAdapterAddress
- doesn't match the local adapter then we won't get to this point since
- we have an InvalidBluetoothAdapter error.
-
- The logic below must change once there is more than one adapter.
- */
+ /*
+ We assume that the current local adapter has been passed.
+ The logic below must change once there is more than one adapter.
+ */
btAdapter = QAndroidJniObject::callStaticObjectMethod("android/bluetooth/BluetoothAdapter",
"getDefaultAdapter",
@@ -83,7 +81,7 @@ QBluetoothServiceDiscoveryAgentPrivate::QBluetoothServiceDiscoveryAgentPrivate(
if (!btAdapter.isValid())
qCWarning(QT_BT_ANDROID) << "Platform does not support Bluetooth";
- qRegisterMetaType<QList<QBluetoothUuid> >("QList<QBluetoothUuid>");
+ qRegisterMetaType<QList<QBluetoothUuid> >();
}
QBluetoothServiceDiscoveryAgentPrivate::~QBluetoothServiceDiscoveryAgentPrivate()
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
index d82a73a8..6958e1b2 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
@@ -71,9 +71,9 @@ QBluetoothServiceDiscoveryAgentPrivate::QBluetoothServiceDiscoveryAgentPrivate(c
managerBluez5 = new OrgFreedesktopDBusObjectManagerInterface(
QStringLiteral("org.bluez"), QStringLiteral("/"),
QDBusConnection::systemBus());
- qRegisterMetaType<QBluetoothServiceDiscoveryAgent::Error>("QBluetoothServiceDiscoveryAgent::Error");
+ qRegisterMetaType<QBluetoothServiceDiscoveryAgent::Error>();
} else {
- qRegisterMetaType<ServiceMap>("ServiceMap");
+ qRegisterMetaType<ServiceMap>();
qDBusRegisterMetaType<ServiceMap>();
manager = new OrgBluezManagerInterface(QStringLiteral("org.bluez"), QStringLiteral("/"),
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm
index 9311df55..caa3942c 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_osx.mm
@@ -49,13 +49,13 @@
#include <QtCore/qloggingcategory.h>
#include <QtCore/qscopedpointer.h>
#include <QtCore/qstring.h>
+#include <QtCore/qglobal.h>
#include <QtCore/qdebug.h>
#include <QtCore/qlist.h>
-// We have to import obj-C headers, they are not guarded against a multiple inclusion.
-#import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h>
-#import <IOBluetooth/objc/IOBluetoothHostController.h>
-#import <IOBluetooth/objc/IOBluetoothDevice.h>
+#include <Foundation/Foundation.h>
+// Only after Foundation.h
+#include "osx/corebluetoothwrapper_p.h"
QT_BEGIN_NAMESPACE
@@ -130,10 +130,10 @@ QBluetoothServiceDiscoveryAgentPrivate::QBluetoothServiceDiscoveryAgentPrivate(c
void QBluetoothServiceDiscoveryAgentPrivate::startDeviceDiscovery()
{
- Q_ASSERT_X(q_ptr, "startDeviceDiscovery()", "invalid q_ptr (null)");
- Q_ASSERT_X(state == Inactive, "startDeviceDiscovery()", "invalid state");
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
+ Q_ASSERT_X(state == Inactive, Q_FUNC_INFO, "invalid state");
Q_ASSERT_X(error != QBluetoothServiceDiscoveryAgent::InvalidBluetoothAdapterError,
- "startDeviceDiscovery()", "invalid bluetooth adapter");
+ Q_FUNC_INFO, "invalid bluetooth adapter");
Q_ASSERT_X(deviceDiscoveryAgent.isNull(), "startDeviceDiscovery()",
"discovery agent already exists");
@@ -146,11 +146,10 @@ void QBluetoothServiceDiscoveryAgentPrivate::startDeviceDiscovery()
void QBluetoothServiceDiscoveryAgentPrivate::stopDeviceDiscovery()
{
- Q_ASSERT_X(q_ptr, "stopDeviceDiscovery()", "invalid q_ptr (null)");
- Q_ASSERT_X(!deviceDiscoveryAgent.isNull(), "stopDeviceDiscovery()",
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
+ Q_ASSERT_X(!deviceDiscoveryAgent.isNull(), Q_FUNC_INFO,
"invalid device discovery agent (null)");
- Q_ASSERT_X(state == DeviceDiscovery, "stopDeviceDiscovery()",
- "invalid state");
+ Q_ASSERT_X(state == DeviceDiscovery, Q_FUNC_INFO, "invalid state");
deviceDiscoveryAgent->stop();
deviceDiscoveryAgent.reset(Q_NULLPTR);
@@ -164,9 +163,9 @@ void QBluetoothServiceDiscoveryAgentPrivate::startServiceDiscovery()
// Any of 'Inactive'/'DeviceDiscovery'/'ServiceDiscovery' states
// are possible.
- Q_ASSERT_X(q_ptr, "startServiceDiscovery()", "invalid q_ptr (null)");
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
Q_ASSERT_X(error != QBluetoothServiceDiscoveryAgent::InvalidBluetoothAdapterError,
- "startServiceDiscovery()", "invalid bluetooth adapter");
+ Q_FUNC_INFO, "invalid bluetooth adapter");
if (discoveredDevices.isEmpty()) {
state = Inactive;
@@ -210,8 +209,8 @@ void QBluetoothServiceDiscoveryAgentPrivate::startServiceDiscovery()
void QBluetoothServiceDiscoveryAgentPrivate::stopServiceDiscovery()
{
- Q_ASSERT_X(state != Inactive, "stopServiceDiscovery()", "invalid state");
- Q_ASSERT_X(q_ptr, "stopServiceDiscovery()", "invalid q_ptr (null)");
+ Q_ASSERT_X(state != Inactive, Q_FUNC_INFO, "invalid state");
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
discoveredDevices.clear();
state = Inactive;
@@ -256,7 +255,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_deviceDiscovered(const QBluetoot
void QBluetoothServiceDiscoveryAgentPrivate::_q_deviceDiscoveryError(QBluetoothDeviceDiscoveryAgent::Error)
{
- Q_ASSERT_X(q_ptr, "_q_deviceDiscoveryError()", "invalid q_ptr (null)");
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
error = QBluetoothServiceDiscoveryAgent::UnknownError;
errorString = tr("Unknown error while scanning for devices");
@@ -271,8 +270,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_deviceDiscoveryError(QBluetoothD
void QBluetoothServiceDiscoveryAgentPrivate::_q_deviceDiscoveryFinished()
{
- Q_ASSERT_X(q_ptr, "_q_deviceDiscoveryFinished()",
- "invalid q_ptr (null)");
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
if (deviceDiscoveryAgent->error() != QBluetoothDeviceDiscoveryAgent::NoError) {
//Forward the device discovery error
@@ -295,7 +293,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_serviceDiscoveryFinished()
void QBluetoothServiceDiscoveryAgentPrivate::SDPInquiryFinished(IOBluetoothDevice *device)
{
- Q_ASSERT_X(device, "SDPInquiryFinished()", "invalid IOBluetoothDevice (nil)");
+ Q_ASSERT_X(device, Q_FUNC_INFO, "invalid IOBluetoothDevice (nil)");
if (state == Inactive)
return;
@@ -305,8 +303,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::SDPInquiryFinished(IOBluetoothDevic
NSArray *const records = device.services;
for (IOBluetoothSDPServiceRecord *record in records) {
QBluetoothServiceInfo serviceInfo;
- Q_ASSERT_X(discoveredDevices.size() >= 1, "SDPInquiryFinished()",
- "invalid number of devices");
+ Q_ASSERT_X(discoveredDevices.size() >= 1, Q_FUNC_INFO, "invalid number of devices");
serviceInfo.setDevice(discoveredDevices.at(0));
OSXBluetooth::extract_service_record(record, serviceInfo);
@@ -331,8 +328,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::SDPInquiryError(IOBluetoothDevice *
{
Q_UNUSED(device)
- qCWarning(QT_BT_OSX) << "QBluetoothServiceDiscoveryAgentPrivate::SDPInquiryError(), "
- "inquiry failed with IOKit code: " << int(errorCode);
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "inquiry failed with IOKit code: " << int(errorCode);
discoveredDevices.clear();
// TODO: find a better mapping from IOReturn to QBluetoothServiceDiscoveryAgent::Error.
@@ -347,8 +343,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::SDPInquiryError(IOBluetoothDevice *
void QBluetoothServiceDiscoveryAgentPrivate::performMinimalServiceDiscovery(const QBluetoothAddress &deviceAddress)
{
- Q_ASSERT_X(!deviceAddress.isNull(), "performMinimalServiceDiscovery()",
- "invalid device address");
+ Q_ASSERT_X(!deviceAddress.isNull(), Q_FUNC_INFO, "invalid device address");
QT_BT_MAC_AUTORELEASEPOOL;
@@ -365,7 +360,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::performMinimalServiceDiscovery(cons
NSArray *const records = device.services;
for (IOBluetoothSDPServiceRecord *record in records) {
QBluetoothServiceInfo serviceInfo;
- Q_ASSERT_X(discoveredDevices.size() >= 1, "SDPInquiryFinished()",
+ Q_ASSERT_X(discoveredDevices.size() >= 1, Q_FUNC_INFO,
"invalid number of devices");
serviceInfo.setDevice(discoveredDevices.at(0));
@@ -389,11 +384,9 @@ void QBluetoothServiceDiscoveryAgentPrivate::performMinimalServiceDiscovery(cons
void QBluetoothServiceDiscoveryAgentPrivate::setupDeviceDiscoveryAgent()
{
- Q_ASSERT_X(q_ptr, "setupDeviceDiscoveryAgent()",
- "invalid q_ptr (null)");
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
Q_ASSERT_X(deviceDiscoveryAgent.isNull() || !deviceDiscoveryAgent->isActive(),
- "setupDeviceDiscoveryAgent()",
- "device discovery agent is active");
+ Q_FUNC_INFO, "device discovery agent is active");
deviceDiscoveryAgent.reset(new QBluetoothDeviceDiscoveryAgent(localAdapterAddress, q_ptr));
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp
index d8a03105..4b7108be 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp
@@ -132,8 +132,8 @@ QBluetoothServiceDiscoveryAgentPrivate::QBluetoothServiceDiscoveryAgentPrivate(c
connect(&m_queryTimer, SIGNAL(timeout()), this, SLOT(queryTimeout()));
ppsRegisterForEvent(QStringLiteral("service_updated"), this);
//Needed for connecting signals and slots from static function
- qRegisterMetaType<QBluetoothServiceInfo>("QBluetoothServiceInfo");
- qRegisterMetaType<QBluetoothServiceDiscoveryAgent::Error>("QBluetoothServiceDiscoveryAgent::Error");
+ qRegisterMetaType<QBluetoothServiceInfo>();
+ qRegisterMetaType<QBluetoothServiceDiscoveryAgent::Error>();
}
QBluetoothServiceDiscoveryAgentPrivate::~QBluetoothServiceDiscoveryAgentPrivate()
diff --git a/src/bluetooth/qbluetoothserviceinfo_osx.mm b/src/bluetooth/qbluetoothserviceinfo_osx.mm
index ae88b4e7..1240df18 100644
--- a/src/bluetooth/qbluetoothserviceinfo_osx.mm
+++ b/src/bluetooth/qbluetoothserviceinfo_osx.mm
@@ -52,8 +52,9 @@
#include <QtCore/qmap.h>
#include <QtCore/qurl.h>
-// Import, it's Objective-C header (no inclusion guards).
-#import <IOBluetooth/objc/IOBluetoothSDPServiceRecord.h>
+#include <Foundation/Foundation.h>
+// Only after Foundation.h:
+#include "osx/corebluetoothwrapper_p.h"
QT_BEGIN_NAMESPACE
@@ -115,7 +116,7 @@ QBluetoothServiceInfoPrivate::QBluetoothServiceInfoPrivate(QBluetoothServiceInfo
registered(false),
serviceRecordHandle(0)
{
- Q_ASSERT_X(q, "QBluetoothServiceInfoPrivate()", "invalid q_ptr (null)");
+ Q_ASSERT_X(q, Q_FUNC_INFO, "invalid q_ptr (null)");
}
bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &localAdapter)
@@ -125,8 +126,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca
if (registered)
return false;
- Q_ASSERT_X(!serviceRecord, "QBluetoothServiceInfoPrivate::registerService()",
- "not registered, but serviceRecord is not nil");
+ Q_ASSERT_X(!serviceRecord, Q_FUNC_INFO, "not registered, but serviceRecord is not nil");
using namespace OSXBluetooth;
@@ -134,8 +134,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca
serviceDict(iobluetooth_service_dictionary(*q_ptr));
if (!serviceDict) {
- qCWarning(QT_BT_OSX) << "QBluetoothServiceInfoPrivate::registerService(), "
- "failed to create a service dictionary";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to create a service dictionary";
return false;
}
@@ -148,8 +147,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca
// 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 register a service record";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to register a service record";
return false;
}
@@ -159,8 +157,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca
#endif
if (!newRecord) {
- qCWarning(QT_BT_OSX) << "QBluetoothServiceInfoPrivate::registerService(), "
- "failed to register a service record";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to register a service record";
// In case of SDK < 10.9 it's not possible to remove a service record ...
// no way to obtain record handle yet.
return false;
@@ -168,8 +165,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca
BluetoothSDPServiceRecordHandle newRecordHandle = 0;
if ([newRecord getServiceRecordHandle:&newRecordHandle] != kIOReturnSuccess) {
- qCWarning(QT_BT_OSX) << "QBluetoothServiceInfoPrivate::registerService(), "
- "failed to register a service record";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to register a service record";
#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_NA)
[newRecord removeServiceRecord];
#endif
@@ -204,8 +200,7 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress &loca
#else
IOBluetoothRemoveServiceWithRecordHandle(newRecordHandle);
#endif
- qCWarning(QT_BT_OSX) << "QBluetoothServiceInfoPrivate::registerService(), "
- "failed to register a service record";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to register a service record";
return false;
}
@@ -229,8 +224,7 @@ bool QBluetoothServiceInfoPrivate::unregisterService()
if (!registered)
return false;
- Q_ASSERT_X(serviceRecord, "QBluetoothServiceInfoPrivate::unregisterService()",
- "service registered, but serviceRecord is nil");
+ Q_ASSERT_X(serviceRecord, Q_FUNC_INFO, "service registered, but serviceRecord is nil");
#if QT_MAC_PLATFORM_SDK_EQUAL_OR_ABOVE(__MAC_10_9, __IPHONE_NA)
[serviceRecord removeServiceRecord];
diff --git a/src/bluetooth/qbluetoothsocket.h b/src/bluetooth/qbluetoothsocket.h
index 5b4d3c5b..e68c2bc3 100644
--- a/src/bluetooth/qbluetoothsocket.h
+++ b/src/bluetooth/qbluetoothsocket.h
@@ -161,4 +161,7 @@ Q_BLUETOOTH_EXPORT QDebug operator<<(QDebug, QBluetoothSocket::SocketState);
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(QBluetoothSocket::SocketError)
+Q_DECLARE_METATYPE(QBluetoothSocket::SocketState)
+
#endif
diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp
index e8d7d028..02440abc 100644
--- a/src/bluetooth/qbluetoothsocket_android.cpp
+++ b/src/bluetooth/qbluetoothsocket_android.cpp
@@ -40,7 +40,6 @@
#include <QtConcurrent/QtConcurrentRun>
#include <QtAndroidExtras/QAndroidJniEnvironment>
-
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
@@ -57,8 +56,8 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate()
adapter = QAndroidJniObject::callStaticObjectMethod("android/bluetooth/BluetoothAdapter",
"getDefaultAdapter",
"()Landroid/bluetooth/BluetoothAdapter;");
- qRegisterMetaType<QBluetoothSocket::SocketError>("QBluetoothSocket::SocketError");
- qRegisterMetaType<QBluetoothSocket::SocketState>("QBluetoothSocket::SocketState");
+ qRegisterMetaType<QBluetoothSocket::SocketError>();
+ qRegisterMetaType<QBluetoothSocket::SocketState>();
}
QBluetoothSocketPrivate::~QBluetoothSocketPrivate()
diff --git a/src/bluetooth/qbluetoothsocket_osx.mm b/src/bluetooth/qbluetoothsocket_osx.mm
index 027c7e37..2bdd1291 100644
--- a/src/bluetooth/qbluetoothsocket_osx.mm
+++ b/src/bluetooth/qbluetoothsocket_osx.mm
@@ -85,7 +85,7 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address,
Q_ASSERT_X(state == QBluetoothSocket::ServiceLookupState
|| state == QBluetoothSocket::UnconnectedState,
- "connectToService()", "invalid state");
+ Q_FUNC_INFO, "invalid state");
socketError = QBluetoothSocket::NoSocketError;
errorString.clear();
@@ -157,7 +157,7 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address,
void QBluetoothSocketPrivate::close()
{
// Can never be called while we're in connectToService:
- Q_ASSERT_X(!isConnecting, "close()", "internal inconsistency - "
+ Q_ASSERT_X(!isConnecting, Q_FUNC_INFO, "internal inconsistency - "
"still in connectToService()");
// Only go through closing if the socket was fully opened
@@ -171,7 +171,7 @@ void QBluetoothSocketPrivate::close()
void QBluetoothSocketPrivate::abort()
{
// Can never be called while we're in connectToService:
- Q_ASSERT_X(!isConnecting, "abort()", "internal inconsistency - "
+ Q_ASSERT_X(!isConnecting, Q_FUNC_INFO, "internal inconsistency - "
"still in connectToService()");
if (socketType == QBluetoothServiceInfo::RfcommProtocol)
@@ -240,10 +240,10 @@ void QBluetoothSocketPrivate::_q_writeNotify()
{
Q_ASSERT_X(socketType == QBluetoothServiceInfo::L2capProtocol
|| socketType == QBluetoothServiceInfo::RfcommProtocol,
- "_q_writeNotify()", "invalid socket type");
- Q_ASSERT_X(l2capChannel || rfcommChannel, "_q_writeNotify()",
+ Q_FUNC_INFO, "invalid socket type");
+ Q_ASSERT_X(l2capChannel || rfcommChannel, Q_FUNC_INFO,
"invalid socket (no open channel)");
- Q_ASSERT_X(q_ptr, "_q_writeNotify()", "invalid q_ptr (null)");
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
if (txBuffer.size()) {
const bool isL2CAP = socketType == QBluetoothServiceInfo::L2capProtocol;
@@ -281,7 +281,7 @@ bool QBluetoothSocketPrivate::setChannel(IOBluetoothRFCOMMChannel *channel)
// It must be a newborn socket!
Q_ASSERT_X(socketError == QBluetoothSocket::NoSocketError
&& state == QBluetoothSocket::UnconnectedState && !rfcommChannel && !l2capChannel,
- "QBluetoothSocketPrivate::setChannel()", "unexpected socket state");
+ Q_FUNC_INFO, "unexpected socket state");
openMode = QIODevice::ReadWrite;
rfcommChannel.reset([[ObjCRFCOMMChannel alloc] initWithDelegate:this channel:channel]);
@@ -305,7 +305,7 @@ bool QBluetoothSocketPrivate::setChannel(IOBluetoothL2CAPChannel *channel)
// It must be a newborn socket!
Q_ASSERT_X(socketError == QBluetoothSocket::NoSocketError
&& state == QBluetoothSocket::UnconnectedState && !l2capChannel && !rfcommChannel,
- "QBluetoothSocketPrivate::setChannel()", "unexpected socket state");
+ Q_FUNC_INFO, "unexpected socket state");
openMode = QIODevice::ReadWrite;
l2capChannel.reset([[ObjCL2CAPChannel alloc] initWithDelegate:this channel:channel]);
@@ -323,7 +323,7 @@ void QBluetoothSocketPrivate::setChannelError(IOReturn errorCode)
{
Q_UNUSED(errorCode)
- Q_ASSERT_X(q_ptr, "setChannelError()", "invalid q_ptr (null)");
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
if (isConnecting) {
// The delegate's method was called while we are still in
@@ -336,7 +336,7 @@ void QBluetoothSocketPrivate::setChannelError(IOReturn errorCode)
void QBluetoothSocketPrivate::channelOpenComplete()
{
- Q_ASSERT_X(q_ptr, "channelOpenComplete()", "invalid q_ptr (null)");
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
if (!isConnecting) {
q_ptr->setSocketState(QBluetoothSocket::ConnectedState);
@@ -351,7 +351,7 @@ void QBluetoothSocketPrivate::channelOpenComplete()
void QBluetoothSocketPrivate::channelClosed()
{
- Q_ASSERT_X(q_ptr, "channelClosed()", "invalid q_ptr (null)");
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
// Channel was closed by IOBluetooth and we can not write any data
// (thus close/abort probably will not work).
@@ -369,9 +369,9 @@ void QBluetoothSocketPrivate::channelClosed()
void QBluetoothSocketPrivate::readChannelData(void *data, std::size_t size)
{
- Q_ASSERT_X(data, "readChannelData()", "invalid data (null)");
- Q_ASSERT_X(size, "readChannelData()", "invalid data size (0)");
- Q_ASSERT_X(q_ptr, "readChannelData()", "invalid q_ptr (null)");
+ Q_ASSERT_X(data, Q_FUNC_INFO, "invalid data (null)");
+ Q_ASSERT_X(size, Q_FUNC_INFO, "invalid data size (0)");
+ Q_ASSERT_X(q_ptr, Q_FUNC_INFO, "invalid q_ptr (null)");
const char *src = static_cast<char *>(data);
char *dst = buffer.reserve(size);
@@ -390,8 +390,8 @@ void QBluetoothSocketPrivate::writeComplete()
qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize)
{
- Q_ASSERT_X(data, "writeData()", "invalid data (null)");
- Q_ASSERT_X(maxSize > 0, "writeData()", "invalid data size");
+ Q_ASSERT_X(data, Q_FUNC_INFO, "invalid data (null)");
+ Q_ASSERT_X(maxSize > 0, Q_FUNC_INFO, "invalid data size");
if (state != QBluetoothSocket::ConnectedState) {
errorString = tr("Cannot write while not connected");
@@ -403,7 +403,7 @@ qint64 QBluetoothSocketPrivate::writeData(const char *data, qint64 maxSize)
// IOBluetoothL2CAPChannel buffered (writeAsync).
if (!txBuffer.size())
- QMetaObject::invokeMethod(this, "_q_writeNotify", Qt::QueuedConnection);
+ QMetaObject::invokeMethod(this, Q_FUNC_INFO, Qt::QueuedConnection);
char *dst = txBuffer.reserve(maxSize);
std::copy(data, data + maxSize, dst);
@@ -452,7 +452,7 @@ qint64 QBluetoothSocket::bytesToWrite() const
void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, OpenMode openMode)
{
if (state() != UnconnectedState && state() != ServiceLookupState) {
- qCWarning(QT_BT_OSX) << "QBluetoothSocket::connectToService() called on a busy socket";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "called on a busy socket";
d_ptr->errorString = tr("Trying to connect while connection is in progress");
setSocketError(OperationError);
return;
@@ -468,7 +468,8 @@ void QBluetoothSocket::connectToService(const QBluetoothServiceInfo &service, Op
} else {
// Try service discovery.
if (service.serviceUuid().isNull()) {
- qCWarning(QT_BT_OSX) << "No port, no PSM, and no UUID provided, unable to connect";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "No port, "
+ "no PSM, and no UUID provided, unable to connect";
return;
}
@@ -480,7 +481,7 @@ void QBluetoothSocket::connectToService(const QBluetoothAddress &address, const
OpenMode openMode)
{
if (state() != QBluetoothSocket::UnconnectedState) {
- qCWarning(QT_BT_OSX) << "QBluetoothSocket::connectToService() called on a busy socket";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "called on a busy socket";
d_ptr->errorString = tr("Trying to connect while connection is in progress");
setSocketError(QBluetoothSocket::OperationError);
return;
@@ -497,7 +498,7 @@ void QBluetoothSocket::connectToService(const QBluetoothAddress &address, quint1
OpenMode openMode)
{
if (state() != QBluetoothSocket::UnconnectedState) {
- qCWarning(QT_BT_OSX) << "QBluetoothSocket::connectToService() called on a busy socket";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "called on a busy socket";
d_ptr->errorString = tr("Trying to connect while connection is in progress");
setSocketError(OperationError);
return;
@@ -538,8 +539,7 @@ void QBluetoothSocket::setSocketState(QBluetoothSocket::SocketState state)
// We can register for L2CAP/RFCOMM open notifications,
// that's different from 'listen' and is implemented
// in QBluetoothServer.
- qCWarning(QT_BT_OSX) << "QBluetoothSocket::setSocketState(), "
- "listening sockets are not supported";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "listening sockets are not supported";
}
}
@@ -577,7 +577,7 @@ void QBluetoothSocket::doDeviceDiscovery(const QBluetoothServiceInfo &service, O
if (!service.serviceClassUuids().isEmpty())
d_ptr->discoveryAgent->setUuidFilter(service.serviceClassUuids());
- Q_ASSERT_X(!d_ptr->discoveryAgent->uuidFilter().isEmpty(), "doDeviceDiscovery()",
+ Q_ASSERT_X(!d_ptr->discoveryAgent->uuidFilter().isEmpty(), Q_FUNC_INFO,
"invalid service info");
d_ptr->discoveryAgent->start(QBluetoothServiceDiscoveryAgent::FullDiscovery);
diff --git a/src/bluetooth/qbluetoothtransfermanager.cpp b/src/bluetooth/qbluetoothtransfermanager.cpp
index 65eecae3..ea2406f1 100644
--- a/src/bluetooth/qbluetoothtransfermanager.cpp
+++ b/src/bluetooth/qbluetoothtransfermanager.cpp
@@ -90,6 +90,8 @@ QT_BEGIN_NAMESPACE
QBluetoothTransferManager::QBluetoothTransferManager(QObject *parent)
: QObject(parent)
{
+ qRegisterMetaType<QBluetoothTransferReply*>();
+ qRegisterMetaType<QBluetoothTransferReply::TransferError>();
}
/*!
diff --git a/src/bluetooth/qbluetoothtransferreply.cpp b/src/bluetooth/qbluetoothtransferreply.cpp
index af1bf828..a40e7191 100644
--- a/src/bluetooth/qbluetoothtransferreply.cpp
+++ b/src/bluetooth/qbluetoothtransferreply.cpp
@@ -118,8 +118,6 @@ void QBluetoothTransferReply::abort()
QBluetoothTransferReply::QBluetoothTransferReply(QObject *parent)
: QObject(parent), d_ptr(new QBluetoothTransferReplyPrivate())
{
- qRegisterMetaType<QBluetoothTransferReply*>();
- qRegisterMetaType<QBluetoothTransferReply::TransferError>();
}
/*!
diff --git a/src/bluetooth/qbluetoothtransferreply_osx.mm b/src/bluetooth/qbluetoothtransferreply_osx.mm
index 3204e7b6..37d73a56 100644
--- a/src/bluetooth/qbluetoothtransferreply_osx.mm
+++ b/src/bluetooth/qbluetoothtransferreply_osx.mm
@@ -120,7 +120,7 @@ QBluetoothTransferReplyOSXPrivate::QBluetoothTransferReplyOSXPrivate(QBluetoothT
minimalScan(true),
requestComplete(false)
{
- Q_ASSERT_X(q, "QBluetoothTransferReplyOSXPrivate", "invalid q_ptr (null)");
+ Q_ASSERT_X(q, Q_FUNC_INFO, "invalid q_ptr (null)");
}
QBluetoothTransferReplyOSXPrivate::~QBluetoothTransferReplyOSXPrivate()
@@ -140,8 +140,8 @@ bool QBluetoothTransferReplyOSXPrivate::isActive() const
bool QBluetoothTransferReplyOSXPrivate::startOPP(const QBluetoothAddress &device)
{
- Q_ASSERT_X(!isActive(), "startOPP", "already started");
- Q_ASSERT_X(!device.isNull(), "startOPP", "invalid device address");
+ Q_ASSERT_X(!isActive(), Q_FUNC_INFO, "already started");
+ Q_ASSERT_X(!device.isNull(), Q_FUNC_INFO, "invalid device address");
errorString.clear();
error = QBluetoothTransferReply::NoError;
@@ -164,15 +164,13 @@ bool QBluetoothTransferReplyOSXPrivate::startOPP(const QBluetoothAddress &device
void QBluetoothTransferReplyOSXPrivate::sendConnect(const QBluetoothAddress &device, quint16 channelID)
{
- Q_ASSERT_X(!session, "sendConnect", "session is already active");
+ Q_ASSERT_X(!session, Q_FUNC_INFO, "session is already active");
error = QBluetoothTransferReply::NoError;
errorString.clear();
if (device.isNull() || !channelID) {
- qCWarning(QT_BT_OSX) << "QBluetoothTransferReplyOSXPrivate::sendConnect(), "
- "invalid device address or port";
-
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid device address or port";
setReplyError(QBluetoothTransferReply::HostNotFoundError,
QObject::tr("Invalid target address"));
return;
@@ -181,8 +179,7 @@ void QBluetoothTransferReplyOSXPrivate::sendConnect(const QBluetoothAddress &dev
OBEXSession newSession([[ObjCOBEXSession alloc] initWithDelegate:this
remoteDevice:device channelID:channelID]);
if (!newSession) {
- qCWarning(QT_BT_OSX) << "QBluetoothTransferReplyOSXPrivate::sendConnect(), "
- "failed to allocate OSXBTOBEXSession object";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "failed to allocate OSXBTOBEXSession object";
setReplyError(QBluetoothTransferReply::UnknownError,
QObject::tr("Failed to create an OBEX session"));
@@ -197,8 +194,7 @@ void QBluetoothTransferReplyOSXPrivate::sendConnect(const QBluetoothAddress &dev
if ([session isConnected])
sendPut();// Connected, send a PUT request.
} else {
- qCWarning(QT_BT_OSX) << "QBluetoothTransferReplyOSXPrivate::sendConnect(), "
- "OBEXConnect failed";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "OBEXConnect failed";
if (error == QBluetoothTransferReply::NoError) {
// The error is not set yet.
@@ -214,10 +210,10 @@ void QBluetoothTransferReplyOSXPrivate::sendConnect(const QBluetoothAddress &dev
void QBluetoothTransferReplyOSXPrivate::sendPut()
{
- Q_ASSERT_X(inputStream, "sendPut", "invalid input stream (null)");
- Q_ASSERT_X(session, "sendPut", "invalid OBEX session (nil)");
- Q_ASSERT_X([session isConnected], "sendPut", "not connected");
- Q_ASSERT_X(![session hasActiveRequest], "sendPut",
+ Q_ASSERT_X(inputStream, Q_FUNC_INFO, "invalid input stream (null)");
+ 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");
QString fileName;
@@ -354,9 +350,7 @@ QBluetoothTransferReplyOSX::QBluetoothTransferReplyOSX(QIODevice *input,
if (input) {
QMetaObject::invokeMethod(this, "start", Qt::QueuedConnection);
} else {
- qCWarning(QT_BT_OSX) << "QBluetoothTransferReplyOSX::QBluetoothTransferReplyOSX(), "
- "invalid input stream (null)";
-
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid input stream (null)";
osx_d_ptr->requestComplete = true;
osx_d_ptr->errorString = tr("Invalid input file (null)");
osx_d_ptr->error = FileNotFoundError;
@@ -417,8 +411,7 @@ bool QBluetoothTransferReplyOSX::start()
if (!osx_d_ptr->isActive()) {
// Step 0: find a channelID.
if (request().address().isNull()) {
- qCWarning(QT_BT_OSX) << "QBluetoothTransferReplyOSX::start(), "
- "invalid device address";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "invalid device address";
osx_d_ptr->setReplyError(HostNotFoundError, tr("Invalid target address"));
return false;
}
@@ -432,7 +425,7 @@ bool QBluetoothTransferReplyOSX::start()
void QBluetoothTransferReplyOSX::serviceDiscoveryFinished()
{
- Q_ASSERT_X(osx_d_ptr->agent.data(), "serviceDiscoveryFinished",
+ Q_ASSERT_X(osx_d_ptr->agent.data(), Q_FUNC_INFO,
"invalid service discovery agent (null)");
const QList<QBluetoothServiceInfo> services = osx_d_ptr->agent->discoveredServices();
@@ -454,7 +447,7 @@ void QBluetoothTransferReplyOSX::serviceDiscoveryFinished()
void QBluetoothTransferReplyOSX::serviceDiscoveryError(QBluetoothServiceDiscoveryAgent::Error errorCode)
{
- Q_ASSERT_X(osx_d_ptr->agent.data(), "serviceDiscoveryError", "invalid service discovery agent (null)");
+ Q_ASSERT_X(osx_d_ptr->agent.data(), Q_FUNC_INFO, "invalid service discovery agent (null)");
if (errorCode == QBluetoothServiceDiscoveryAgent::PoweredOffError) {
// There's nothing else we can do.
diff --git a/src/bluetooth/qbluetoothuuid.cpp b/src/bluetooth/qbluetoothuuid.cpp
index f4840428..ef5328bd 100644
--- a/src/bluetooth/qbluetoothuuid.cpp
+++ b/src/bluetooth/qbluetoothuuid.cpp
@@ -211,6 +211,18 @@ Q_GLOBAL_STATIC_WITH_ARGS(QUuid, baseUuid, ("{00000000-0000-1000-8000-00805F9B34
sensor intended for sports and fitness applications.
\value LocationAndNavigation Location Navigation UUID (service). The service exposes location and navigation-related
data from a Location and Navigation sensor intended for outdoor activity applications.
+ \value EnvironmentalSensing Environmental sensor UUID (service). The service exposes data from an environmental sensor
+ for sports and fitness applications.
+ \value BodyComposition Body composition UUID (service). The service exposes data about the body composition intended
+ for consumer healthcare applications.
+ \value UserData User Data UUID (service). The User Data service provides user-related data such as name,
+ gender or weight in sports and fitness environments.
+ \value WeightScale Weight Scale UUID (service). The Weight Scale service exposes weight-related data from
+ a scale for consumer healthcare, sports and fitness applications.
+ \value BondManagement Bond Management UUID (service). The Bond Management service enables user to manage the
+ storage of bond information on Bluetooth devices.
+ \value ContinuousGlucoseMonitoring Continuous Glucose Monitoring UUID (service). The Continuous Glucose Monitoring service
+ exposes glucose data from a monitoring sensor for use in healthcare applications.
*/
/*!
@@ -218,8 +230,20 @@ Q_GLOBAL_STATIC_WITH_ARGS(QUuid, baseUuid, ("{00000000-0000-1000-8000-00805F9B34
\since 5.4
This enum is a convienience type for Bluetooth low energy service characteristics class UUIDs. Values of this type
- will be implicitly converted into a QBluetoothUuid when necessary.
-
+ will be implicitly converted into a QBluetoothUuid when necessary. The detailed type descriptions can be found
+ on \l{https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicsHome.aspx}{bluetooth.org}.
+
+ \value AerobicHeartRateLowerLimit The lower limit of the heart rate where the user improves his endurance while
+ exercising.
+ \value AerobicHeartRateUpperLimit The upper limit of the heart rate where the user improves his endurance while
+ exercising.
+ \value AerobicThreshold This characteristic states the first metabolic threshold.
+ \value Age This characteristic states the age of the user.
+ \value AnaerobicHeartRateLowerLimit The lower limit of the heart rate where the user enhances his anaerobic
+ tolerance while exercising.
+ \value AnaerobicHeartRateUpperLimit The upper limit of the heart rate where the user enhances his anaerobic
+ tolerance while exercising.
+ \value AnaerobicThreshold This characteristic states the second metabolic threshold.
\value AlertCategoryID Categories of alerts/messages.
\value AlertCategoryIDBitMask Categories of alerts/messages.
\value AlertLevel The level of an alert a device is to sound.
@@ -229,8 +253,14 @@ Q_GLOBAL_STATIC_WITH_ARGS(QUuid, baseUuid, ("{00000000-0000-1000-8000-00805F9B34
Client can write the command here to request the several
functions toward the server.
\value AlertStatus The Alert Status characteristic defines the Status of alert.
+ \value ApparentWindDirection The characteristic exposes the apparent wind direction. The apparent wind is
+ experienced by an observer in motion. This characteristic states the direction
+ of the wind with an angle measured clockwise relative to the observers heading.
+ \value ApparentWindSpeed The characteristic exposes the apparent wind speed in meters per second.
+ The apparent wind is experienced by an observer in motion.
\value Appearance The external appearance of this device. The values are composed
of a category (10-bits) and sub-categories (6-bits).
+ \value BarometricPressureTrend This characteristic exposes the trend the barometric pressure is taking.
\value BatteryLevel The current charge level of a battery. 100% represents fully charged
while 0% represents fully discharged.
\value BloodPressureFeature The Blood Pressure Feature characteristic is used to describe the supported
@@ -239,7 +269,12 @@ Q_GLOBAL_STATIC_WITH_ARGS(QUuid, baseUuid, ("{00000000-0000-1000-8000-00805F9B34
containing a Flags field, a Blood Pressure Measurement Compound Value field,
and contains additional fields such as Time Stamp, Pulse Rate and User ID
as determined by the contents of the Flags field.
- \value BodySensorLocation
+ \value BodyCompositionFeature This characteristic describes the available features in the \l BodyCompositionMeasurement
+ characteristic.
+ \value BodyCompositionMeasurement This characteristic describes the body composition such as muscle percentage
+ or the body water mass.
+ \value BodySensorLocation The Body Sensor Location characteristic describes the location of a sensor on
+ the body (e.g.: chest, finger or hand).
\value BootKeyboardInputReport The Boot Keyboard Input Report characteristic is used to transfer fixed format
and length Input Report data between a HID Host operating in Boot Protocol Mode
and a HID Service corresponding to a boot keyboard.
@@ -255,7 +290,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(QUuid, baseUuid, ("{00000000-0000-1000-8000-00805F9B34
is a variable length structure containing a Flags field and, based on the contents
of the Flags field, may contain one or more additional fields as shown in the tables
below.
- \value CurrentTime
+ \value CurrentTime The Current Time characteristic shows the same information as the \l ExactTime256
+ characteristic and information on timezone, DST and the method of update employed.
\value CyclingPowerControlPoint The Cycling Power Control Point characteristic is used to request a specific function
to be executed on the receiving device.
\value CyclingPowerFeature The CP Feature characteristic is used to report a list of features supported by
@@ -266,14 +302,28 @@ Q_GLOBAL_STATIC_WITH_ARGS(QUuid, baseUuid, ("{00000000-0000-1000-8000-00805F9B34
\value CyclingPowerVector The Cycling Power Vector characteristic is a variable length structure containing
a Flags fieldand based on the contents of the Flags field, may contain one or more
additional fields as shown in the table below.
+ \value DatabaseChangeIncrement
+ \value DateOfBirth This characteristic states the user's date of birth.
+ \value DateOfThresholdAssessment
\value DateTime The Date Time characteristic is used to represent time.
- \value DayDateTime
- \value DayOfWeek
- \value DeviceName
- \value DSTOffset
- \value ExactTime256
+ \value DayDateTime The Day Date Time characteristic presents the date, time and day of the week.
+ \value DayOfWeek The Day of Week characteristic describes the day of the week (Monday - Sunday).
+ \value DescriptorValueChanged This characteristic is related to the Environmental Sensing Service.
+ \value DeviceName The Device Name characteristic contains the name of the device.
+ \value DewPoint This characteristic states the dew point in degree Celsius.
+ \value DSTOffset The DST Offset characteristic describes the offset employed by the daylight saving time.
+ \value Elevation The Elevation characteristic states the elevation above/below sea level.
+ \value EmailAddress This characteristic states the email of the user.
+ \value ExactTime256 The Exact Time 256 characteristic describes the data, day and time
+ with an accuracy of 1/256th of a second.
+ \value FatBurnHeartRateLowerLimit The lower limit of the heart rate where the user maximizes the fat burn while exercising.
+ \value FatBurnHeartRateUpperLimit The upper limit of the heart rate where the user maximizes the fat burn while exercising.
\value FirmwareRevisionString The value of this characteristic is a UTF-8 string representing the firmware revision
for the firmware within the device.
+ \value FirstName This characteristic exposes the user's first name.
+ \value FiveZoneHeartRateLimits This characteristic contains the limits between the heart rate zones for the
+ 5-zone heart rate definition.
+ \value Gender This characteristic states the user's gender.
\value GlucoseFeature The Glucose Feature characteristic is used to describe the supported features
of the Server. When read, the Glucose Feature characteristic returns a value
that is used by a Client to determine the supported features of the Server.
@@ -282,20 +332,31 @@ Q_GLOBAL_STATIC_WITH_ARGS(QUuid, baseUuid, ("{00000000-0000-1000-8000-00805F9B34
of the Flags field, may contain a Time Offset field, Glucose Concentration field,
Type-Sample Location field and a Sensor Status Annunciation field.
\value GlucoseMeasurementContext
+ \value GustFactor The characteristic states a factor of wind speed increase between average wind speed in
+ maximum gust speed.
\value HardwareRevisionString The value of this characteristic is a UTF-8 string representing the hardware revision
for the hardware within the device.
+ \value MaximumRecommendedHeartRate This characteristic exposes the maximum recommended heart rate that limits exertion.
\value HeartRateControlPoint
+ \value HeartRateMax This characteristic states the maximum heart rate a user can reach in beats per minute.
\value HeartRateMeasurement
+ \value HeatIndex This characteristic provides a heat index in degree Celsius.
+ \value Height This characteristic states the user's height.
\value HIDControlPoint The HID Control Point characteristic is a control-point attribute that defines the
HID Commands when written.
\value HIDInformation The HID Information Characteristic returns the HID attributes when read.
+ \value HipCircumference This characteristic states the user's hip circumference in meters.
+ \value Humidity The characteristic states the humidity in percent.
\value IEEE1107320601RegulatoryCertificationDataList The value of the characteristic is an opaque structure listing
various regulatory and/or certification compliance items to which the device
claims adherence.
\value IntermediateCuffPressure This characteristic has the same format as the Blood Pressure Measurement
characteristic.
\value IntermediateTemperature The Intermediate Temperature characteristic has the same format as the
- Temperature Measurement characteristic
+ Temperature Measurement characteristic.
+ \value Irradiance This characteristic states the power of electromagnetic radiation in watt per square meter.
+ \value Language This characteristic contains the language definition based on ISO639-1.
+ \value LastName This characteristic states the user's last name.
\value LNControlPoint The LN Control Point characteristic is used to request a specific function
to be executed on the receiving device.
\value LNFeature The LN Feature characteristic is used to report a list of features supported
@@ -304,6 +365,11 @@ Q_GLOBAL_STATIC_WITH_ARGS(QUuid, baseUuid, ("{00000000-0000-1000-8000-00805F9B34
\value LocationAndSpeed The Location and Speed characteristic is a variable length structure containing
a Flags field and, based on the contents of the Flags field, may contain a combination
of data fields.
+ \value MagneticDeclination The characteristic contains the angle on the horizontal plane between the direction of
+ the (Geographic) True North and the Magnetic North, measured clockwise from True North
+ to Magnetic North.
+ \value MagneticFluxDensity2D This characteristic states the magnetic flux density on an x and y axis.
+ \value MagneticFluxDensity3D This characteristic states the magnetic flux density on an x, y and z axis.
\value ManufacturerNameString The value of this characteristic is a UTF-8 string representing the name of the
manufacturer of the device.
\value MeasurementInterval The Measurement Interval characteristic defines the time between measurements.
@@ -317,11 +383,14 @@ Q_GLOBAL_STATIC_WITH_ARGS(QUuid, baseUuid, ("{00000000-0000-1000-8000-00805F9B34
\value PeripheralPrivacyFlag
\value PnPID The PnP_ID characteristic returns its value when read using the GATT Characteristic
Value Read procedure.
+ \value PollenConcentration The characteristic exposes the pollen concentration count per cubic meter.
\value PositionQuality The Position Quality characteristic is a variable length structure containing a
- Flags field and at least one of the optional data
+ Flags field and at least one of the optional data.
+ \value Pressure The Pressure characteristic states the value of a pressure sensor.
\value ProtocolMode The Protocol Mode characteristic is used to expose the current protocol mode of
the HID Service with which it is associated, or to set the desired protocol
mode of the HID Service.
+ \value Rainfall This characteristic exposes the rainfall in meters.
\value ReconnectionAddress The Information included in this page is informative. The normative descriptions
are contained in the applicable specification.
\value RecordAccessControlPoint This control point is used with a service to provide basic management functionality
@@ -329,6 +398,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QUuid, baseUuid, ("{00000000-0000-1000-8000-00805F9B34
\value ReferenceTimeInformation
\value Report The Report characteristic is used to exchange data between a HID Device and a HID Host.
\value ReportMap Only a single instance of this characteristic exists as part of a HID Service.
+ \value RestingHeartRate This characteristic exposes the lowest heart rate a user can reach.
\value RingerControlPoint The Ringer Control Point characteristic defines the Control Point of Ringer.
\value RingerSetting The Ringer Setting characteristic defines the Setting of the Ringer.
\value RSCFeature The RSC (Running Speed and Cadence) Feature characteristic is used to describe the
@@ -347,26 +417,46 @@ Q_GLOBAL_STATIC_WITH_ARGS(QUuid, baseUuid, ("{00000000-0000-1000-8000-00805F9B34
\value ServiceChanged
\value SoftwareRevisionString The value of this characteristic is a UTF-8 string representing the software
revision for the software within the device.
+ \value SportTypeForAerobicAnaerobicThresholds This characteristic is used to preset the various Aerobic and Anaerobic
+ threshold characteristics based on the to-be-performed sport type.
\value SupportedNewAlertCategory Category that the server supports for new alert.
\value SupportedUnreadAlertCategory Category that the server supports for unread alert.
\value SystemID If the system ID is based of a Bluetooth Device Address with a Company Identifier
(OUI) is 0x123456 and the Company Assigned Identifier is 0x9ABCDE, then the System
Identifier is required to be 0x123456FFFE9ABCDE.
+ \value Temperature The value of this characteristic states the temperature in degree Celsius.
\value TemperatureMeasurement The Temperature Measurement characteristic is a variable length structure containing
a Flags field, a Temperature Measurement Value field and, based upon the contents of
the Flags field, optionally a Time Stamp field and/or a Temperature Type field.
\value TemperatureType The Temperature Type characteristic is an enumeration that indicates where the
temperature was measured.
+ \value ThreeZoneHeartRateLimits This characteristic contains the limits between the heart rate zones for the
+ 3-zone heart rate definition.
\value TimeAccuracy
\value TimeSource
\value TimeUpdateControlPoint
\value TimeUpdateState
\value TimeWithDST
\value TimeZone
+ \value TrueWindDirection The characteristic states the direction of the wind with an angle measured clockwise
+ relative to (Geographic) True North. A wind coming from the east is given as 90 degrees.
+ \value TrueWindSpeed The characteristic states the wind speed in meters per seconds.
+ \value TwoZoneHeartRateLimits This characteristic contains the limits between the heart rate zones for the
+ 2-zone heart rate definition.
\value TxPowerLevel The value of the characteristic is a signed 8 bit integer that has a fixed point
exponent of 0.
\value UnreadAlertStatus This characteristic shows how many numbers of unread alerts exist in the specific
category in the device.
+ \value UserControlPoint
+ \value UserIndex This characteristic states the index of the user.
+ \value UVIndex This characteristic exposes the UV index.
+ \value VO2Max This characteristic exposes the maximum Oxygen uptake of a user.
+ \value WaistCircumference This characteristic states the user's waist circumference in meters.
+ \value Weight This characteristic exposes the user's weight in kilograms.
+ \value WeightMeasurement This characteristic provides weight related data such as BMI or the user's weight.
+ \value WeightScaleFeature This characteristic describes the available data in the \l WeightMeasurement
+ characteristic.
+ \value WindChill This characteristic states the wind chill in degree Celsius
*/
/*!
@@ -376,7 +466,8 @@ Q_GLOBAL_STATIC_WITH_ARGS(QUuid, baseUuid, ("{00000000-0000-1000-8000-00805F9B34
Descriptors are attributes that describe Bluetooth Low Energy characteristic values.
This enum is a convienience type for descriptor class UUIDs. Values of this type
- will be implicitly converted into a QBluetoothUuid when necessary.
+ will be implicitly converted into a QBluetoothUuid when necessary. The detailed type specifications
+ can be found on \l{https://developer.bluetooth.org/gatt/descriptors/Pages/DescriptorsHomePage.aspx}{bluetooth.org}.
\value CharacteristicExtendedProperties Descriptor defines additional Characteristic Properties.
The existence of this descriptor is indicated by the
@@ -395,6 +486,14 @@ Q_GLOBAL_STATIC_WITH_ARGS(QUuid, baseUuid, ("{00000000-0000-1000-8000-00805F9B34
\value ReportReference Mapping information in the form of a Report ID and Report Type which maps the
current parent characteristic to the Report ID(s) and Report Type (s) defined
within the Report Map characteristic.
+ \value EnvironmentalSensingConfiguration Descriptor defines how multiple trigger settings descriptors are combined. Therefore
+ this descriptor works together with the \l EnvironmentalSensingTriggerSetting descriptor
+ to define the conditions under which the associated characteristic value can be notified.
+ \value EnvironmentalSensingMeasurement Descriptor defines the additional information for the environmental sensing server
+ such as the intended application, sampling functions or measurement period and uncertainty.
+ \value EnvironmentalSensingTriggerSetting Descriptor defines under which conditions an environmental sensing server (ESS) should
+ trigger notifications. Examples of such conditions are certain thresholds being reached
+ or timers having expired. This implies that the ESS characteristic supports notifications.
\value UnknownDescriptorType The descriptor type is unknown.
*/
@@ -709,6 +808,12 @@ QString QBluetoothUuid::serviceClassToString(QBluetoothUuid::ServiceClassUuid uu
case QBluetoothUuid::CyclingSpeedAndCadence: return QBluetoothServiceDiscoveryAgent::tr("Cycling Speed and Cadance");
case QBluetoothUuid::CyclingPower: return QBluetoothServiceDiscoveryAgent::tr("Cycling Power");
case QBluetoothUuid::LocationAndNavigation: return QBluetoothServiceDiscoveryAgent::tr("Location and Navigation");
+ case QBluetoothUuid::EnvironmentalSensing: return QBluetoothServiceDiscoveryAgent::tr("Environmental Sensing");
+ case QBluetoothUuid::BodyComposition: return QBluetoothServiceDiscoveryAgent::tr("Body Composition");
+ case QBluetoothUuid::UserData: return QBluetoothServiceDiscoveryAgent::tr("User Data");
+ case QBluetoothUuid::WeightScale: return QBluetoothServiceDiscoveryAgent::tr("Weight Scale");
+ case QBluetoothUuid::BondManagement: return QBluetoothServiceDiscoveryAgent::tr("Bond Management");
+ case QBluetoothUuid::ContinuousGlucoseMonitoring: return QBluetoothServiceDiscoveryAgent::tr("Continuous Glucose Monitoring");
default:
break;
}
@@ -872,6 +977,74 @@ QString QBluetoothUuid::characteristicToString(CharacteristicType uuid)
case QBluetoothUuid::PositionQuality: return QBluetoothServiceDiscoveryAgent::tr("Position Quality");
case QBluetoothUuid::LNFeature: return QBluetoothServiceDiscoveryAgent::tr("LN Feature");
case QBluetoothUuid::LNControlPoint: return QBluetoothServiceDiscoveryAgent::tr("LN Control Point");
+ case QBluetoothUuid::MagneticDeclination:
+ return QBluetoothServiceDiscoveryAgent::tr("Magnetic Declination", "angle between geographic and magnetic north");
+ case QBluetoothUuid::Elevation: return QBluetoothServiceDiscoveryAgent::tr("Elevation", "above/below sea level");
+ case QBluetoothUuid::Pressure: return QBluetoothServiceDiscoveryAgent::tr("Pressure");
+ case QBluetoothUuid::Temperature: return QBluetoothServiceDiscoveryAgent::tr("Temperature");
+ case QBluetoothUuid::Humidity: return QBluetoothServiceDiscoveryAgent::tr("Humidity");
+ case QBluetoothUuid::TrueWindSpeed: return QBluetoothServiceDiscoveryAgent::tr("True Wind Speed", "wind speed while standing");
+ case QBluetoothUuid::TrueWindDirection : return QBluetoothServiceDiscoveryAgent::tr("True Wind Direction");
+ case QBluetoothUuid::ApparentWindSpeed:
+ return QBluetoothServiceDiscoveryAgent::tr("Apparent Wind Speed", "wind speed while observer is moving");
+ case QBluetoothUuid::ApparentWindDirection: return QBluetoothServiceDiscoveryAgent::tr("Apparent Wind Direction");
+ case QBluetoothUuid::GustFactor:
+ return QBluetoothServiceDiscoveryAgent::tr("Gust Factor", "factor by which wind gust is stronger than average wind");
+ case QBluetoothUuid::PollenConcentration: return QBluetoothServiceDiscoveryAgent::tr("Pollen Concentration");
+ case QBluetoothUuid::UVIndex: return QBluetoothServiceDiscoveryAgent::tr("UV Index");
+ case QBluetoothUuid::Irradiance: return QBluetoothServiceDiscoveryAgent::tr("Irradiance");
+ case QBluetoothUuid::Rainfall: return QBluetoothServiceDiscoveryAgent::tr("Rainfall");
+ case QBluetoothUuid::WindChill: return QBluetoothServiceDiscoveryAgent::tr("Wind Chill");
+ case QBluetoothUuid::HeatIndex: return QBluetoothServiceDiscoveryAgent::tr("Heat Index");
+ case QBluetoothUuid::DewPoint: return QBluetoothServiceDiscoveryAgent::tr("Dew Point");
+ case QBluetoothUuid::DescriptorValueChanged:
+ return QBluetoothServiceDiscoveryAgent::tr("Descriptor Value Changed", "Environmental sensing related");
+ case QBluetoothUuid::AerobicHeartRateLowerLimit:
+ return QBluetoothServiceDiscoveryAgent::tr("Aerobic Heart Rate Lower Limit");
+ case QBluetoothUuid::AerobicHeartRateUpperLimit:
+ return QBluetoothServiceDiscoveryAgent::tr("Aerobic Heart Rate Upper Limit");
+ case QBluetoothUuid::AerobicThreshold: return QBluetoothServiceDiscoveryAgent::tr("Aerobic Threshold");
+ case QBluetoothUuid::Age: return QBluetoothServiceDiscoveryAgent::tr("Age", "age of person");
+ case QBluetoothUuid::AnaerobicHeartRateLowerLimit:
+ return QBluetoothServiceDiscoveryAgent::tr("Anaerobic Heart Rate Lower Limit");
+ case QBluetoothUuid::AnaerobicHeartRateUpperLimit:
+ return QBluetoothServiceDiscoveryAgent::tr("Anaerobic Heart Rate Upper Limit");
+ case QBluetoothUuid::AnaerobicThreshold: return QBluetoothServiceDiscoveryAgent::tr("Anaerobic Threshold");
+ case QBluetoothUuid::DateOfBirth: return QBluetoothServiceDiscoveryAgent::tr("Date Of Birth");
+ case QBluetoothUuid::DateOfThresholdAssessment: return QBluetoothServiceDiscoveryAgent::tr("Date Of Threshold Assessment");
+ case QBluetoothUuid::EmailAddress: return QBluetoothServiceDiscoveryAgent::tr("Email Address");
+ case QBluetoothUuid::FatBurnHeartRateLowerLimit:
+ return QBluetoothServiceDiscoveryAgent::tr("Fat Burn Heart Rate Lower Limit");
+ case QBluetoothUuid::FatBurnHeartRateUpperLimit:
+ return QBluetoothServiceDiscoveryAgent::tr("Fat Burn Heart Rate Upper Limit");
+ case QBluetoothUuid::FirstName: return QBluetoothServiceDiscoveryAgent::tr("First Name");
+ case QBluetoothUuid::FiveZoneHeartRateLimits: return QBluetoothServiceDiscoveryAgent::tr("5-Zone Heart Rate Limits");
+ case QBluetoothUuid::Gender: return QBluetoothServiceDiscoveryAgent::tr("Gender");
+ case QBluetoothUuid::HeartRateMax: return QBluetoothServiceDiscoveryAgent::tr("Heart Rate Maximum");
+ case QBluetoothUuid::Height: return QBluetoothServiceDiscoveryAgent::tr("Height", "of a person");
+ case QBluetoothUuid::HipCircumference: return QBluetoothServiceDiscoveryAgent::tr("Hip Circumference");
+ case QBluetoothUuid::LastName: return QBluetoothServiceDiscoveryAgent::tr("Last Name");
+ case QBluetoothUuid::MaximumRecommendedHeartRate:
+ return QBluetoothServiceDiscoveryAgent::tr("Maximum Recommended Heart Rate");
+ case QBluetoothUuid::RestingHeartRate: return QBluetoothServiceDiscoveryAgent::tr("Resting Heart Rate");
+ case QBluetoothUuid::SportTypeForAerobicAnaerobicThresholds:
+ return QBluetoothServiceDiscoveryAgent::tr("Sport Type For Aerobic/Anaerobic Thresholds");
+ case QBluetoothUuid::ThreeZoneHeartRateLimits: return QBluetoothServiceDiscoveryAgent::tr("3-Zone Heart Rate Limits");
+ case QBluetoothUuid::TwoZoneHeartRateLimits: return QBluetoothServiceDiscoveryAgent::tr("2-Zone Heart Rate Limits");
+ case QBluetoothUuid::VO2Max: return QBluetoothServiceDiscoveryAgent::tr("Oxygen Uptake");
+ case QBluetoothUuid::WaistCircumference: return QBluetoothServiceDiscoveryAgent::tr("Waist Circumference");
+ case QBluetoothUuid::Weight: return QBluetoothServiceDiscoveryAgent::tr("Weight");
+ case QBluetoothUuid::DatabaseChangeIncrement:
+ return QBluetoothServiceDiscoveryAgent::tr("Database Change Increment", "Environmental sensing related");
+ case QBluetoothUuid::UserIndex: return QBluetoothServiceDiscoveryAgent::tr("User Index");
+ case QBluetoothUuid::BodyCompositionFeature: return QBluetoothServiceDiscoveryAgent::tr("Body Composition Feature");
+ case QBluetoothUuid::BodyCompositionMeasurement: return QBluetoothServiceDiscoveryAgent::tr("Body Composition Measurement");
+ case QBluetoothUuid::WeightMeasurement: return QBluetoothServiceDiscoveryAgent::tr("Weight Measurement");
+ case QBluetoothUuid::UserControlPoint: return QBluetoothServiceDiscoveryAgent::tr("User Control Point");
+ case QBluetoothUuid::MagneticFluxDensity2D: return QBluetoothServiceDiscoveryAgent::tr("Magnetic Flux Density 2D");
+ case QBluetoothUuid::MagneticFluxDensity3D: return QBluetoothServiceDiscoveryAgent::tr("Magnetic Flux Density 3D");
+ case QBluetoothUuid::Language: return QBluetoothServiceDiscoveryAgent::tr("Language");
+ case QBluetoothUuid::BarometricPressureTrend: return QBluetoothServiceDiscoveryAgent::tr("Barometric Pressure Trend");
default:
break;
}
@@ -883,7 +1056,7 @@ QString QBluetoothUuid::characteristicToString(CharacteristicType uuid)
Returns a human-readable and translated name for the given descriptor type
represented by \a uuid.
- \sa QBluetoothUuid::CharacteristicType
+ \sa QBluetoothUuid::DescriptorType
\since 5.4
*/
@@ -908,6 +1081,12 @@ QString QBluetoothUuid::descriptorToString(QBluetoothUuid::DescriptorType uuid)
return QBluetoothServiceDiscoveryAgent::tr("External Report Reference");
case QBluetoothUuid::ReportReference:
return QBluetoothServiceDiscoveryAgent::tr("Report Reference");
+ case QBluetoothUuid::EnvironmentalSensingConfiguration:
+ return QBluetoothServiceDiscoveryAgent::tr("Environmental Sensing Configuration");
+ case QBluetoothUuid::EnvironmentalSensingMeasurement:
+ return QBluetoothServiceDiscoveryAgent::tr("Environmental Sensing Measurement");
+ case QBluetoothUuid::EnvironmentalSensingTriggerSetting:
+ return QBluetoothServiceDiscoveryAgent::tr("Environmental Sensing Trigger Setting");
default:
break;
}
diff --git a/src/bluetooth/qbluetoothuuid.h b/src/bluetooth/qbluetoothuuid.h
index 2c035ffa..94e14d0e 100644
--- a/src/bluetooth/qbluetoothuuid.h
+++ b/src/bluetooth/qbluetoothuuid.h
@@ -166,6 +166,13 @@ public:
CyclingSpeedAndCadence = 0x1816,
CyclingPower = 0x1818,
LocationAndNavigation = 0x1819,
+ EnvironmentalSensing = 0x181a,
+ BodyComposition = 0x181b,
+ UserData = 0x181c,
+ WeightScale = 0x181d,
+ BondManagement = 0x181e,
+ ContinuousGlucoseMonitoring = 0x181f,
+
};
enum CharacteristicType {
@@ -180,21 +187,28 @@ public:
DateTime = 0x2a08,
DayOfWeek = 0x2a09,
DayDateTime = 0x2a0a,
+ /* 0x2a0b not defined */
ExactTime256 = 0x2a0c,
DSTOffset = 0x2a0d,
TimeZone = 0x2a0e,
LocalTimeInformation = 0x2a0f,
+ /* 0x2a10 not defined */
TimeWithDST = 0x2a11,
TimeAccuracy = 0x2a12,
TimeSource = 0x2a13,
ReferenceTimeInformation = 0x2a14,
+ /* 0x2a15 not defined */
TimeUpdateControlPoint = 0x2a16,
TimeUpdateState = 0x2a17,
GlucoseMeasurement = 0x2a18,
BatteryLevel = 0x2a19,
+ /* 0x2a1a not defined */
+ /* 0x2a1b not defined */
TemperatureMeasurement = 0x2a1c,
TemperatureType = 0x2a1d,
IntermediateTemperature = 0x2a1e,
+ /* 0x2a1f not defined */
+ /* 0x2a20 not defined */
MeasurementInterval = 0x2a21,
BootKeyboardInputReport = 0x2a22,
SystemID = 0x2a23,
@@ -206,6 +220,11 @@ public:
ManufacturerNameString = 0x2a29,
IEEE1107320601RegulatoryCertificationDataList = 0x2a2a,
CurrentTime = 0x2a2b,
+ MagneticDeclination = 0x2a2c,
+ /* 0x2a2d not defined */
+ /* 0x2a2e not defined */
+ /* 0x2a2f not defined */
+ /* 0x2a30 not defined */
ScanRefresh = 0x2a31,
BootKeyboardOutputReport = 0x2a32,
BootMouseInputReport = 0x2a33,
@@ -215,6 +234,11 @@ public:
HeartRateMeasurement = 0x2a37,
BodySensorLocation = 0x2a38,
HeartRateControlPoint = 0x2a39,
+ /* 0x2a3a not defined */
+ /* 0x2a3b not defined */
+ /* 0x2a3c not defined */
+ /* 0x2a3d not defined */
+ /* 0x2a3e not defined */
AlertStatus = 0x2a3f,
RingerControlPoint = 0x2a40,
RingerSetting = 0x2a41,
@@ -238,9 +262,19 @@ public:
RSCMeasurement = 0x2a53,
RSCFeature = 0x2a54,
SCControlPoint = 0x2a55,
+ /* 0x2a56 not defined */
+ /* 0x2a57 not defined */
+ /* 0x2a58 not defined */
+ /* 0x2a59 not defined */
+ /* 0x2a5a not defined */
CSCMeasurement = 0x2a5b,
CSCFeature = 0x2a5c,
SensorLocation = 0x2a5d,
+ /* 0x2a5e not defined */
+ /* 0x2a5f not defined */
+ /* 0x2a60 not defined */
+ /* 0x2a61 not defined */
+ /* 0x2a62 not defined */
CyclingPowerMeasurement = 0x2a63,
CyclingPowerVector = 0x2a64,
CyclingPowerFeature = 0x2a65,
@@ -250,6 +284,62 @@ public:
PositionQuality = 0x2a69,
LNFeature = 0x2a6a,
LNControlPoint = 0x2a6b,
+ Elevation = 0x2a6c,
+ Pressure = 0x2a6d,
+ Temperature = 0x2a6e,
+ Humidity = 0x2a6f,
+ TrueWindSpeed = 0x2a70,
+ TrueWindDirection = 0x2a71,
+ ApparentWindSpeed = 0x2a72,
+ ApparentWindDirection = 0x2a73,
+ GustFactor = 0x2a74,
+ PollenConcentration = 0x2a75,
+ UVIndex = 0x2a76,
+ Irradiance = 0x2a77,
+ Rainfall = 0x2a78,
+ WindChill = 0x2a79,
+ HeatIndex = 0x2a7a,
+ DewPoint = 0x2a7b,
+ /* 0x2a7c not defined */
+ DescriptorValueChanged = 0x2a7d,
+ AerobicHeartRateLowerLimit = 0x2a7e,
+ AerobicThreshold = 0x2a7f,
+ Age = 0x2a80,
+ AnaerobicHeartRateLowerLimit = 0x2a81,
+ AnaerobicHeartRateUpperLimit = 0x2a82,
+ AnaerobicThreshold = 0x2a83,
+ AerobicHeartRateUpperLimit = 0x2a84,
+ DateOfBirth = 0x2a85,
+ DateOfThresholdAssessment = 0x2a86,
+ EmailAddress = 0x2a87,
+ FatBurnHeartRateLowerLimit = 0x2a88,
+ FatBurnHeartRateUpperLimit = 0x2a89,
+ FirstName = 0x2a8a,
+ FiveZoneHeartRateLimits = 0x2a8b,
+ Gender = 0x2a8c,
+ HeartRateMax = 0x2a8d,
+ Height = 0x2a8e,
+ HipCircumference = 0x2a8f,
+ LastName = 0x2a90,
+ MaximumRecommendedHeartRate = 0x2a91,
+ RestingHeartRate = 0x2a92,
+ SportTypeForAerobicAnaerobicThresholds = 0x2a93,
+ ThreeZoneHeartRateLimits = 0x2a94,
+ TwoZoneHeartRateLimits = 0x2a95,
+ VO2Max = 0x2a96,
+ WaistCircumference = 0x2a97,
+ Weight = 0x2a98,
+ DatabaseChangeIncrement = 0x2a99,
+ UserIndex = 0x2a9a,
+ BodyCompositionFeature = 0x2a9b,
+ BodyCompositionMeasurement = 0x2a9c,
+ WeightMeasurement = 0x2a9d,
+ WeightScaleFeature = 0x2a9e,
+ UserControlPoint = 0x2a9f,
+ MagneticFluxDensity2D = 0x2aa0,
+ MagneticFluxDensity3D = 0x2aa1,
+ Language = 0x2aa2,
+ BarometricPressureTrend = 0x2aa3
};
enum DescriptorType {
@@ -262,7 +352,12 @@ public:
CharacteristicAggregateFormat = 0x2905,
ValidRange = 0x2906,
ExternalReportReference = 0x2907,
- ReportReference = 0x2908
+ ReportReference = 0x2908,
+ /* 0x2909 not defined */
+ /* 0x290a not defined */
+ EnvironmentalSensingConfiguration = 0x290b,
+ EnvironmentalSensingMeasurement = 0x290c,
+ EnvironmentalSensingTriggerSetting = 0x290d
};
QBluetoothUuid();
diff --git a/src/bluetooth/qlowenergycharacteristic.cpp b/src/bluetooth/qlowenergycharacteristic.cpp
index 2f8bd6fa..91e9d94d 100644
--- a/src/bluetooth/qlowenergycharacteristic.cpp
+++ b/src/bluetooth/qlowenergycharacteristic.cpp
@@ -195,9 +195,11 @@ QLowEnergyCharacteristic::PropertyTypes QLowEnergyCharacteristic::properties() c
\l {QLowEnergyService::writeCharacteristic()}{write operation} or when an update
notification is received.
- The returned \l QByteArray is empty if the characteristic does not have the
- \l {QLowEnergyCharacteristic::Read}{read permission}. However, a non-readable
- characteristic may obtain a non-empty value via a related notification or write operation.
+ The returned \l QByteArray always remains empty if the characteristic does not
+ have the \l {QLowEnergyCharacteristic::Read}{read permission}. In such cases only
+ the \l QLowEnergyService::characteristicChanged() or
+ \l QLowEnergyService::characteristicWritten() may provice information about the
+ value of this characteristic.
*/
QByteArray QLowEnergyCharacteristic::value() const
{
diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp
index 25bd35d7..e1b668ca 100644
--- a/src/bluetooth/qlowenergycontroller_android.cpp
+++ b/src/bluetooth/qlowenergycontroller_android.cpp
@@ -165,7 +165,7 @@ void QLowEnergyControllerPrivate::writeCharacteristic(
const QSharedPointer<QLowEnergyServicePrivate> service,
const QLowEnergyHandle charHandle,
const QByteArray &newValue,
- bool /*writeWithResponse*/)
+ bool writeWithResponse)
{
//TODO don't ignore WriteWithResponse, right now we assume responses
Q_ASSERT(!service.isNull());
@@ -182,9 +182,11 @@ void QLowEnergyControllerPrivate::writeCharacteristic(
bool result = false;
if (hub) {
qCDebug(QT_BT_ANDROID) << "Write characteristic with handle " << charHandle
- << newValue.toHex() << "(service:" << service->uuid << ")";
- result = hub->javaObject().callMethod<jboolean>("writeCharacteristic", "(I[B)Z",
- charHandle, payload);
+ << newValue.toHex() << "(service:" << service->uuid
+ << ", writeWithResponse:" << writeWithResponse << ")";
+ result = hub->javaObject().callMethod<jboolean>("writeCharacteristic", "(I[BI)Z",
+ charHandle, payload,
+ writeWithResponse ? QLowEnergyService::WriteWithResponse : QLowEnergyService::WriteWithoutResponse);
}
if (env->ExceptionOccurred()) {
@@ -429,7 +431,10 @@ void QLowEnergyControllerPrivate::characteristicWritten(
return;
}
- updateValueOfCharacteristic(charHandle, data, false);
+ // only update cache when property is readable. Otherwise it remains
+ // empty.
+ if (characteristic.properties() & QLowEnergyCharacteristic::Read)
+ updateValueOfCharacteristic(charHandle, data, false);
emit service->characteristicWritten(characteristic, data);
}
@@ -477,7 +482,10 @@ void QLowEnergyControllerPrivate::characteristicChanged(
return;
}
- updateValueOfCharacteristic(characteristic.attributeHandle(),
+ // only update cache when property is readable. Otherwise it remains
+ // empty.
+ if (characteristic.properties() & QLowEnergyCharacteristic::Read)
+ updateValueOfCharacteristic(characteristic.attributeHandle(),
data, false);
emit service->characteristicChanged(characteristic, data);
}
diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp
index 55acfc36..63de6edb 100644
--- a/src/bluetooth/qlowenergycontroller_bluez.cpp
+++ b/src/bluetooth/qlowenergycontroller_bluez.cpp
@@ -908,8 +908,9 @@ void QLowEnergyControllerPrivate::processReply(
const QByteArray newValue = request.reference2.toByteArray();
if (!descriptorHandle) {
- updateValueOfCharacteristic(charHandle, newValue, NEW_VALUE);
QLowEnergyCharacteristic ch(service, charHandle);
+ if (ch.properties() & QLowEnergyCharacteristic::Read)
+ updateValueOfCharacteristic(charHandle, newValue, NEW_VALUE);
emit service->characteristicWritten(ch, newValue);
} else {
updateValueOfDescriptor(charHandle, descriptorHandle, newValue, NEW_VALUE);
@@ -976,8 +977,9 @@ void QLowEnergyControllerPrivate::processReply(
attrHandle, newValue, NEW_VALUE);
emit service->descriptorWritten(descriptor, newValue);
} else {
- updateValueOfCharacteristic(attrHandle, newValue, NEW_VALUE);
QLowEnergyCharacteristic ch(service, attrHandle);
+ if (ch.properties() & QLowEnergyCharacteristic::Read)
+ updateValueOfCharacteristic(attrHandle, newValue, NEW_VALUE);
emit service->characteristicWritten(ch, newValue);
}
}
@@ -1236,7 +1238,8 @@ void QLowEnergyControllerPrivate::processUnsolicitedReply(const QByteArray &payl
const QLowEnergyCharacteristic ch = characteristicForHandle(changedHandle);
if (ch.isValid() && ch.handle() == changedHandle) {
- updateValueOfCharacteristic(ch.attributeHandle(), payload.mid(3), NEW_VALUE);
+ if (ch.properties() & QLowEnergyCharacteristic::Read)
+ updateValueOfCharacteristic(ch.attributeHandle(), payload.mid(3), NEW_VALUE);
emit ch.d_ptr->characteristicChanged(ch, payload.mid(3));
} else {
qCWarning(QT_BT_BLUEZ) << "Cannot find matching characteristic for "
diff --git a/src/bluetooth/qlowenergycontroller_osx.mm b/src/bluetooth/qlowenergycontroller_osx.mm
index 48e144cc..a0ad49de 100644
--- a/src/bluetooth/qlowenergycontroller_osx.mm
+++ b/src/bluetooth/qlowenergycontroller_osx.mm
@@ -71,12 +71,12 @@ typedef QSharedPointer<QLowEnergyServicePrivate> ServicePrivate;
// Convenience function, can return a smart pointer that 'isNull'.
ServicePrivate qt_createLEService(QLowEnergyControllerPrivateOSX *controller, CBService *cbService, bool included)
{
- Q_ASSERT_X(controller, "createLEService()", "invalid controller (null)");
- Q_ASSERT_X(cbService, "createLEService()", "invalid service (nil)");
+ Q_ASSERT_X(controller, Q_FUNC_INFO, "invalid controller (null)");
+ Q_ASSERT_X(cbService, Q_FUNC_INFO, "invalid service (nil)");
CBUUID *const cbUuid = cbService.UUID;
if (!cbUuid) {
- qCDebug(QT_BT_OSX) << "createLEService(), invalid service, "
+ qCDebug(QT_BT_OSX) << Q_FUNC_INFO << "invalid service, "
"UUID is nil";
return ServicePrivate();
}
@@ -133,15 +133,13 @@ QLowEnergyControllerPrivateOSX::QLowEnergyControllerPrivateOSX(QLowEnergyControl
addressType(QLowEnergyController::PublicAddress)
{
// This is the "wrong" constructor - no valid device UUID to connect later.
- Q_ASSERT_X(q, "QLowEnergyControllerPrivate", "invalid q_ptr (null)");
+ Q_ASSERT_X(q, Q_FUNC_INFO, "invalid q_ptr (null)");
// We still create a manager, to simplify error handling later.
centralManager.reset([[ObjCCentralManager alloc] initWithDelegate:this]);
if (!centralManager) {
- qCWarning(QT_BT_OSX) << "QBluetoothLowEnergyControllerPrivateOSX::"
- "QBluetoothLowEnergyControllerPrivateOSX(), "
- "failed to initialize central manager";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO
+ << "failed to initialize central manager";
}
-
}
QLowEnergyControllerPrivateOSX::QLowEnergyControllerPrivateOSX(QLowEnergyController *q,
@@ -153,12 +151,11 @@ QLowEnergyControllerPrivateOSX::QLowEnergyControllerPrivateOSX(QLowEnergyControl
controllerState(QLowEnergyController::UnconnectedState),
addressType(QLowEnergyController::PublicAddress)
{
- Q_ASSERT_X(q, "QLowEnergyControllerPrivateOSX", "invalid q_ptr (null)");
+ Q_ASSERT_X(q, Q_FUNC_INFO, "invalid q_ptr (null)");
centralManager.reset([[ObjCCentralManager alloc] initWithDelegate:this]);
if (!centralManager) {
- qCWarning(QT_BT_OSX) << "QBluetoothLowEnergyControllerPrivateOSX::"
- "QBluetoothLowEnergyControllerPrivateOSX(), "
- "failed to initialize central manager";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO
+ << "failed to initialize central manager";
}
}
@@ -184,7 +181,7 @@ void QLowEnergyControllerPrivateOSX::LEnotSupported()
void QLowEnergyControllerPrivateOSX::connectSuccess()
{
Q_ASSERT_X(controllerState == QLowEnergyController::ConnectingState,
- "connectSuccess", "invalid state");
+ Q_FUNC_INFO, "invalid state");
controllerState = QLowEnergyController::ConnectedState;
@@ -197,7 +194,7 @@ void QLowEnergyControllerPrivateOSX::connectSuccess()
void QLowEnergyControllerPrivateOSX::serviceDiscoveryFinished(LEServices services)
{
Q_ASSERT_X(controllerState == QLowEnergyController::DiscoveringState,
- "serviceDiscoveryFinished", "invalid state");
+ Q_FUNC_INFO, "invalid state");
using namespace OSXBluetooth;
@@ -219,8 +216,8 @@ void QLowEnergyControllerPrivateOSX::serviceDiscoveryFinished(LEServices service
continue;
if (discoveredServices.contains(newService->uuid)) {
// It's a bit stupid we first created it ...
- qCDebug(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::serviceDiscoveryFinished(), "
- << "discovered service with a duplicated UUID "<<newService->uuid;
+ qCDebug(QT_BT_OSX) << Q_FUNC_INFO << "discovered service with a duplicated UUID "
+ << newService->uuid;
continue;
}
discoveredServices.insert(newService->uuid, newService);
@@ -271,8 +268,7 @@ void QLowEnergyControllerPrivateOSX::serviceDiscoveryFinished(LEServices service
toVisitNext.resetWithoutRetain([[NSMutableArray alloc] init]);
}
} else {
- qCDebug(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::serviceDiscoveryFinished(), "
- "no services found";
+ qCDebug(QT_BT_OSX) << Q_FUNC_INFO << "no services found";
}
foreach (const QBluetoothUuid &uuid, discoveredServices.keys()) {
@@ -288,14 +284,13 @@ void QLowEnergyControllerPrivateOSX::serviceDiscoveryFinished(LEServices service
void QLowEnergyControllerPrivateOSX::serviceDetailsDiscoveryFinished(LEService service)
{
- Q_ASSERT_X(!service.isNull(), "serviceDetailsDiscoveryFinished",
- "invalid service (null)");
+ Q_ASSERT_X(!service.isNull(), Q_FUNC_INFO, "invalid service (null)");
QT_BT_MAC_AUTORELEASEPOOL;
if (!discoveredServices.contains(service->uuid)) {
- qCDebug(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::serviceDetailsDiscoveryFinished(), "
- "unknown service uuid: " << service->uuid;
+ qCDebug(QT_BT_OSX) << Q_FUNC_INFO << "unknown service uuid: "
+ << service->uuid;
return;
}
@@ -311,24 +306,24 @@ void QLowEnergyControllerPrivateOSX::serviceDetailsDiscoveryFinished(LEService s
void QLowEnergyControllerPrivateOSX::characteristicWriteNotification(QLowEnergyHandle charHandle,
const QByteArray &value)
{
- Q_ASSERT_X(charHandle, "characteristicWriteNotification",
- "invalid characteristic handle(0)");
+ Q_ASSERT_X(charHandle, Q_FUNC_INFO, "invalid characteristic handle(0)");
ServicePrivate service(serviceForHandle(charHandle));
if (service.isNull()) {
- qCWarning(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::characteristicWriteNotification(), "
- "can not find service for characteristic handle " << charHandle;
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "can not find service for characteristic handle "
+ << charHandle;
return;
}
QLowEnergyCharacteristic characteristic(characteristicForHandle(charHandle));
if (!characteristic.isValid()) {
- qCWarning(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::characteristicWriteNotification(), "
- "unknown characteristic";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "unknown characteristic";
return;
}
- updateValueOfCharacteristic(charHandle, value, false);
+ if (characteristic.properties() & QLowEnergyCharacteristic::Read)
+ updateValueOfCharacteristic(charHandle, value, false);
+
emit service->characteristicWritten(characteristic, value);
}
@@ -337,35 +332,37 @@ void QLowEnergyControllerPrivateOSX::characteristicUpdateNotification(QLowEnergy
{
// TODO: write/update notifications are quite similar (except asserts/warnings messages
// and different signals emitted). Merge them into one function?
- Q_ASSERT_X(charHandle, "characteristicUpdateNotification",
- "invalid characteristic handle(0)");
+ Q_ASSERT_X(charHandle, Q_FUNC_INFO, "invalid characteristic handle(0)");
ServicePrivate service(serviceForHandle(charHandle));
if (service.isNull()) {
- qCWarning(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::characteristicUpdateNotification(), "
- "can not find service for characteristic handle " << charHandle;
+ // This can be an error (no characteristic found for this handle),
+ // it can also be that we set notify value before the service
+ // was reported (serviceDetailsDiscoveryFinished) - this happens,
+ // if we read a descriptor (characteristic client configuration),
+ // and it's (pre)set.
return;
}
QLowEnergyCharacteristic characteristic(characteristicForHandle(charHandle));
if (!characteristic.isValid()) {
- qCWarning(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::characteristicUpdateNotification(), "
- "unknown characteristic";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "unknown characteristic";
return;
}
- updateValueOfCharacteristic(charHandle, value, false);
+ if (characteristic.properties() & QLowEnergyCharacteristic::Read)
+ updateValueOfCharacteristic(charHandle, value, false);
+
emit service->characteristicChanged(characteristic, value);
}
void QLowEnergyControllerPrivateOSX::descriptorWriteNotification(QLowEnergyHandle dHandle, const QByteArray &value)
{
- Q_ASSERT_X(dHandle, "descriptorWriteNotification", "invalid descriptor handle (0)");
+ Q_ASSERT_X(dHandle, Q_FUNC_INFO, "invalid descriptor handle (0)");
const QLowEnergyDescriptor qtDescriptor(descriptorForHandle(dHandle));
if (!qtDescriptor.isValid()) {
- qCWarning(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::descriptorWriteNotification(), "
- "unknown descriptor " << dHandle;
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "unknown descriptor " << dHandle;
return;
}
@@ -422,20 +419,17 @@ void QLowEnergyControllerPrivateOSX::error(const QBluetoothUuid &serviceUuid,
ServicePrivate qtService(discoveredServices.value(serviceUuid));
qtService->setState(QLowEnergyService::InvalidService);
} else {
- qCDebug(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::error(), "
- "error reported for unknown service "<<serviceUuid;
+ qCDebug(QT_BT_OSX) << Q_FUNC_INFO << "error reported for unknown service "
+ << serviceUuid;
}
}
void QLowEnergyControllerPrivateOSX::error(const QBluetoothUuid &serviceUuid,
- QLowEnergyHandle charHandle,
QLowEnergyService::ServiceError errorCode)
{
- Q_UNUSED(charHandle)
-
if (!discoveredServices.contains(serviceUuid)) {
- qCDebug(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::error(), "
- "unknown service uuid: " << serviceUuid;
+ qCDebug(QT_BT_OSX) << Q_FUNC_INFO << "unknown service uuid: "
+ << serviceUuid;
return;
}
@@ -445,12 +439,12 @@ void QLowEnergyControllerPrivateOSX::error(const QBluetoothUuid &serviceUuid,
void QLowEnergyControllerPrivateOSX::connectToDevice()
{
- Q_ASSERT_X(isValid(), "connectToDevice", "invalid private controller");
+ Q_ASSERT_X(isValid(), Q_FUNC_INFO, "invalid private controller");
Q_ASSERT_X(controllerState == QLowEnergyController::UnconnectedState,
- "connectToDevice", "invalid state");
- Q_ASSERT_X(!deviceUuid.isNull(), "connectToDevice",
+ Q_FUNC_INFO, "invalid state");
+ Q_ASSERT_X(!deviceUuid.isNull(), Q_FUNC_INFO,
"invalid private controller (no device uuid)");
- Q_ASSERT_X(!isConnecting, "connectToDevice",
+ Q_ASSERT_X(!isConnecting, Q_FUNC_INFO,
"recursive connectToDevice call");
setErrorDescription(QLowEnergyController::NoError);
@@ -481,9 +475,9 @@ void QLowEnergyControllerPrivateOSX::connectToDevice()
void QLowEnergyControllerPrivateOSX::discoverServices()
{
- Q_ASSERT_X(isValid(), "discoverServices", "invalid private controller");
+ Q_ASSERT_X(isValid(), Q_FUNC_INFO, "invalid private controller");
Q_ASSERT_X(controllerState != QLowEnergyController::UnconnectedState,
- "discoverServices", "not connected to peripheral");
+ Q_FUNC_INFO, "not connected to peripheral");
controllerState = QLowEnergyController::DiscoveringState;
emit q_ptr->stateChanged(QLowEnergyController::DiscoveringState);
@@ -492,18 +486,17 @@ void QLowEnergyControllerPrivateOSX::discoverServices()
void QLowEnergyControllerPrivateOSX::discoverServiceDetails(const QBluetoothUuid &serviceUuid)
{
- Q_ASSERT_X(isValid(), "discoverServiceDetails", "invalid private controller");
+ Q_ASSERT_X(isValid(), Q_FUNC_INFO, "invalid private controller");
if (controllerState != QLowEnergyController::DiscoveredState) {
- qCWarning(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::discoverServiceDetails(), "
- "can not discover service details in the current state, "
- "QLowEnergyController::DiscoveredState is expected";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO
+ << "can not discover service details in the current state, "
+ << "QLowEnergyController::DiscoveredState is expected";
return;
}
if (!discoveredServices.contains(serviceUuid)) {
- qCWarning(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::discoverServiceDetails(), "
- "unknown service: " << serviceUuid;
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "unknown service: " << serviceUuid;
return;
}
@@ -521,18 +514,29 @@ void QLowEnergyControllerPrivateOSX::setNotifyValue(QSharedPointer<QLowEnergySer
QLowEnergyHandle charHandle,
const QByteArray &newValue)
{
- Q_ASSERT_X(!service.isNull(), "setNotifyValue", "invalid service (null)");
- Q_ASSERT_X(isValid(), "setNotifyValue", "invalid controller");
+ Q_ASSERT_X(!service.isNull(), Q_FUNC_INFO, "invalid service (null)");
+ Q_ASSERT_X(isValid(), Q_FUNC_INFO, "invalid controller");
+
+ if (newValue.size() > 2) {
+ // Qt's API requires an error on such write.
+ // With Core Bluetooth we do not write any descriptor,
+ // but instead call a special method. So it's better to
+ // intercept wrong data size here:
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "client characteristic configuration descriptor "
+ "is 2 bytes, but value size is: " << newValue.size();
+ service->setError(QLowEnergyService::DescriptorWriteError);
+ return;
+ }
if (!discoveredServices.contains(service->uuid)) {
- qCWarning(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::setNotifyValue(), "
- "no service with uuid: " << service->uuid << " found";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "no service with uuid: "
+ << service->uuid << " found";
return;
}
if (!service->characteristicList.contains(charHandle)) {
- qCDebug(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::setNotifyValue(), "
- "no characteristic with handle: " << charHandle << " found";
+ qCDebug(QT_BT_OSX) << Q_FUNC_INFO << "no characteristic with handle: "
+ << charHandle << " found";
return;
}
@@ -544,21 +548,21 @@ void QLowEnergyControllerPrivateOSX::writeCharacteristic(QSharedPointer<QLowEner
QLowEnergyHandle charHandle, const QByteArray &newValue,
bool writeWithResponse)
{
- Q_ASSERT_X(!service.isNull(), "writeCharacteristic", "invalid service (null)");
- Q_ASSERT_X(isValid(), "writeCharacteristic", "invalid controller");
+ Q_ASSERT_X(!service.isNull(), Q_FUNC_INFO, "invalid service (null)");
+ Q_ASSERT_X(isValid(), Q_FUNC_INFO, "invalid controller");
// We can work only with services, found on a given peripheral
// (== created by the given LE controller),
// otherwise we can not write anything at all.
if (!discoveredServices.contains(service->uuid)) {
- qCWarning(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::writeCharacteristic(), "
- "no service with uuid: " << service->uuid << " found";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "no service with uuid: "
+ << service->uuid << " found";
return;
}
if (!service->characteristicList.contains(charHandle)) {
- qCDebug(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::writeCharacteristic(), "
- "no characteristic with handle: " << charHandle << " found";
+ qCDebug(QT_BT_OSX) << Q_FUNC_INFO << "no characteristic with handle: "
+ << charHandle << " found";
return;
}
@@ -590,15 +594,15 @@ void QLowEnergyControllerPrivateOSX::writeDescriptor(QSharedPointer<QLowEnergySe
QLowEnergyHandle descriptorHandle,
const QByteArray &newValue)
{
- Q_ASSERT_X(!service.isNull(), "writeDescriptor", "invalid service (null)");
- Q_ASSERT_X(isValid(), "writeDescriptor", "invalid controller");
+ Q_ASSERT_X(!service.isNull(), Q_FUNC_INFO, "invalid service (null)");
+ Q_ASSERT_X(isValid(), Q_FUNC_INFO, "invalid controller");
// We can work only with services found on a given peripheral
// (== created by the given LE controller),
// otherwise we can not write anything at all.
if (!discoveredServices.contains(service->uuid)) {
- qCWarning(QT_BT_OSX) << "QLowEnergyControllerPrivateOSX::writeDescriptor(), "
- "no service with uuid: " << service->uuid << " found";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "no service with uuid: "
+ << service->uuid << " found";
return;
}
@@ -716,10 +720,13 @@ QLowEnergyController::QLowEnergyController(const QBluetoothAddress &remoteAddres
: QObject(parent),
d_ptr(new QLowEnergyControllerPrivateOSX(this))
{
- Q_UNUSED(remoteAddress)
+ OSX_D_PTR;
+
+ osx_d_ptr->remoteAddress = remoteAddress;
+ osx_d_ptr->localAddress = QBluetoothLocalDevice().address();
- qCWarning(QT_BT_OSX) << "QLowEnergyController::QLowEnergyController(), "
- "construction with remote address is not supported!";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "construction with remote address "
+ "is not supported!";
}
QLowEnergyController::QLowEnergyController(const QBluetoothDeviceInfo &remoteDevice,
@@ -727,6 +734,9 @@ QLowEnergyController::QLowEnergyController(const QBluetoothDeviceInfo &remoteDev
: QObject(parent),
d_ptr(new QLowEnergyControllerPrivateOSX(this, remoteDevice))
{
+ OSX_D_PTR;
+
+ osx_d_ptr->localAddress = QBluetoothLocalDevice().address();
// That's the only "real" ctor - with Core Bluetooth we need a _valid_ deviceUuid
// from 'remoteDevice'.
}
@@ -742,8 +752,8 @@ QLowEnergyController::QLowEnergyController(const QBluetoothAddress &remoteAddres
osx_d_ptr->remoteAddress = remoteAddress;
osx_d_ptr->localAddress = localAddress;
- qCWarning(QT_BT_OSX) << "QLowEnergyController::QLowEnergyController(), "
- "construction with remote/local addresses is not supported!";
+ qCWarning(QT_BT_OSX) << Q_FUNC_INFO << "construction with remote/local "
+ "addresses is not supported!";
}
QLowEnergyController::~QLowEnergyController()
diff --git a/src/bluetooth/qlowenergycontroller_osx_p.h b/src/bluetooth/qlowenergycontroller_osx_p.h
index dbf22776..c7db0668 100644
--- a/src/bluetooth/qlowenergycontroller_osx_p.h
+++ b/src/bluetooth/qlowenergycontroller_osx_p.h
@@ -83,7 +83,6 @@ private:
void error(const QBluetoothUuid &serviceUuid,
QLowEnergyController::Error errorCode) Q_DECL_OVERRIDE;
void error(const QBluetoothUuid &serviceUuid,
- QLowEnergyHandle charHandle,
QLowEnergyService::ServiceError error) Q_DECL_OVERRIDE;
void connectToDevice();
diff --git a/src/bluetooth/qlowenergyservice.cpp b/src/bluetooth/qlowenergyservice.cpp
index 10307332..c33de8d5 100644
--- a/src/bluetooth/qlowenergyservice.cpp
+++ b/src/bluetooth/qlowenergyservice.cpp
@@ -151,6 +151,9 @@ QT_BEGIN_NAMESPACE
to be a secondary service. Each service may be included
by another service which is indicated by IncludedService.
\value IncludedService The service is included by another service.
+ On some platforms, this flag cannot be determined until
+ the service that includes the current service was
+ discovered.
*/
/*!
@@ -242,6 +245,15 @@ QT_BEGIN_NAMESPACE
by calling \l writeCharacteristic(). If the write operation is not successful,
the \l error() signal is emitted using the \l CharacteristicWriteError flag.
+ Since this signal is an indication of a successful write operation \a newValue
+ generally matches the value that was passed to the associated
+ \l writeCharacteristic() call. However, it may happen that the two values differ
+ from each other. This can occur in cases when the written value is
+ used by the remote device to trigger an operation and it returns some other value via
+ the written and/or change notification. Such cases are very specific to the
+ target device. In any case, the reception of the written signal can still be considered
+ as a sign that the target device received the to-be-written value.
+
\note If \l writeCharacteristic() is called using the \l WriteWithoutResponse mode,
this signal and the \l error() are never emitted.
@@ -284,8 +296,8 @@ QLowEnergyService::QLowEnergyService(QSharedPointer<QLowEnergyServicePrivate> p,
: QObject(parent),
d_ptr(p)
{
- qRegisterMetaType<QLowEnergyService::ServiceState>("QLowEnergyService::ServiceState");
- qRegisterMetaType<QLowEnergyService::ServiceError>("QLowEnergyService::ServiceError");
+ qRegisterMetaType<QLowEnergyService::ServiceState>();
+ qRegisterMetaType<QLowEnergyService::ServiceError>();
connect(p.data(), SIGNAL(error(QLowEnergyService::ServiceError)),
this, SIGNAL(error(QLowEnergyService::ServiceError)));
@@ -310,6 +322,9 @@ QLowEnergyService::~QLowEnergyService()
Returns the UUIDs of all services which are included by the
current service.
+ The returned list is empty if this service instance's \l discoverDetails()
+ was not yet called or there are no known characteristics.
+
It is possible that an included service contains yet another service. Such
second level includes have to be obtained via their relevant first level
QLowEnergyService instance. Technically, this could create
@@ -335,7 +350,6 @@ QList<QBluetoothUuid> QLowEnergyService::includedServices() const
Therefore any service object instance created after
the first one has a state equal to already existing instances.
-
A service becomes invalid if the \l QLowEnergyController disconnects
from the remote device. An invalid service retains its internal state
at the time of the disconnect event. This implies that once the service
@@ -358,9 +372,14 @@ QLowEnergyService::ServiceState QLowEnergyService::state() const
/*!
Returns the type of the service.
+ \note The type attribute cannot be relied upon until the service has
+ reached the \l ServiceDiscovered state. This field is initialised
+ with \l PrimaryService.
+
\note On Android, it is not possible to determine whether a service
is a primary or secondary service. Therefore all services
have the \l PrimaryService flag set.
+
*/
QLowEnergyService::ServiceTypes QLowEnergyService::type() const
{
@@ -371,6 +390,9 @@ QLowEnergyService::ServiceTypes QLowEnergyService::type() const
Returns the matching characteristic for \a uuid; otherwise an invalid
characteristic.
+ The returned characteristic is invalid if this service instance's \l discoverDetails()
+ was not yet called or there are no characteristics with a matching \a uuid.
+
\sa characteristics()
*/
QLowEnergyCharacteristic QLowEnergyService::characteristic(const QBluetoothUuid &uuid) const
diff --git a/src/bluetooth/qlowenergyservice.h b/src/bluetooth/qlowenergyservice.h
index 136f85ee..2c86d380 100644
--- a/src/bluetooth/qlowenergyservice.h
+++ b/src/bluetooth/qlowenergyservice.h
@@ -120,4 +120,7 @@ private:
QT_END_NAMESPACE
+Q_DECLARE_METATYPE(QLowEnergyService::ServiceState)
+Q_DECLARE_METATYPE(QLowEnergyService::ServiceError)
+
#endif // QLOWENERGYSERVICE_H
diff --git a/src/bluetooth/qlowenergyservice_osx.mm b/src/bluetooth/qlowenergyservice_osx.mm
index cb1c1f30..c6284bbd 100644
--- a/src/bluetooth/qlowenergyservice_osx.mm
+++ b/src/bluetooth/qlowenergyservice_osx.mm
@@ -63,8 +63,8 @@ QLowEnergyService::QLowEnergyService(QSharedPointer<QLowEnergyServicePrivate> d,
: QObject(parent),
d_ptr(d)
{
- qRegisterMetaType<QLowEnergyService::ServiceState>("QLowEnergyService::ServiceState");
- qRegisterMetaType<QLowEnergyService::ServiceError>("QLowEnergyService::ServiceError");
+ qRegisterMetaType<QLowEnergyService::ServiceState>();
+ qRegisterMetaType<QLowEnergyService::ServiceError>();
connect(d.data(), SIGNAL(error(QLowEnergyService::ServiceError)),
this, SIGNAL(error(QLowEnergyService::ServiceError)));
@@ -184,15 +184,13 @@ void QLowEnergyService::writeCharacteristic(const QLowEnergyCharacteristic &ch,
if (!contains(ch))
return;
- if (state() != ServiceDiscovered) {
+ QLowEnergyControllerPrivateOSX *const controller = qt_mac_le_controller(d_ptr);
+
+ if (state() != ServiceDiscovered || !controller) {
d_ptr->setError(QLowEnergyService::OperationError);
return;
}
- QLowEnergyControllerPrivateOSX *const controller = qt_mac_le_controller(d_ptr);
- if (!controller)
- return;
-
// Don't write if properties don't permit it
if (mode == WriteWithResponse && (ch.properties() & QLowEnergyCharacteristic::Write))
controller->writeCharacteristic(ch.d_ptr, ch.attributeHandle(), newValue, true);
@@ -227,10 +225,7 @@ void QLowEnergyService::writeDescriptor(const QLowEnergyDescriptor &descriptor,
return;
QLowEnergyControllerPrivateOSX *const controller = qt_mac_le_controller(d_ptr);
- if (!controller)
- return;
-
- if (state() != ServiceDiscovered) {
+ if (state() != ServiceDiscovered || !controller) {
d_ptr->setError(OperationError);
return;
}
diff --git a/src/imports/bluetooth/plugins.qmltypes b/src/imports/bluetooth/plugins.qmltypes
index f7d0d08d..cf2146e2 100644
--- a/src/imports/bluetooth/plugins.qmltypes
+++ b/src/imports/bluetooth/plugins.qmltypes
@@ -30,7 +30,8 @@ Module {
"NoError": 0,
"InputOutputError": 1,
"PoweredOffError": 2,
- "UnknownError": 3
+ "UnknownError": 3,
+ "InvalidBluetoothAdapterError": 4
}
}
Property { name: "error"; type: "Error"; isReadonly: true }
diff --git a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
index 20f47f65..01a53bfa 100644
--- a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
+++ b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
@@ -151,7 +151,19 @@ void QDeclarativeBluetoothDiscoveryModel::componentComplete()
void QDeclarativeBluetoothDiscoveryModel::errorDiscovery(QBluetoothServiceDiscoveryAgent::Error error)
{
- d->m_error = static_cast<QDeclarativeBluetoothDiscoveryModel::Error>(error);
+ switch (error) {
+ case QBluetoothServiceDiscoveryAgent::InvalidBluetoothAdapterError:
+ d->m_error = QDeclarativeBluetoothDiscoveryModel::InvalidBluetoothAdapterError; break;
+ case QBluetoothServiceDiscoveryAgent::NoError:
+ d->m_error = QDeclarativeBluetoothDiscoveryModel::NoError; break;
+ case QBluetoothServiceDiscoveryAgent::InputOutputError:
+ d->m_error = QDeclarativeBluetoothDiscoveryModel::InputOutputError; break;
+ case QBluetoothServiceDiscoveryAgent::PoweredOffError:
+ d->m_error = QDeclarativeBluetoothDiscoveryModel::PoweredOffError; break;
+ case QBluetoothServiceDiscoveryAgent::UnknownError:
+ d->m_error = QDeclarativeBluetoothDiscoveryModel::UnknownError; break;
+ }
+
emit errorChanged();
}
@@ -187,6 +199,12 @@ void QDeclarativeBluetoothDiscoveryModel::clearModel()
\li An IO failure occurred during device discovery
\row \li \c BluetoothDiscoveryModel.PoweredOffError
\li The bluetooth device is not powered on.
+ \row \li \c BluetoothDiscoveryModel.InvalidBluetoothAdapterError
+ \li There is no default Bluetooth device to perform the
+ service discovery. The model always uses the local default adapter.
+ Specifying a default adapter is not possible. If that's required,
+ \l QBluetoothServiceDiscoveryAgent should be directly used. This
+ value was introduced by Qt 5.4.
\row \li \c BluetoothDiscoveryModel.UnknownError
\li An unknown error occurred.
\endtable
@@ -407,6 +425,13 @@ void QDeclarativeBluetoothDiscoveryModel::setRunning(bool running)
//qDebug() << "Minimal Discovery";
d->m_serviceAgent->start(QBluetoothServiceDiscoveryAgent::MinimalDiscovery);
}
+
+ // we could not start service discovery
+ if (!d->m_serviceAgent->isActive()) {
+ d->m_running = false;
+ errorDiscovery(d->m_serviceAgent->error());
+ return;
+ }
}
}
diff --git a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h
index 279fb063..1834ce36 100644
--- a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h
+++ b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h
@@ -94,7 +94,8 @@ public:
NoError,
InputOutputError,
PoweredOffError,
- UnknownError
+ UnknownError,
+ InvalidBluetoothAdapterError
};
Error error() const;
diff --git a/src/imports/nfc/qdeclarativenearfield.cpp b/src/imports/nfc/qdeclarativenearfield.cpp
index f6c68b85..58ed0e50 100644
--- a/src/imports/nfc/qdeclarativenearfield.cpp
+++ b/src/imports/nfc/qdeclarativenearfield.cpp
@@ -96,6 +96,7 @@
/*!
\qmlproperty bool NearField::polling
+ \since 5.5
This property indicates if the underlying adapter is currently in polling state. If set to \c true
the adapter will start polling and stop polling if set to \c false.
@@ -106,12 +107,14 @@
/*!
\qmlsignal NearField::tagFound()
+ \since 5.5
This signal will be emitted when a tag has been detected.
*/
/*!
\qmlsignal NearField::tagRemoved()
+ \since 5.5
This signal will be emitted when a tag has been removed.
*/
@@ -254,6 +257,8 @@ void QDeclarativeNearField::_q_handleTargetDetected(QNearFieldTarget *target)
this, SLOT(_q_handleNdefMessage(QNdefMessage)));
target->readNdefMessages();
}
+
+ emit tagFound();
}
void QDeclarativeNearField::append_messageRecord(QQmlListProperty<QQmlNdefRecord> *list,
diff --git a/src/nfc/doc/src/nfc-overview.qdoc b/src/nfc/doc/src/nfc-overview.qdoc
index b068dfb5..f068201c 100644
--- a/src/nfc/doc/src/nfc-overview.qdoc
+++ b/src/nfc/doc/src/nfc-overview.qdoc
@@ -105,7 +105,7 @@ Depending on the platform it may even be possible to start the application that
\note This feature is not available on all platforms and, in addition to the code snippets below,
may require further platform specific setup.
-\snippet annotatedurl/main.cpp QNearFieldManager register handler
+\snippet annotatedurl/annotatedurl.cpp QNearFieldManager register handler
For comparison an application that uses an empty NDEF filter (match all behavior) in combination with
\l QNearFieldManager::registerNdefMessageHandler() would behave similarly to another application that uses
diff --git a/src/nfc/qndefnfcsmartposterrecord.cpp b/src/nfc/qndefnfcsmartposterrecord.cpp
index d1a6e4d5..9c6d756b 100644
--- a/src/nfc/qndefnfcsmartposterrecord.cpp
+++ b/src/nfc/qndefnfcsmartposterrecord.cpp
@@ -602,7 +602,10 @@ bool QNdefNfcSmartPosterRecord::removeIcon(const QByteArray &type)
}
/*!
- Adds the icon record list \a icons to the smart poster. Any existing records are overwritten.
+ Adds the icon record list \a icons to the smart poster.
+ Any existing records are overwritten.
+
+ \sa hasIcon(), icon()
*/
void QNdefNfcSmartPosterRecord::setIcons(const QList<QNdefNfcIconRecord> &icons)
{
@@ -617,7 +620,13 @@ void QNdefNfcSmartPosterRecord::setIcons(const QList<QNdefNfcIconRecord> &icons)
}
/*!
- Returns the size from the size record if available. Otherwise returns 0.
+ Returns the size from the size record if available; otherwise returns 0.
+
+ The value is optional and contains the size in bytes of the object
+ that the URI refers to. It may be used by the device to determine
+ whether it can accommodate the object.
+
+ \sa setSize()
*/
quint32 QNdefNfcSmartPosterRecord::size() const
{
@@ -628,7 +637,10 @@ quint32 QNdefNfcSmartPosterRecord::size() const
}
/*!
- Sets the size record to \a size
+ Sets the record \a size. The value contains the size in bytes of
+ the object that the URI refers to.
+
+ \sa size(), hasSize()
*/
void QNdefNfcSmartPosterRecord::setSize(quint32 size)
{
@@ -642,7 +654,12 @@ void QNdefNfcSmartPosterRecord::setSize(quint32 size)
}
/*!
- Returns the type from the type record if available. Otherwise returns an empty byte array.
+ Returns the UTF-8 encoded MIME type that describes the type of the objects
+ that can be reached via uri().
+
+ If the type is not known the return QByteArray is empty.
+
+ \sa setTypeInfo(), hasTypeInfo()
*/
QByteArray QNdefNfcSmartPosterRecord::typeInfo() const
{
@@ -653,7 +670,10 @@ QByteArray QNdefNfcSmartPosterRecord::typeInfo() const
}
/*!
- Sets the type record to \a type
+ Sets the type record to \a type. \a type must be UTF-8 encoded
+ and describes the type of the object referenced by uri()
+
+ \sa typeInfo()
*/
void QNdefNfcSmartPosterRecord::setTypeInfo(const QByteArray &type)
{
diff --git a/src/nfc/qndefnfcsmartposterrecord.h b/src/nfc/qndefnfcsmartposterrecord.h
index ffd45dad..0b2d3b7e 100644
--- a/src/nfc/qndefnfcsmartposterrecord.h
+++ b/src/nfc/qndefnfcsmartposterrecord.h
@@ -124,6 +124,7 @@ public:
quint32 size() const;
void setSize(quint32 size);
+ //TODO Qt 6 the mimetype should be QString as it is UTF-8
QByteArray typeInfo() const;
void setTypeInfo(const QByteArray &type);
diff --git a/src/nfc/qnearfieldtarget.cpp b/src/nfc/qnearfieldtarget.cpp
index cbf5bd42..6374c8fb 100644
--- a/src/nfc/qnearfieldtarget.cpp
+++ b/src/nfc/qnearfieldtarget.cpp
@@ -272,9 +272,9 @@ QNearFieldTarget::RequestId &QNearFieldTarget::RequestId::operator=(const Reques
QNearFieldTarget::QNearFieldTarget(QObject *parent)
: QObject(parent), d_ptr(new QNearFieldTargetPrivate)
{
- qRegisterMetaType<RequestId>("QNearFieldTarget::RequestId");
- qRegisterMetaType<Error>("QNearFieldTarget::Error");
- qRegisterMetaType<QNdefMessage>("QNdefMessage::QNdefMessage");
+ qRegisterMetaType<QNearFieldTarget::RequestId>();
+ qRegisterMetaType<QNearFieldTarget::Error>();
+ qRegisterMetaType<QNdefMessage>();
}
/*!
diff --git a/src/nfc/qnearfieldtarget_emulator.cpp b/src/nfc/qnearfieldtarget_emulator.cpp
index ee0c6188..a483fe4b 100644
--- a/src/nfc/qnearfieldtarget_emulator.cpp
+++ b/src/nfc/qnearfieldtarget_emulator.cpp
@@ -187,7 +187,7 @@ bool TagType2::waitForRequestCompleted(const RequestId &id, int msecs)
TagActivator::TagActivator()
: timerId(-1)
{
- qRegisterMetaType<QNearFieldTarget::Error>("QNearFieldTarget::Error");
+ qRegisterMetaType<QNearFieldTarget::Error>();
}
TagActivator::~TagActivator()
diff --git a/src/nfc/qnearfieldtarget_neard_p.h b/src/nfc/qnearfieldtarget_neard_p.h
index 100456bf..26a699a2 100644
--- a/src/nfc/qnearfieldtarget_neard_p.h
+++ b/src/nfc/qnearfieldtarget_neard_p.h
@@ -76,6 +76,7 @@ public:
{
m_readErrorTimer.setSingleShot(true);
m_recordPathsCollectedTimer.setSingleShot(true);
+ m_delayedWriteTimer.setSingleShot(true);
qCDebug(QT_NFC_NEARD) << "tag found at path" << interfacePath.path();
m_dbusProperties = new OrgFreedesktopDBusPropertiesInterface(QStringLiteral("org.neard"),
@@ -112,6 +113,8 @@ public:
this, &NearFieldTarget::createNdefMessage);
QObject::connect(&m_readErrorTimer, &QTimer::timeout,
this, &NearFieldTarget::handleReadError);
+ QObject::connect(&m_delayedWriteTimer, &QTimer::timeout,
+ this, &NearFieldTarget::handleWriteRequest);
QObject::connect(NeardHelper::instance(), &NeardHelper::recordFound,
this, &NearFieldTarget::handleRecordFound);
}
@@ -151,12 +154,12 @@ public:
if (isValid()) {
// if the user calls readNdefMessages before the previous request has been completed
// return the current request id.
- if (m_currentRequestId.isValid())
- return m_currentRequestId;
+ if (m_currentReadRequestId.isValid())
+ return m_currentReadRequestId;
QNearFieldTarget::RequestId requestId = QNearFieldTarget::RequestId(new QNearFieldTarget::RequestIdPrivate());
// save the id so it can be passed along with requestCompleted
- m_currentRequestId = requestId;
+ m_currentReadRequestId = requestId;
// since the triggering of interfaceAdded will ultimately lead to createNdefMessage being called
// we need to make sure that ndefMessagesRead will only be triggered when readNdefMessages has
// been called before. In case readNdefMessages is called again after that we can directly call
@@ -187,6 +190,15 @@ public:
QNearFieldTarget::RequestId writeNdefMessages(const QList<QNdefMessage> &messages)
{
+ // disabling write due to neard crash (see QTBUG-43802)
+ qWarning("QNearFieldTarget::WriteNdefMessages() disabled. See QTBUG-43802\n");
+ return QNearFieldTarget::RequestId();
+
+
+ // return old request id when previous write request hasn't completed
+ if (m_currentWriteRequestId.isValid())
+ return m_currentReadRequestId;
+
qCDebug(QT_NFC_NEARD) << "writing messages";
if (messages.isEmpty() || messages.first().isEmpty()) {
qCWarning(QT_NFC_NEARD) << "No record specified";
@@ -200,50 +212,34 @@ public:
QNdefRecord record = messages.first().first();
if (record.typeNameFormat() == QNdefRecord::NfcRtd) {
- QVariantMap recordProperties;
+ m_currentWriteRequestData.clear();
if (record.isRecordType<QNdefNfcUriRecord>()) {
- recordProperties.insert(QStringLiteral("Type"), QStringLiteral("URI"));
+ m_currentWriteRequestData.insert(QStringLiteral("Type"), QStringLiteral("URI"));
QNdefNfcUriRecord uriRecord = static_cast<QNdefNfcUriRecord>(record);
- recordProperties.insert(QStringLiteral("URI"), uriRecord.uri().path());
+ m_currentWriteRequestData.insert(QStringLiteral("URI"), uriRecord.uri().toString());
} else if (record.isRecordType<QNdefNfcSmartPosterRecord>()) {
- recordProperties.insert(QStringLiteral("Type"), QStringLiteral("SmartPoster"));
+ m_currentWriteRequestData.insert(QStringLiteral("Type"), QStringLiteral("SmartPoster"));
QNdefNfcSmartPosterRecord spRecord = static_cast<QNdefNfcSmartPosterRecord>(record);
- recordProperties.insert(QStringLiteral("URI"), spRecord.uri().path());
+ m_currentWriteRequestData.insert(QStringLiteral("URI"), spRecord.uri().toString());
// Currently neard only supports the uri property for writing
} else if (record.isRecordType<QNdefNfcTextRecord>()) {
- recordProperties.insert(QStringLiteral("Type"), QStringLiteral("Text"));
+ m_currentWriteRequestData.insert(QStringLiteral("Type"), QStringLiteral("Text"));
QNdefNfcTextRecord textRecord = static_cast<QNdefNfcTextRecord>(record);
- recordProperties.insert(QStringLiteral("Representation"), textRecord.text());
- recordProperties.insert(QStringLiteral("Encoding"),
+ m_currentWriteRequestData.insert(QStringLiteral("Representation"), textRecord.text());
+ m_currentWriteRequestData.insert(QStringLiteral("Encoding"),
textRecord.encoding() == QNdefNfcTextRecord::Utf8 ?
QStringLiteral("UTF-8") : QStringLiteral("UTF-16") );
- recordProperties.insert(QStringLiteral("Language"), textRecord.locale());
+ m_currentWriteRequestData.insert(QStringLiteral("Language"), textRecord.locale());
} else {
qCWarning(QT_NFC_NEARD) << "Record type not supported for writing";
return QNearFieldTarget::RequestId();
}
- OrgNeardTagInterface tagInterface(QStringLiteral("org.neard"),
- m_tagPath.path(),
- QDBusConnection::systemBus());
- if (!tagInterface.isValid()) {
- qCWarning(QT_NFC_NEARD) << "tag interface invalid";
- } else {
- QDBusPendingReply<> reply;
- reply = tagInterface.Write(recordProperties);
- reply.waitForFinished();
- if (reply.isError()) {
- qCWarning(QT_NFC_NEARD) << "Error writing to NFC tag" << reply.error();
- return QNearFieldTarget::RequestId();
- }
-
- QMetaObject::invokeMethod(this, "ndefMessagesWritten", Qt::QueuedConnection);
+ m_currentWriteRequestId = QNearFieldTarget::RequestId(new QNearFieldTarget::RequestIdPrivate());
+ // trigger delayed write
+ m_delayedWriteTimer.start(100);
- QNearFieldTarget::RequestId requestId = QNearFieldTarget::RequestId(new QNearFieldTarget::RequestIdPrivate());
- QMetaObject::invokeMethod(this, "requestCompleted", Qt::QueuedConnection,
- Q_ARG(const QNearFieldTarget::RequestId, requestId));
- return requestId;
- }
+ return m_currentWriteRequestId;
}
return QNearFieldTarget::RequestId();
@@ -268,10 +264,9 @@ private:
const QString &locale = reply.value().value(QStringLiteral("Language")).toString();
const QString &encoding = reply.value().value(QStringLiteral("Encoding")).toString();
const QString &uri = reply.value().value(QStringLiteral("URI")).toString();
-// const QString &mimetype = reply.value().value(QStringLiteral("MIMEType")).toString();
+
// const QString &mime = reply.value().value(QStringLiteral("MIME")).toString();
// const QString &arr = reply.value().value(QStringLiteral("ARR")).toString();
-// const QString &size = reply.value().value(QStringLiteral("Size")).toString();
const QString type = reply.value().value(QStringLiteral("Type")).toString();
if (type == QStringLiteral("Text")) {
@@ -292,12 +287,26 @@ private:
if (!uri.isEmpty())
spRecord.setUri(QUrl(uri));
-// const QString &actionString = reply.value().value(QStringLiteral("Action")).toString();
-// if (!action.isEmpty()) {
-// QNdefNfcSmartPosterRecord::Action action;
+ const QString &action = reply.value().value(QStringLiteral("Action")).toString();
+ if (!action.isEmpty()) {
+ if (action == QStringLiteral("Do"))
+ spRecord.setAction(QNdefNfcSmartPosterRecord::DoAction);
+ else if (action == QStringLiteral("Save"))
+ spRecord.setAction(QNdefNfcSmartPosterRecord::SaveAction);
+ else if (action == QStringLiteral("Edit"))
+ spRecord.setAction(QNdefNfcSmartPosterRecord::EditAction);
+ }
+
+ if (reply.value().contains(QStringLiteral("Size"))) {
+ uint size = reply.value().value(QStringLiteral("Size")).toUInt();
+ spRecord.setSize(size);
+ }
+
+ const QString &mimeType = reply.value().value(QStringLiteral("MIMEType")).toString();
+ if (!mimeType.isEmpty()) {
+ spRecord.setTypeInfo(mimeType.toUtf8());
+ }
-// spRecord.setAction(acti);
-// }
return spRecord;
} else if (type == QStringLiteral("URI")) {
@@ -338,23 +347,50 @@ private:
Q_ARG(const QNdefMessage, newNdefMessage));
// the request id in requestCompleted has to match the one created in readNdefMessages
QMetaObject::invokeMethod(this, "requestCompleted", Qt::QueuedConnection,
- Q_ARG(const QNearFieldTarget::RequestId, m_currentRequestId));
+ Q_ARG(const QNearFieldTarget::RequestId, m_currentReadRequestId));
} else {
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
Q_ARG(const QNearFieldTarget::Error, QNearFieldTarget::UnknownError),
- Q_ARG(const QNearFieldTarget::RequestId, m_currentRequestId));
+ Q_ARG(const QNearFieldTarget::RequestId, m_currentReadRequestId));
}
m_readRequested = false;
// invalidate the current request id
- m_currentRequestId = QNearFieldTarget::RequestId(0);
+ m_currentReadRequestId = QNearFieldTarget::RequestId(0);
}
}
void handleReadError()
{
- emit QNearFieldTarget::error(QNearFieldTarget::UnknownError, m_currentRequestId);
- m_currentRequestId = QNearFieldTarget::RequestId(0);
+ emit QNearFieldTarget::error(QNearFieldTarget::UnknownError, m_currentReadRequestId);
+ m_currentReadRequestId = QNearFieldTarget::RequestId(0);
+ }
+
+ void handleWriteRequest()
+ {
+ OrgNeardTagInterface tagInterface(QStringLiteral("org.neard"),
+ m_tagPath.path(),
+ QDBusConnection::systemBus());
+ if (!tagInterface.isValid()) {
+ qCWarning(QT_NFC_NEARD) << "tag interface invalid";
+ } else {
+ QDBusPendingReply<> reply;
+ reply = tagInterface.Write(m_currentWriteRequestData);
+ reply.waitForFinished();
+ if (reply.isError()) {
+ qCWarning(QT_NFC_NEARD) << "Error writing to NFC tag" << reply.error();
+ QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
+ Q_ARG(const QNearFieldTarget::Error, QNearFieldTarget::UnknownError),
+ Q_ARG(const QNearFieldTarget::RequestId, m_currentWriteRequestId));
+ }
+
+ QMetaObject::invokeMethod(this, "ndefMessagesWritten", Qt::QueuedConnection);
+ QMetaObject::invokeMethod(this, "requestCompleted", Qt::QueuedConnection,
+ Q_ARG(const QNearFieldTarget::RequestId, m_currentWriteRequestId));
+ }
+
+ // invalidate current write request
+ m_currentWriteRequestId = QNearFieldTarget::RequestId(0);
}
protected:
@@ -363,9 +399,12 @@ protected:
QList<QDBusObjectPath> m_recordPaths;
QTimer m_recordPathsCollectedTimer;
QTimer m_readErrorTimer;
+ QTimer m_delayedWriteTimer;
QNearFieldTarget::Type m_type;
bool m_readRequested;
- QNearFieldTarget::RequestId m_currentRequestId;
+ QNearFieldTarget::RequestId m_currentReadRequestId;
+ QNearFieldTarget::RequestId m_currentWriteRequestId;
+ QVariantMap m_currentWriteRequestData;
};
QT_END_NAMESPACE