summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.qmake.conf2
-rw-r--r--examples/bluetooth/btchat/remoteselector.cpp2
-rw-r--r--src/bluetooth/android/jni_android.cpp4
-rw-r--r--src/bluetooth/doc/snippets/doc_src_qtbluetooth.cpp34
-rw-r--r--src/bluetooth/doc/src/bluetooth-overview.qdoc4
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent.cpp6
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_bluez.cpp41
-rw-r--r--src/bluetooth/qbluetoothlocaldevice_p.h2
-rw-r--r--src/bluetooth/qbluetoothserver_p.h6
-rw-r--r--src/bluetooth/qbluetoothserver_qnx.cpp59
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent.cpp2
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp23
-rw-r--r--src/bluetooth/qbluetoothserviceinfo_qnx.cpp31
-rw-r--r--src/bluetooth/qbluetoothsocket.cpp9
-rw-r--r--src/bluetooth/qbluetoothsocket_bluez.cpp25
-rw-r--r--src/bluetooth/qbluetoothsocket_qnx.cpp79
-rw-r--r--src/bluetooth/qbluetoothuuid.h3
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp1
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothservice.cpp63
-rw-r--r--src/imports/bluetooth/qdeclarativebluetoothservice_p.h1
-rw-r--r--src/imports/bluetooth/qmldir1
-rw-r--r--src/imports/nfc/qmldir1
-rw-r--r--src/src.pro6
23 files changed, 280 insertions, 125 deletions
diff --git a/.qmake.conf b/.qmake.conf
index efd0e68f..ef45a002 100644
--- a/.qmake.conf
+++ b/.qmake.conf
@@ -1,4 +1,4 @@
load(qt_build_config)
CONFIG += qt_example_installs
-MODULE_VERSION = 5.3.0
+MODULE_VERSION = 5.3.1
diff --git a/examples/bluetooth/btchat/remoteselector.cpp b/examples/bluetooth/btchat/remoteselector.cpp
index e6fd728f..79dc0564 100644
--- a/examples/bluetooth/btchat/remoteselector.cpp
+++ b/examples/bluetooth/btchat/remoteselector.cpp
@@ -75,7 +75,7 @@ void RemoteSelector::startDiscovery(const QBluetoothUuid &uuid)
ui->remoteDevices->clear();
m_discoveryAgent->setUuidFilter(uuid);
- m_discoveryAgent->start();
+ m_discoveryAgent->start(QBluetoothServiceDiscoveryAgent::FullDiscovery);
}
diff --git a/src/bluetooth/android/jni_android.cpp b/src/bluetooth/android/jni_android.cpp
index ebc46a7c..b7221867 100644
--- a/src/bluetooth/android/jni_android.cpp
+++ b/src/bluetooth/android/jni_android.cpp
@@ -93,7 +93,7 @@ QAndroidJniObject valueForStaticField(JavaNames javaName, JavaNames javaFieldNam
case JavaNames::BluetoothDevice:
className = javaBluetoothDeviceClassName; break;
default:
- qWarning(QT_BT_ANDROID) << "Unknown java class name passed to valueForStaticField():" << javaName;
+ qCWarning(QT_BT_ANDROID) << "Unknown java class name passed to valueForStaticField():" << javaName;
return QAndroidJniObject();
}
@@ -132,7 +132,7 @@ QAndroidJniObject valueForStaticField(JavaNames javaName, JavaNames javaFieldNam
case JavaNames::ExtraUuid:
fieldName = javaExtraUuid; break;
default:
- qWarning(QT_BT_ANDROID) << "Unknown java field name passed to valueForStaticField():" << javaFieldName;
+ qCWarning(QT_BT_ANDROID) << "Unknown java field name passed to valueForStaticField():" << javaFieldName;
return QAndroidJniObject();
}
diff --git a/src/bluetooth/doc/snippets/doc_src_qtbluetooth.cpp b/src/bluetooth/doc/snippets/doc_src_qtbluetooth.cpp
index 88520c35..c0c0f61a 100644
--- a/src/bluetooth/doc/snippets/doc_src_qtbluetooth.cpp
+++ b/src/bluetooth/doc/snippets/doc_src_qtbluetooth.cpp
@@ -46,6 +46,7 @@
#include <QtCore/QFile>
#include <QtCore/QObject>
#include <QtBluetooth/QBluetoothDeviceDiscoveryAgent>
+#include <QtBluetooth/QBluetoothServiceDiscoveryAgent>
#include <QtBluetooth/QBluetoothTransferManager>
#include <QtBluetooth/QBluetoothTransferRequest>
#include <QtBluetooth/QBluetoothTransferReply>
@@ -60,11 +61,13 @@ class MyClass : public QObject
public:
MyClass() : QObject() {}
void localDevice();
- void startDiscovery();
+ void startDeviceDiscovery();
+ void startServiceDiscovery();
void objectPush();
public slots:
void deviceDiscovered(const QBluetoothDeviceInfo &device);
+ void serviceDiscovered(const QBluetoothServiceInfo &service);
void transferFinished(QBluetoothTransferReply* reply);
};
@@ -94,8 +97,8 @@ if (localDevice.isValid()) {
}
-//! [discovery]
-void MyClass::startDiscovery()
+//! [device_discovery]
+void MyClass::startDeviceDiscovery()
{
// Create a discovery agent and connect to its signals
@@ -114,7 +117,30 @@ void MyClass::deviceDiscovered(const QBluetoothDeviceInfo &device)
{
qDebug() << "Found new device:" << device.name() << '(' << device.address().toString() << ')';
}
-//! [discovery]
+//! [device_discovery]
+
+//! [service_discovery]
+void MyClass::startServiceDiscovery()
+{
+
+ // Create a discovery agent and connect to its signals
+ QBluetoothServiceDiscoveryAgent *discoveryAgent = new QBluetoothServiceDiscoveryAgent(this);
+ connect(discoveryAgent, SIGNAL(serviceDiscovered(QBluetoothServiceInfo)),
+ this, SLOT(serviceDiscovered(QBluetoothServiceInfo)));
+
+ // Start a discovery
+ discoveryAgent->start();
+
+ //...
+}
+
+// In your local slot, read information about the found devices
+void MyClass::serviceDiscovered(const QBluetoothServiceInfo &service)
+{
+ qDebug() << "Found new service:" << service.serviceName()
+ << '(' << service.device().address().toString() << ')';
+}
+//! [service_discovery]
void MyClass::objectPush()
{
diff --git a/src/bluetooth/doc/src/bluetooth-overview.qdoc b/src/bluetooth/doc/src/bluetooth-overview.qdoc
index 2afd2bd8..f8040fb8 100644
--- a/src/bluetooth/doc/src/bluetooth-overview.qdoc
+++ b/src/bluetooth/doc/src/bluetooth-overview.qdoc
@@ -51,7 +51,7 @@
\section1 Retrieving Local Device Information
The Qt Bluetooth API has three main purposes. The first one is to
- obtain local and remote device information. The first steps in retrieving device information is
+ obtain local and remote device information. The first steps in retrieving device information are
to check if Bluetooth is available on the device and read the local device address and name.
QBluetoothLocalDevice is the class that provides all of this information. Additionally you can use it
to turn Bluetooth on/off, set the visibility of the device and determine the current connections.
@@ -65,7 +65,7 @@
your own and fill them with data, the easier way is to use the QBluetoothDeviceDiscoveryAgent to
start an automated search for visible Bluetooth devices within the connectable range.
- \snippet doc_src_qtbluetooth.cpp discovery
+ \snippet doc_src_qtbluetooth.cpp device_discovery
\section1 Pushing Files to Remote Devices
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
index eeac8f11..6b959c5f 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
@@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE
\li and call start().
\endlist
- \snippet doc_src_qtbluetooth.cpp discovery
+ \snippet doc_src_qtbluetooth.cpp device_discovery
To retrieve results asynchronously, connect to the deviceDiscovered() signal. To get a list of
all discovered devices, call discoveredDevices() after the finished() signal.
@@ -91,8 +91,8 @@ QT_BEGIN_NAMESPACE
support it, GeneralUnlimitedInquiry will be used instead. Setting LimitedInquiry is useful
for multi-player Bluetooth-based games that needs faster communication between the devices.
The phone scans for devices in LimitedInquiry and Service Discovery is done on one or two devices
- to speed up the service scan. After the game has connected to the device it intends to,the device
- returns to GeneralUnilimitedInquiry.
+ to speed up the service scan. After the game has connected to the device it intended to,
+ the device returns to GeneralUnlimitedInquiry.
*/
/*!
diff --git a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp
index 9f2e7fd3..ac694f34 100644
--- a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp
+++ b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp
@@ -347,7 +347,7 @@ QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluet
}
QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q, QBluetoothAddress address)
- : adapter(0), agent(0), localAddress(address), pendingHostModeChange(-1), msgConnection(0), q_ptr(q), connectedCached(false)
+ : adapter(0), agent(0), localAddress(address), pendingHostModeChange(-1), msgConnection(0), q_ptr(q)
{
initializeAdapter();
connectDeviceChanges();
@@ -356,6 +356,7 @@ QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice
void QBluetoothLocalDevicePrivate::connectDeviceChanges()
{
if (adapter) { //invalid QBluetoothLocalDevice due to wrong local adapter address
+ createCache();
connect(adapter, SIGNAL(PropertyChanged(QString,QDBusVariant)), SLOT(PropertyChanged(QString,QDBusVariant)));
connect(adapter, SIGNAL(DeviceCreated(QDBusObjectPath)), SLOT(_q_deviceCreated(QDBusObjectPath)));
connect(adapter, SIGNAL(DeviceRemoved(QDBusObjectPath)), SLOT(_q_deviceRemoved(QDBusObjectPath)));
@@ -438,7 +439,7 @@ void QBluetoothLocalDevicePrivate::RequestConfirmation(const QDBusObjectPath &in
void QBluetoothLocalDevicePrivate::_q_deviceCreated(const QDBusObjectPath &device)
{
OrgBluezDeviceInterface *deviceInterface =
- new OrgBluezDeviceInterface(QLatin1String("org.bluez"), device.path(), QDBusConnection::systemBus());
+ new OrgBluezDeviceInterface(QLatin1String("org.bluez"), device.path(), QDBusConnection::systemBus(), this);
connect(deviceInterface, SIGNAL(PropertyChanged(QString,QDBusVariant)), SLOT(_q_devicePropertyChanged(QString,QDBusVariant)));
devices << deviceInterface;
QDBusPendingReply<QVariantMap> properties = deviceInterface->asyncCall(QLatin1String("GetProperties"));
@@ -451,16 +452,13 @@ void QBluetoothLocalDevicePrivate::_q_deviceCreated(const QDBusObjectPath &devic
const QBluetoothAddress address = QBluetoothAddress(properties.value().value(QLatin1String("Address")).toString());
const bool connected = properties.value().value(QLatin1String("Connected")).toBool();
- if (connectedCached) {
- if (connected)
- connectedDevicesSet.insert(address);
- else
- connectedDevicesSet.remove(address);
- }
- if (connected)
+ if (connected) {
+ connectedDevicesSet.insert(address);
emit q_ptr->deviceConnected(address);
- else
+ } else {
+ connectedDevicesSet.remove(address);
emit q_ptr->deviceDisconnected(address);
+ }
}
void QBluetoothLocalDevicePrivate::_q_deviceRemoved(const QDBusObjectPath &device)
@@ -488,16 +486,13 @@ void QBluetoothLocalDevicePrivate::_q_devicePropertyChanged(const QString &prope
const QBluetoothAddress address = QBluetoothAddress(properties.value(QLatin1String("Address")).toString());
const bool connected = value.variant().toBool();
- if (connectedCached) {
- if (connected)
- connectedDevicesSet.insert(address);
- else
- connectedDevicesSet.remove(address);
- }
- if (connected)
+ if (connected) {
+ connectedDevicesSet.insert(address);
emit q_ptr->deviceConnected(address);
- else
+ } else {
+ connectedDevicesSet.remove(address);
emit q_ptr->deviceDisconnected(address);
+ }
}
}
@@ -513,9 +508,12 @@ void QBluetoothLocalDevicePrivate::createCache()
return;
}
foreach (const QDBusObjectPath &device, reply.value()) {
- OrgBluezDeviceInterface deviceInterface(QLatin1String("org.bluez"), device.path(), QDBusConnection::systemBus());
+ OrgBluezDeviceInterface *deviceInterface =
+ new OrgBluezDeviceInterface(QLatin1String("org.bluez"), device.path(), QDBusConnection::systemBus(), this);
+ connect(deviceInterface, SIGNAL(PropertyChanged(QString,QDBusVariant)), SLOT(_q_devicePropertyChanged(QString,QDBusVariant)));
+ devices << deviceInterface;
- QDBusPendingReply<QVariantMap> properties = deviceInterface.asyncCall(QLatin1String("GetProperties"));
+ QDBusPendingReply<QVariantMap> properties = deviceInterface->asyncCall(QLatin1String("GetProperties"));
properties.waitForFinished();
if (!properties.isValid()) {
qCWarning(QT_BT_BLUEZ) << "Unable to get properties for device " << device.path();
@@ -525,13 +523,10 @@ void QBluetoothLocalDevicePrivate::createCache()
if (properties.value().value(QLatin1String("Connected")).toBool())
connectedDevicesSet.insert(QBluetoothAddress(properties.value().value(QLatin1String("Address")).toString()));
}
- connectedCached = true;
}
QList<QBluetoothAddress> QBluetoothLocalDevicePrivate::connectedDevices() const
{
- if (!connectedCached)
- const_cast<QBluetoothLocalDevicePrivate *>(this)->createCache();
return connectedDevicesSet.toList();
}
diff --git a/src/bluetooth/qbluetoothlocaldevice_p.h b/src/bluetooth/qbluetoothlocaldevice_p.h
index 61527d31..f00c33bf 100644
--- a/src/bluetooth/qbluetoothlocaldevice_p.h
+++ b/src/bluetooth/qbluetoothlocaldevice_p.h
@@ -168,8 +168,6 @@ private:
QBluetoothLocalDevice *q_ptr;
- bool connectedCached;
-
void initializeAdapter();
};
diff --git a/src/bluetooth/qbluetoothserver_p.h b/src/bluetooth/qbluetoothserver_p.h
index 4137986a..afd9d50f 100644
--- a/src/bluetooth/qbluetoothserver_p.h
+++ b/src/bluetooth/qbluetoothserver_p.h
@@ -97,6 +97,10 @@ public:
QBluetoothServiceInfo::Protocol serverType;
#ifdef QT_QNX_BLUETOOTH
+#ifdef QT_QNX_BT_BLUETOOTH
+ static void btCallback(long param, int socket);
+ Q_INVOKABLE void setBtCallbackParameters(int receivedSocket);
+#endif
QList<QBluetoothSocket *> activeSockets;
QString m_serviceName;
#endif
@@ -112,8 +116,10 @@ private:
QString nextClientAddress;
private Q_SLOTS:
+#ifndef QT_QNX_BT_BLUETOOTH
void controlReply(ppsResult result);
void controlEvent(ppsResult result);
+#endif
#elif defined(QT_BLUEZ_BLUETOOTH)
QSocketNotifier *socketNotifier;
#elif defined(QT_ANDROID_BLUETOOTH)
diff --git a/src/bluetooth/qbluetoothserver_qnx.cpp b/src/bluetooth/qbluetoothserver_qnx.cpp
index cc28296c..2aefa041 100644
--- a/src/bluetooth/qbluetoothserver_qnx.cpp
+++ b/src/bluetooth/qbluetoothserver_qnx.cpp
@@ -48,7 +48,9 @@
#include <QSocketNotifier>
#include <QCoreApplication>
-
+#ifdef QT_QNX_BT_BLUETOOTH
+#include <btapi/btspp.h>
+#endif
QT_BEGIN_NAMESPACE
extern QHash<QBluetoothServerPrivate*, int> __fakeServerPorts;
@@ -70,6 +72,42 @@ QBluetoothServerPrivate::~QBluetoothServerPrivate()
activeSockets.clear();
}
+#ifdef QT_QNX_BT_BLUETOOTH
+void QBluetoothServerPrivate::btCallback(long param, int socket)
+{
+ QBluetoothServerPrivate *impl = reinterpret_cast<QBluetoothServerPrivate*>(param);
+ QMetaObject::invokeMethod(impl, "setBtCallbackParameters",
+ Qt::BlockingQueuedConnection,
+ Q_ARG(int, socket));
+}
+
+void QBluetoothServerPrivate::setBtCallbackParameters(int receivedSocket)
+{
+ Q_Q(QBluetoothServer);
+ if (receivedSocket == -1) {
+ qCDebug(QT_BT_QNX) << "Socket error: " << qt_error_string(errno);
+ m_lastError = QBluetoothServer::InputOutputError;
+ emit q->error(m_lastError);
+ return;
+ }
+ socket->setSocketDescriptor(receivedSocket, QBluetoothServiceInfo::RfcommProtocol,
+ QBluetoothSocket::ConnectedState,
+ QBluetoothSocket::ReadWrite);
+ char addr[18];
+ if (bt_spp_get_address(receivedSocket, addr) == -1) {
+ qCDebug(QT_BT_QNX) << "Could not obtain the remote address. "
+ << qt_error_string(errno);
+ m_lastError = QBluetoothServer::InputOutputError;
+ emit q->error(m_lastError);
+ return;
+ }
+ socket->d_ptr->m_peerAddress = QBluetoothAddress(addr);
+ activeSockets.append(socket);
+ socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol, this);
+ socket->setSocketState(QBluetoothSocket::ListeningState);
+ emit q->newConnection();
+}
+#else
void QBluetoothServerPrivate::controlReply(ppsResult result)
{
Q_Q(QBluetoothServer);
@@ -130,6 +168,7 @@ void QBluetoothServerPrivate::controlEvent(ppsResult result)
}
}
}
+#endif
void QBluetoothServer::close()
{
@@ -142,12 +181,19 @@ void QBluetoothServer::close()
}
if (d->socket) {
d->socket->close();
- delete d->socket;
- d->socket = 0;
if (__fakeServerPorts.contains(d)) {
- ppsSendControlMessage("deregister_server", 0x1101, d->m_uuid, QString(), QString(), 0);
+#ifdef QT_QNX_BT_BLUETOOTH
+ QByteArray b_uuid = d->m_uuid.toByteArray();
+ b_uuid = b_uuid.mid(1, b_uuid.length()-2);
+ bt_spp_close_server(b_uuid.data());
+#else
+ ppsSendControlMessage("deregister_server", 0x1101, d->m_uuid,
+ QString(), QString(), 0);
+#endif
__fakeServerPorts.remove(d);
}
+ delete d->socket;
+ d->socket = 0;
}
}
@@ -206,9 +252,10 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
return false;
}
- d->socket->setSocketState(QBluetoothSocket::ListeningState);
-
+#ifndef QT_QNX_BT_BLUETOOTH
ppsRegisterForEvent(QStringLiteral("service_connected"),d);
+#endif
+ d->socket->setSocketState(QBluetoothSocket::ListeningState);
return true;
}
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
index 7e0e701d..36849eed 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
@@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE
\li and call start().
\endlist
- \snippet doc_src_qtbluetooth.cpp discovery
+ \snippet doc_src_qtbluetooth.cpp service_discovery
By default a minimal service discovery is performed. In this mode, the QBluetotohServiceInfo
objects returned are guaranteed to contain only device and service UUID information. Depending
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
index 0e782d5c..a842d3d9 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** 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.
@@ -240,9 +240,24 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_discoveredServices(QDBusPendingC
Q_Q(QBluetoothServiceDiscoveryAgent);
- discoveredServices.append(serviceInfo);
- qCDebug(QT_BT_BLUEZ) << "Discovered services" << discoveredDevices.at(0).address().toString();
- emit q->serviceDiscovered(serviceInfo);
+ //don't include the service if we already discovered it before
+ bool alreadyDiscovered = false;
+ for (int j = 0; j < discoveredServices.count(); j++) {
+ const QBluetoothServiceInfo &info = discoveredServices.at(j);
+ if (info.device() == serviceInfo.device()
+ && info.serviceClassUuids() == serviceInfo.serviceClassUuids()
+ && info.serviceUuid() == serviceInfo.serviceUuid()) {
+ alreadyDiscovered = true;
+ break;
+ }
+ }
+
+ if (!alreadyDiscovered) {
+ discoveredServices.append(serviceInfo);
+ qCDebug(QT_BT_BLUEZ) << "Discovered services" << discoveredDevices.at(0).address().toString();
+ emit q->serviceDiscovered(serviceInfo);
+ }
+
// could stop discovery, check for state
if(discoveryState() == Inactive){
qCDebug(QT_BT_BLUEZ) << "Exit discovery after stop";
diff --git a/src/bluetooth/qbluetoothserviceinfo_qnx.cpp b/src/bluetooth/qbluetoothserviceinfo_qnx.cpp
index 30dac958..8767889b 100644
--- a/src/bluetooth/qbluetoothserviceinfo_qnx.cpp
+++ b/src/bluetooth/qbluetoothserviceinfo_qnx.cpp
@@ -45,6 +45,11 @@
#include "qbluetoothserver_p.h"
#include "qbluetoothserver.h"
+#ifdef QT_QNX_BT_BLUETOOTH
+#include <btapi/btspp.h>
+#include <errno.h>
+#endif
+
QT_BEGIN_NAMESPACE
QBluetoothServiceInfoPrivate::QBluetoothServiceInfoPrivate()
@@ -70,11 +75,19 @@ bool QBluetoothServiceInfoPrivate::unregisterService()
if (serverChannel() == -1)
return false;
if ( __fakeServerPorts.key(serverChannel()) != 0) {
+#ifdef QT_QNX_BT_BLUETOOTH
+ QByteArray b_uuid = attributes.value(QBluetoothServiceInfo::ServiceId).
+ value<QBluetoothUuid>().toByteArray();
+ b_uuid = b_uuid.mid(1, b_uuid.length() - 2);
+ if (bt_spp_close_server(b_uuid.data()) == -1)
+ return false;
+#else
if (!ppsSendControlMessage("deregister_server", 0x1101, attributes.value(QBluetoothServiceInfo::ServiceId).value<QBluetoothUuid>(), QString(),
attributes.value(QBluetoothServiceInfo::ServiceName).toString(),
__fakeServerPorts.key(serverChannel()), BT_SPP_SERVER_SUBTYPE)) {
return false;
}
+#endif
else {
__fakeServerPorts.remove(__fakeServerPorts.key(serverChannel()));
registered = false;
@@ -98,10 +111,28 @@ bool QBluetoothServiceInfoPrivate::registerService(const QBluetoothAddress& loca
return false;
if (__fakeServerPorts.key(serverChannel()) != 0) {
+#ifdef QT_QNX_BT_BLUETOOTH
+ QByteArray b_uuid = attributes.value(QBluetoothServiceInfo::ServiceId)
+ .value<QBluetoothUuid>().toByteArray();
+ b_uuid = b_uuid.mid(1, b_uuid.length() - 2);
+ qCDebug(QT_BT_QNX) << "Registering server. " << b_uuid.data()
+ << attributes.value(QBluetoothServiceInfo::ServiceName)
+ .toString();
+ if (bt_spp_open_server(attributes.value(QBluetoothServiceInfo::ServiceName)
+ .toString().toUtf8().data(),
+ b_uuid.data(), true, &QBluetoothServerPrivate::btCallback,
+ reinterpret_cast<long>(__fakeServerPorts.key(serverChannel()))) == -1) {
+ qCDebug(QT_BT_QNX) << "Could not open the server. "
+ << qt_error_string(errno) << errno;
+ bt_spp_close_server(b_uuid.data());
+ return false;
+ }
+#else
if (!ppsSendControlMessage("register_server", 0x1101, attributes.value(QBluetoothServiceInfo::ServiceId).value<QBluetoothUuid>(), QString(),
attributes.value(QBluetoothServiceInfo::ServiceName).toString(),
__fakeServerPorts.key(serverChannel()), BT_SPP_SERVER_SUBTYPE))
return false;
+#endif
//The server needs to know the service name for the socket mount point path
__fakeServerPorts.key(serverChannel())->m_serviceName = attributes.value(QBluetoothServiceInfo::ServiceName).toString();
} else {
diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp
index 6272ca1f..0c514887 100644
--- a/src/bluetooth/qbluetoothsocket.cpp
+++ b/src/bluetooth/qbluetoothsocket.cpp
@@ -600,7 +600,12 @@ void QBluetoothSocket::abort()
Q_D(QBluetoothSocket);
d->abort();
+
+#ifndef QT_ANDROID_BLUETOOTH
+ //Android closes when the Java event loop comes around
setSocketState(QBluetoothSocket::UnconnectedState);
+ emit disconnected();
+#endif
}
void QBluetoothSocket::disconnectFromService()
@@ -666,7 +671,11 @@ void QBluetoothSocket::close()
d->close();
+#ifndef QT_ANDROID_BLUETOOTH
+ //Android closes when the Java event loop comes around
setSocketState(UnconnectedState);
+ emit disconnected();
+#endif
}
/*!
diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp
index 6aad6603..b9ed73a6 100644
--- a/src/bluetooth/qbluetoothsocket_bluez.cpp
+++ b/src/bluetooth/qbluetoothsocket_bluez.cpp
@@ -134,6 +134,12 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address,
Q_UNUSED(openMode);
int result = -1;
+ if (socket == -1 && !ensureNativeSocket(socketType)) {
+ errorString = QObject::tr("Unknown socket error");
+ q->setSocketError(QBluetoothSocket::UnknownSocketError);
+ return;
+ }
+
if (socketType == QBluetoothServiceInfo::RfcommProtocol) {
sockaddr_rc addr;
@@ -226,6 +232,7 @@ void QBluetoothSocketPrivate::_q_readNotify()
char *writePointer = buffer.reserve(QPRIVATELINEARBUFFER_BUFFERSIZE);
// qint64 readFromDevice = q->readData(writePointer, QPRIVATELINEARBUFFER_BUFFERSIZE);
int readFromDevice = ::read(socket, writePointer, QPRIVATELINEARBUFFER_BUFFERSIZE);
+ buffer.chop(QPRIVATELINEARBUFFER_BUFFERSIZE - (readFromDevice < 0 ? 0 : readFromDevice));
if(readFromDevice <= 0){
int errsv = errno;
readNotifier->setEnabled(false);
@@ -238,11 +245,8 @@ void QBluetoothSocketPrivate::_q_readNotify()
q->setSocketError(QBluetoothSocket::UnknownSocketError);
q->disconnectFromService();
- q->setSocketState(QBluetoothSocket::UnconnectedState);
}
else {
- buffer.chop(QPRIVATELINEARBUFFER_BUFFERSIZE - (readFromDevice < 0 ? 0 : readFromDevice));
-
emit q->readyRead();
}
}
@@ -259,9 +263,6 @@ void QBluetoothSocketPrivate::abort()
// QBluetoothSocket::close
QT_CLOSE(socket);
socket = -1;
-
- Q_Q(QBluetoothSocket);
- emit q->disconnected();
}
QString QBluetoothSocketPrivate::localName() const
@@ -508,17 +509,7 @@ void QBluetoothSocketPrivate::close()
connectWriteNotifier->setEnabled(true);
}
else {
-
- delete readNotifier;
- readNotifier = 0;
- delete connectWriteNotifier;
- connectWriteNotifier = 0;
-
- // We are disconnected now, so go to unconnected.
- q->setSocketState(QBluetoothSocket::UnconnectedState);
- emit q->disconnected();
- QT_CLOSE(socket);
- socket = -1;
+ abort();
}
}
diff --git a/src/bluetooth/qbluetoothsocket_qnx.cpp b/src/bluetooth/qbluetoothsocket_qnx.cpp
index ad4359e2..c54a0937 100644
--- a/src/bluetooth/qbluetoothsocket_qnx.cpp
+++ b/src/bluetooth/qbluetoothsocket_qnx.cpp
@@ -43,8 +43,15 @@
#include "qbluetoothsocket_p.h"
#include "qbluetoothlocaldevice.h"
#include <sys/stat.h>
+#ifdef QT_QNX_BT_BLUETOOTH
+#include <errno.h>
+#include <btapi/btspp.h>
+#endif
QT_BEGIN_NAMESPACE
+#ifdef QT_QNX_BT_BLUETOOTH
+static int initCounter = 0;
+#endif
QBluetoothSocketPrivate::QBluetoothSocketPrivate()
: socket(-1),
@@ -57,12 +64,28 @@ QBluetoothSocketPrivate::QBluetoothSocketPrivate()
discoveryAgent(0),
isServerSocket(false)
{
+#ifdef QT_QNX_BT_BLUETOOTH
+ if (!initCounter && (bt_spp_init() == -1))
+ qCDebug(QT_BT_QNX) << "Could not initialize Bluetooth library. "
+ << qt_error_string(errno);
+
+ initCounter++;
+#else
ppsRegisterControl();
+#endif
}
QBluetoothSocketPrivate::~QBluetoothSocketPrivate()
{
+#ifdef QT_QNX_BT_BLUETOOTH
+ if (initCounter == 1 && (bt_spp_deinit() == -1))
+ qCDebug(QT_BT_QNX) << "Could not deinitialize Bluetooth library."
+ "SPP connection is still open.";
+
+ initCounter--;
+#else
ppsUnregisterControl(this);
+#endif
close();
}
@@ -79,27 +102,47 @@ void QBluetoothSocketPrivate::connectToService(const QBluetoothAddress &address,
const QBluetoothUuid &uuid,
QIODevice::OpenMode openMode)
{
+ Q_Q(QBluetoothSocket);
Q_UNUSED(openMode);
qCDebug(QT_BT_QNX) << "Connecting socket";
- if (isServerSocket) {
- m_peerAddress = address;
- m_uuid = uuid;
+
+ m_peerAddress = address;
+#ifdef QT_QNX_BT_BLUETOOTH
+ QByteArray b_uuid = uuid.toByteArray();
+ b_uuid = b_uuid.mid(1, b_uuid.length() - 2);
+ socket = bt_spp_open(address.toString().toUtf8().data(), b_uuid.data(), false);
+ if (socket == -1) {
+ qCWarning(QT_BT_QNX) << "Could not connect to" << address.toString() << b_uuid << qt_error_string(errno);
+ errorString = qt_error_string(errno);
+ q->setSocketError(QBluetoothSocket::NetworkError);
return;
}
+ delete readNotifier;
+ delete connectWriteNotifier;
+
+ readNotifier = new QSocketNotifier(socket, QSocketNotifier::Read);
+ QObject::connect(readNotifier, SIGNAL(activated(int)), q, SLOT(_q_readNotify()));
+ connectWriteNotifier = new QSocketNotifier(socket, QSocketNotifier::Write, q);
+ QObject::connect(connectWriteNotifier, SIGNAL(activated(int)), q, SLOT(_q_writeNotify()));
+
+ connecting = true;
+ q->setOpenMode(openMode);
+#else
+ m_uuid = uuid;
+ if (isServerSocket)
+ return;
+
if (state != QBluetoothSocket::UnconnectedState) {
qCDebug(QT_BT_QNX) << "Socket already connected";
return;
}
- state = QBluetoothSocket::ConnectingState;
-
- m_uuid = uuid;
- m_peerAddress = address;
ppsSendControlMessage("connect_service", 0x1101, uuid, address.toString(), QString(), this, BT_SPP_CLIENT_SUBTYPE);
ppsRegisterForEvent(QStringLiteral("service_connected"),this);
ppsRegisterForEvent(QStringLiteral("get_mount_point_path"),this);
- socketType = QBluetoothServiceInfo::RfcommProtocol;
+#endif
+ q->setSocketState(QBluetoothSocket::ConnectingState);
}
void QBluetoothSocketPrivate::_q_writeNotify()
@@ -166,9 +209,16 @@ void QBluetoothSocketPrivate::abort()
{
Q_Q(QBluetoothSocket);
qCDebug(QT_BT_QNX) << "Disconnecting service";
+#ifdef QT_QNX_BT_BLUETOOTH
+ if (isServerSocket)
+ bt_spp_close_server(m_uuid.toString().toUtf8().data());
+ else
+ bt_spp_close(socket);
+#else
if (q->state() != QBluetoothSocket::ClosingState)
ppsSendControlMessage("disconnect_service", 0x1101, m_uuid, m_peerAddress.toString(), QString(), 0,
isServerSocket ? BT_SPP_SERVER_SUBTYPE : BT_SPP_CLIENT_SUBTYPE);
+#endif
delete readNotifier;
readNotifier = 0;
delete connectWriteNotifier;
@@ -176,8 +226,6 @@ void QBluetoothSocketPrivate::abort()
::close(socket);
- q->setSocketState(QBluetoothSocket::UnconnectedState);
- Q_EMIT q->disconnected();
isServerSocket = false;
}
@@ -284,11 +332,6 @@ bool QBluetoothSocketPrivate::setSocketDescriptor(int socketDescriptor, QBluetoo
socket = socketDescriptor;
socketType = socketType_;
- // ensure that O_NONBLOCK is set on new connections.
- int flags = fcntl(socket, F_GETFL, 0);
- if (!(flags & O_NONBLOCK))
- fcntl(socket, F_SETFL, flags | O_NONBLOCK);
-
readNotifier = new QSocketNotifier(socket, QSocketNotifier::Read);
QObject::connect(readNotifier, SIGNAL(activated(int)), q, SLOT(_q_readNotify()));
connectWriteNotifier = new QSocketNotifier(socket, QSocketNotifier::Write, q);
@@ -301,7 +344,9 @@ bool QBluetoothSocketPrivate::setSocketDescriptor(int socketDescriptor, QBluetoo
emit q->connected();
isServerSocket = true;
+#ifndef QT_QNX_BT_BLUETOOTH
ppsRegisterForEvent(QStringLiteral("service_disconnected"),this);
+#endif
return true;
}
@@ -313,6 +358,7 @@ qint64 QBluetoothSocketPrivate::bytesAvailable() const
void QBluetoothSocketPrivate::controlReply(ppsResult result)
{
+#ifndef QT_QNX_BT_BLUETOOTH
Q_Q(QBluetoothSocket);
if (result.msg == QStringLiteral("connect_service")) {
@@ -363,15 +409,18 @@ void QBluetoothSocketPrivate::controlReply(ppsResult result)
ppsRegisterForEvent(QStringLiteral("service_disconnected"),this);
}
}
+#endif
}
void QBluetoothSocketPrivate::controlEvent(ppsResult result)
{
+#ifndef QT_QNX_BT_BLUETOOTH
Q_Q(QBluetoothSocket);
if (result.msg == QStringLiteral("service_disconnected")) {
q->setSocketState(QBluetoothSocket::ClosingState);
close();
}
+#endif
}
QT_END_NAMESPACE
diff --git a/src/bluetooth/qbluetoothuuid.h b/src/bluetooth/qbluetoothuuid.h
index 014b975a..f33d8c13 100644
--- a/src/bluetooth/qbluetoothuuid.h
+++ b/src/bluetooth/qbluetoothuuid.h
@@ -174,11 +174,14 @@ public:
quint128 toUInt128() const;
};
+#ifndef QT_NO_DEBUG_STREAM
+/// TODO: Move implementation to .cpp, uninline and add Q_BLUETOOTH_EXPORT for Qt 6
inline QDebug operator<<(QDebug debug, const QBluetoothUuid &uuid)
{
debug << uuid.toString();
return debug;
}
+#endif
QT_END_NAMESPACE
diff --git a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
index 842d042d..d042bdfe 100644
--- a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
+++ b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp
@@ -403,6 +403,7 @@ void QDeclarativeBluetoothDiscoveryModel::setRunning(bool running)
}
d->m_serviceAgent->setRemoteAddress(QBluetoothAddress(d->m_remoteAddress));
+ d->m_serviceAgent->clear();
if (!d->m_uuid.isEmpty())
d->m_serviceAgent->setUuidFilter(QBluetoothUuid(d->m_uuid));
diff --git a/src/imports/bluetooth/qdeclarativebluetoothservice.cpp b/src/imports/bluetooth/qdeclarativebluetoothservice.cpp
index adff13db..e246ca8d 100644
--- a/src/imports/bluetooth/qdeclarativebluetoothservice.cpp
+++ b/src/imports/bluetooth/qdeclarativebluetoothservice.cpp
@@ -102,8 +102,6 @@ public:
delete m_service;
}
- int listen();
-
bool m_componentComplete;
QBluetoothServiceInfo *m_service;
QDeclarativeBluetoothService::Protocol m_protocol;
@@ -271,28 +269,6 @@ bool QDeclarativeBluetoothService::isRegistered() const
return d->m_service->isRegistered();
}
-
-int QDeclarativeBluetoothServicePrivate::listen() {
-
- if (m_service->socketProtocol() == QBluetoothServiceInfo::UnknownProtocol) {
- qCWarning(QT_BT_QML) << "Unknown protocol, can't make service" << m_protocol;
- return -1;
- }
- QBluetoothServiceInfo::Protocol serverType = QBluetoothServiceInfo::UnknownProtocol;
- if (m_service->socketProtocol() == QBluetoothServiceInfo::L2capProtocol)
- serverType = QBluetoothServiceInfo::L2capProtocol;
- else if (m_service->socketProtocol() == QBluetoothServiceInfo::RfcommProtocol)
- serverType = QBluetoothServiceInfo::RfcommProtocol;
-
- QBluetoothServer *server = new QBluetoothServer(serverType);
- server->setMaxPendingConnections(1);
- server->listen(QBluetoothAddress());
- server->serverPort();
- m_server = server;
-
- return server->serverPort();
-}
-
void QDeclarativeBluetoothService::setRegistered(bool registered)
{
if (!d->m_componentComplete) {
@@ -308,9 +284,21 @@ void QDeclarativeBluetoothService::setRegistered(bool registered)
return;
}
- d->listen();
- connect(d->m_server, SIGNAL(newConnection()), this, SLOT(new_connection()));
+ if (d->m_protocol == UnknownProtocol) {
+ qCWarning(QT_BT_QML) << "Unknown protocol, can't make service" << d->m_protocol;
+ return;
+ }
+
+ QBluetoothServer *server
+ = new QBluetoothServer(static_cast<QBluetoothServiceInfo::Protocol>(d->m_protocol));
+ server->setMaxPendingConnections(1);
+ if (!server->listen()) {
+ qCWarning(QT_BT_QML) << "Could not start server. Error:" << server->error();
+ return;
+ }
+ d->m_server = server;
+ connect(d->m_server, SIGNAL(newConnection()), this, SLOT(new_connection()));
d->m_service->setAttribute(QBluetoothServiceInfo::ServiceRecordHandle, (uint)0x00010010);
@@ -321,7 +309,7 @@ void QDeclarativeBluetoothService::setRegistered(bool registered)
//qDebug() << "name/uuid" << d->m_name << d->m_uuid << d->m_port;
d->m_service->setAttribute(QBluetoothServiceInfo::BrowseGroupList,
- QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
+ QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup));
QBluetoothServiceInfo::Sequence protocolDescriptorList;
QBluetoothServiceInfo::Sequence protocol;
@@ -329,26 +317,19 @@ void QDeclarativeBluetoothService::setRegistered(bool registered)
if (d->m_protocol == L2CapProtocol) {
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap))
<< QVariant::fromValue(quint16(d->m_server->serverPort()));
- protocolDescriptorList.append(QVariant::fromValue(protocol));
- }
- else if (d->m_protocol == RfcommProtocol) {
+ } else if (d->m_protocol == RfcommProtocol) {
protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
<< QVariant::fromValue(quint8(d->m_server->serverPort()));
- protocolDescriptorList.append(QVariant::fromValue(protocol));
- }
- else {
- qCWarning(QT_BT_QML) << "No protocol specified for bluetooth service";
}
+ protocolDescriptorList.append(QVariant::fromValue(protocol));
+
d->m_service->setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList,
- protocolDescriptorList);
+ protocolDescriptorList);
- if (d->m_service->registerService()) {
+ if (d->m_service->registerService())
emit registeredChanged();
- }
- else {
- qCWarning(QT_BT_QML) << "Register service failed";
- //TODO propaget this error to the user
- }
+ else
+ qCWarning(QT_BT_QML) << "Register service failed"; // TODO: propagate this error to the user
}
QBluetoothServiceInfo *QDeclarativeBluetoothService::serviceInfo() const
diff --git a/src/imports/bluetooth/qdeclarativebluetoothservice_p.h b/src/imports/bluetooth/qdeclarativebluetoothservice_p.h
index e7e861c7..644e8905 100644
--- a/src/imports/bluetooth/qdeclarativebluetoothservice_p.h
+++ b/src/imports/bluetooth/qdeclarativebluetoothservice_p.h
@@ -68,6 +68,7 @@ class QDeclarativeBluetoothService : public QObject, public QQmlParserStatus
Q_ENUMS(Protocol)
public:
+ /// TODO: Merge/Replace with QBluetoothServiceInfo::Protocol in Qt 6
enum Protocol {
RfcommProtocol = QBluetoothServiceInfo::RfcommProtocol,
L2CapProtocol = QBluetoothServiceInfo::L2capProtocol,
diff --git a/src/imports/bluetooth/qmldir b/src/imports/bluetooth/qmldir
index 159d2422..2f5b2fac 100644
--- a/src/imports/bluetooth/qmldir
+++ b/src/imports/bluetooth/qmldir
@@ -1,3 +1,4 @@
module QtBluetooth
plugin declarative_bluetooth
+classname QBluetoothQmlPlugin
typeinfo plugins.qmltypes
diff --git a/src/imports/nfc/qmldir b/src/imports/nfc/qmldir
index 3afa926d..0025f3e6 100644
--- a/src/imports/nfc/qmldir
+++ b/src/imports/nfc/qmldir
@@ -1,3 +1,4 @@
module QtNfc
plugin declarative_nfc
+classname QNfcQmlPlugin
typeinfo plugins.qmltypes
diff --git a/src/src.pro b/src/src.pro
index 6ab12bda..e017d34b 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -3,14 +3,14 @@ TEMPLATE = subdirs
SUBDIRS += bluetooth nfc
android: SUBDIRS += android
-!android {
+contains(QT_CONFIG, private_tests) {
bluetooth_doc_snippets.subdir = bluetooth/doc/snippets
bluetooth_doc_snippets.depends = bluetooth
- SUBDIRS += bluetooth_doc_snippets
nfc_doc_snippets.subdir = nfc/doc/snippets
nfc_doc_snippets.depends = nfc
- SUBDIRS += nfc_doc_snippets
+
+ SUBDIRS += bluetooth_doc_snippets nfc_doc_snippets
}
qtHaveModule(quick) {