summaryrefslogtreecommitdiffstats
path: root/src/bluetooth
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-02-28 15:15:03 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-01 20:09:28 +0100
commit17d38319d205fd186ffbb638e53e43fde011c753 (patch)
tree7aac0462c81781547e797060e002c72f43f72537 /src/bluetooth
parent6c90b603cff92834ac7f58610fc6982ec801f2fd (diff)
Fix qrfcomm unit test
The patch also aligns the error behavior of QBluetoothServer::listen() across the various platforms. Task-number: QTBUG-22017 Change-Id: Ic81808c94d060ca07bd125afa842452e53efaec7 Reviewed-by: Nedim Hadzic <nedimhadzija@gmail.com> Reviewed-by: Fabian Bumberger <fbumberger@rim.com>
Diffstat (limited to 'src/bluetooth')
-rw-r--r--src/bluetooth/qbluetoothserver_android.cpp20
-rw-r--r--src/bluetooth/qbluetoothserver_bluez.cpp18
-rw-r--r--src/bluetooth/qbluetoothserver_p.cpp7
-rw-r--r--src/bluetooth/qbluetoothserver_qnx.cpp17
4 files changed, 53 insertions, 9 deletions
diff --git a/src/bluetooth/qbluetoothserver_android.cpp b/src/bluetooth/qbluetoothserver_android.cpp
index c7c798d3..f90c540e 100644
--- a/src/bluetooth/qbluetoothserver_android.cpp
+++ b/src/bluetooth/qbluetoothserver_android.cpp
@@ -127,9 +127,20 @@ void QBluetoothServer::close()
bool QBluetoothServer::listen(const QBluetoothAddress &localAdapter, quint16 port)
{
+ Q_D(QBluetoothServer);
+ if (serverType() != QBluetoothServiceInfo::RfcommProtocol) {
+ d->m_lastError = UnsupportedProtocolError;
+ emit error(d->m_lastError);
+ return false;
+ }
+
const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices();
- if (!localDevices.count())
+ if (!localDevices.count()) {
+ qCWarning(QT_BT_ANDROID) << "Device does not support Bluetooth";
+ d->m_lastError = QBluetoothServer::UnknownError;
+ emit error(d->m_lastError);
return false; //no Bluetooth device
+ }
if (!localAdapter.isNull()) {
bool found = false;
@@ -146,13 +157,6 @@ bool QBluetoothServer::listen(const QBluetoothAddress &localAdapter, quint16 por
}
}
- Q_D(QBluetoothServer);
- if (serverType() != QBluetoothServiceInfo::RfcommProtocol) {
- d->m_lastError = UnsupportedProtocolError;
- emit error(d->m_lastError);
- return false;
- }
-
if (d->isListening())
return false;
diff --git a/src/bluetooth/qbluetoothserver_bluez.cpp b/src/bluetooth/qbluetoothserver_bluez.cpp
index b78fb526..1ee055de 100644
--- a/src/bluetooth/qbluetoothserver_bluez.cpp
+++ b/src/bluetooth/qbluetoothserver_bluez.cpp
@@ -42,6 +42,7 @@
#include "qbluetoothserver.h"
#include "qbluetoothserver_p.h"
#include "qbluetoothsocket.h"
+#include "qbluetoothlocaldevice.h"
#include <QtCore/QLoggingCategory>
#include <QtCore/QSocketNotifier>
@@ -110,6 +111,23 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
return false; //already listening, nothing to do
}
+ QBluetoothLocalDevice device(address);
+ if (!device.isValid()) {
+ qCWarning(QT_BT_BLUEZ) << "Device does not support Bluetooth or"
+ << address.toString() << "is not a valid local adapter";
+ d->m_lastError = QBluetoothServer::UnknownError;
+ emit error(d->m_lastError);
+ return false;
+ }
+
+ QBluetoothLocalDevice::HostMode hostMode = device.hostMode();
+ if (hostMode == QBluetoothLocalDevice::HostPoweredOff) {
+ d->m_lastError = QBluetoothServer::PoweredOffError;
+ emit error(d->m_lastError);
+ qCWarning(QT_BT_BLUEZ) << "Bluetooth device is powered off";
+ return false;
+ }
+
int sock = d->socket->socketDescriptor();
if (sock < 0) {
/* Negative socket descriptor is not always an error case
diff --git a/src/bluetooth/qbluetoothserver_p.cpp b/src/bluetooth/qbluetoothserver_p.cpp
index 213d73f1..d9efcf2f 100644
--- a/src/bluetooth/qbluetoothserver_p.cpp
+++ b/src/bluetooth/qbluetoothserver_p.cpp
@@ -46,12 +46,17 @@
QT_BEGIN_NAMESPACE
QBluetoothServerPrivate::QBluetoothServerPrivate(QBluetoothServiceInfo::Protocol sType)
- : serverType(sType), m_lastError(QBluetoothServer::NoError)
+ : maxPendingConnections(1), serverType(sType), m_lastError(QBluetoothServer::NoError)
{
+ if (sType == QBluetoothServiceInfo::RfcommProtocol)
+ socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
+ else
+ socket = new QBluetoothSocket(QBluetoothServiceInfo::L2capProtocol);
}
QBluetoothServerPrivate::~QBluetoothServerPrivate()
{
+ delete socket;
}
void QBluetoothServer::close()
diff --git a/src/bluetooth/qbluetoothserver_qnx.cpp b/src/bluetooth/qbluetoothserver_qnx.cpp
index 5dfacfb2..63e92f4f 100644
--- a/src/bluetooth/qbluetoothserver_qnx.cpp
+++ b/src/bluetooth/qbluetoothserver_qnx.cpp
@@ -163,6 +163,23 @@ bool QBluetoothServer::listen(const QBluetoothAddress &address, quint16 port)
return false;
}
+ QBluetoothLocalDevice device(address);
+ if (!device.isValid()) {
+ qCWarning(QT_BT_QNX) << "Device does not support Bluetooth or"
+ << address.toString() << "is not a valid local adapter";
+ d->m_lastError = QBluetoothServer::UnknownError;
+ emit error(d->m_lastError);
+ return false;
+ }
+
+ QBluetoothLocalDevice::HostMode hostMode= device.hostMode();
+ if (hostMode == QBluetoothLocalDevice::HostPoweredOff) {
+ d->m_lastError = QBluetoothServer::PoweredOffError;
+ emit error(d->m_lastError);
+ qCWarning(QT_BT_QNX) << "Bluetooth device is powered off";
+ return false;
+ }
+
// listen has already been called before
if (!d->socket)
d->socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);