summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-05-08 09:51:40 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-05-08 09:51:40 +0200
commit94445dd4b9a6754a63736a05b9bccaaffc0a4038 (patch)
treefedeb79f2a583da4935fcd8fc5f70298812c056d /src
parent74449f1b0b2952dcbad9525c167b36fbf908696f (diff)
parentef7de5da3d4d2346ec7110413c8fb12db8c94013 (diff)
Merge branch 'stable' into dev
Conflicts: .qmake.conf src/bluetooth/qbluetoothlocaldevice_bluez.cpp src/bluetooth/qbluetoothserver_p.h src/bluetooth/qbluetoothsocket_qnx.cpp Change-Id: I08792f10155f9b4e6af30066b70e24b48985ddd6
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/android/servicediscoverybroadcastreceiver.cpp6
-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.cpp48
-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_android.cpp23
-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
22 files changed, 307 insertions, 126 deletions
diff --git a/src/bluetooth/android/servicediscoverybroadcastreceiver.cpp b/src/bluetooth/android/servicediscoverybroadcastreceiver.cpp
index 0a3f97f9..87564ce6 100644
--- a/src/bluetooth/android/servicediscoverybroadcastreceiver.cpp
+++ b/src/bluetooth/android/servicediscoverybroadcastreceiver.cpp
@@ -76,8 +76,10 @@ void ServiceDiscoveryBroadcastReceiver::onReceive(JNIEnv *env, jobject context,
"getParcelableArrayExtra",
"(Ljava/lang/String;)[Landroid/os/Parcelable;",
keyExtra.object<jstring>());
- if (!parcelableUuids.isValid())
+ if (!parcelableUuids.isValid()) {
+ emit uuidFetchFinished(QBluetoothAddress(), QList<QBluetoothUuid>());
return;
+ }
const QList<QBluetoothUuid> result = ServiceDiscoveryBroadcastReceiver::convertParcelableArray(parcelableUuids);
keyExtra = valueForStaticField(JavaNames::BluetoothDevice, JavaNames::ExtraDevice);
@@ -89,6 +91,8 @@ void ServiceDiscoveryBroadcastReceiver::onReceive(JNIEnv *env, jobject context,
if (bluetoothDevice.isValid()) {
address = QBluetoothAddress(bluetoothDevice.callObjectMethod<jstring>("getAddress").toString());
emit uuidFetchFinished(address, result);
+ } else {
+ emit uuidFetchFinished(QBluetoothAddress(), QList<QBluetoothUuid>());
}
}
}
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 2c2cba11..0afca649 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 b9117ac8..6abcb2f8 100644
--- a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp
+++ b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp
@@ -648,8 +648,7 @@ QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice
discoveryWasAlreadyActive(true),
pendingHostModeChange(-1),
msgConnection(0),
- q_ptr(q),
- connectedCached(false)
+ q_ptr(q)
{
if (isBluez5())
initializeAdapterBluez5();
@@ -662,6 +661,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)),
@@ -978,7 +978,8 @@ void QBluetoothLocalDevicePrivate::_q_deviceCreated(const QDBusObjectPath &devic
{
OrgBluezDeviceInterface *deviceInterface
= new OrgBluezDeviceInterface(QLatin1String("org.bluez"),
- device.path(), QDBusConnection::systemBus());
+ device.path(),
+ QDBusConnection::systemBus(), this);
connect(deviceInterface, SIGNAL(PropertyChanged(QString, QDBusVariant)),
SLOT(_q_devicePropertyChanged(QString, QDBusVariant)));
devices << deviceInterface;
@@ -994,16 +995,13 @@ void QBluetoothLocalDevicePrivate::_q_deviceCreated(const QDBusObjectPath &devic
= 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)
@@ -1033,16 +1031,13 @@ void QBluetoothLocalDevicePrivate::_q_devicePropertyChanged(const QString &prope
= 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);
+ }
}
}
@@ -1058,11 +1053,16 @@ 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"));
+ = deviceInterface->asyncCall(QLatin1String("GetProperties"));
properties.waitForFinished();
if (!properties.isValid()) {
qCWarning(QT_BT_BLUEZ) << "Unable to get properties for device " << device.path();
@@ -1074,14 +1074,10 @@ void QBluetoothLocalDevicePrivate::createCache()
QBluetoothAddress(properties.value().value(QLatin1String("Address")).toString()));
}
}
- connectedCached = true;
}
QList<QBluetoothAddress> QBluetoothLocalDevicePrivate::connectedDevices() const
{
- if (adapter && !connectedCached)
- const_cast<QBluetoothLocalDevicePrivate *>(this)->createCache();
-
return connectedDevicesSet.toList();
}
diff --git a/src/bluetooth/qbluetoothlocaldevice_p.h b/src/bluetooth/qbluetoothlocaldevice_p.h
index 7fc82e2f..33f813e1 100644
--- a/src/bluetooth/qbluetoothlocaldevice_p.h
+++ b/src/bluetooth/qbluetoothlocaldevice_p.h
@@ -193,8 +193,6 @@ private:
QBluetoothLocalDevice *q_ptr;
- bool connectedCached;
-
void initializeAdapter();
void initializeAdapterBluez5();
};
diff --git a/src/bluetooth/qbluetoothserver_p.h b/src/bluetooth/qbluetoothserver_p.h
index 1a620645..492ad489 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 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_android.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
index 2e55d40e..2643d7a9 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent_android.cpp
@@ -246,6 +246,12 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_processFetchedUuids(
if (discoveredDevices.count() == 0)
return;
+ //could not find any service for the current address/device -> go to next one
+ if (address.isNull() || uuids.isEmpty()) {
+ _q_serviceDiscoveryFinished();
+ return;
+ }
+
if (QT_BT_ANDROID().isDebugEnabled()) {
qCDebug(QT_BT_ANDROID) << "Found UUID for" << address.toString()
<< "\ncount: " << uuids.count();
@@ -416,7 +422,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::populateDiscoveredServices(const QB
}
for (int i = 0; i < uuids.count(); i++) {
- if (i == sppIndex) //skip SPP service class id
+ if (i == sppIndex && !customUuids.isEmpty())
continue;
QBluetoothServiceInfo serviceInfo;
@@ -444,6 +450,21 @@ void QBluetoothServiceDiscoveryAgentPrivate::populateDiscoveredServices(const QB
serviceInfo.setServiceName(QBluetoothServiceDiscoveryAgent::tr("Serial Port Profile"));
serviceInfo.setServiceUuid(uuids.at(i));
+ } else if (sppIndex == i && customUuids.isEmpty()) {
+ //set rfcomm protocol
+ QBluetoothServiceInfo::Sequence protocol;
+ protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm))
+ << QVariant::fromValue(0);
+ protocolDescriptorList.append(QVariant::fromValue(protocol));
+
+ QBluetoothServiceInfo::Sequence classId;
+ classId << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::SerialPort));
+ serviceInfo.setAttribute(QBluetoothServiceInfo::BluetoothProfileDescriptorList,
+ classId);
+
+ //also we need to set the custom uuid to the SPP uuid
+ //otherwise QBluetoothSocket::connectToService() would fail due to a missing service uuid
+ serviceInfo.setServiceUuid(uuids.at(i));
} else if (customUuids.contains(i)) {
//custom uuid but no serial port
serviceInfo.setServiceUuid(uuids.at(i));
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 6e5c26ec..10f08aa5 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);
- 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 bb1d327c..d4974967 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) {