summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent.cpp17
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent.h1
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent.cpp20
-rw-r--r--src/bluetooth/qbluetoothservicediscoveryagent.h1
4 files changed, 36 insertions, 3 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
index 57136a65..99ceaabe 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp
@@ -38,6 +38,7 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include "qbluetoothhostinfo.h"
#include "qbluetoothdevicediscoveryagent.h"
#include "qbluetoothdevicediscoveryagent_p.h"
@@ -71,6 +72,7 @@ QT_BEGIN_NAMESPACE
\value NoError No error has occurred.
\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 An invalid Bluetooth adapter was specified
\value UnknownError An unknown error has occurred.
*/
@@ -137,11 +139,24 @@ QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(QObject *parent)
Constructs a new Bluetooth device discovery agent with parent \a parent and uses the adapter \a deviceAdapter
for the device search. If \a deviceAdapter is default constructed the resulting
QBluetoothDeviceDiscoveryAgent object will use the local default Bluetooth adapter.
+ If an invalid Bluetooth adapter address is specified, \a error will be set to
+ \a InvalidBluetoothAdapterError.
+
+ \sa error
*/
QBluetoothDeviceDiscoveryAgent::QBluetoothDeviceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, QObject *parent)
: QObject(parent), d_ptr(new QBluetoothDeviceDiscoveryAgentPrivate(deviceAdapter))
{
d_ptr->q_ptr = this;
+ if (!deviceAdapter.isNull()) {
+ const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices();
+ foreach (const QBluetoothHostInfo &hostInfo, localDevices) {
+ if (hostInfo.address() == deviceAdapter)
+ return;
+ }
+ d_ptr->lastError = InvalidBluetoothAdapterError;
+ d_ptr->errorString = tr("Invalid Bluetooth adapter address");
+ }
}
/*!
@@ -194,7 +209,7 @@ QList<QBluetoothDeviceInfo> QBluetoothDeviceDiscoveryAgent::discoveredDevices()
void QBluetoothDeviceDiscoveryAgent::start()
{
Q_D(QBluetoothDeviceDiscoveryAgent);
- if (!isActive())
+ if (!isActive() && d->lastError != InvalidBluetoothAdapterError)
d->start();
}
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.h b/src/bluetooth/qbluetoothdevicediscoveryagent.h
index a311d14f..4ac1685e 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent.h
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent.h
@@ -66,6 +66,7 @@ public:
NoError,
InputOutputError,
PoweredOffError,
+ InvalidBluetoothAdapterError,
UnknownError = 100 //New errors must be added before Unknown error
};
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
index 1bf31245..ea275ad8 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp
+++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp
@@ -39,6 +39,8 @@
**
****************************************************************************/
+#include "qbluetoothhostinfo.h"
+#include "qbluetoothlocaldevice.h"
#include "qbluetoothservicediscoveryagent.h"
#include "qbluetoothservicediscoveryagent_p.h"
@@ -78,6 +80,7 @@ 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 UnknownError An unknown error has occurred.
+ \value InvalidBluetoothAdapterError An invalid Bluetooth adapter was specified
*/
/*!
@@ -123,12 +126,24 @@ QBluetoothServiceDiscoveryAgent::QBluetoothServiceDiscoveryAgent(QObject *parent
/*!
Constructs a new QBluetoothServiceDiscoveryAgent for \a deviceAdapter and with \a parent.
- If \a deviceAdapter is null, the default adapter will be used.
+ If \a deviceAdapter is null, the default adapter will be used. If an invalid Bluetooth adapter address
+ is specified, \a error will be set to \a InvalidBluetoothAdapterError.
+
+ \sa error
*/
QBluetoothServiceDiscoveryAgent::QBluetoothServiceDiscoveryAgent(const QBluetoothAddress &deviceAdapter, QObject *parent)
: QObject(parent), d_ptr(new QBluetoothServiceDiscoveryAgentPrivate(deviceAdapter))
{
d_ptr->q_ptr = this;
+ if (!deviceAdapter.isNull()) {
+ const QList<QBluetoothHostInfo> localDevices = QBluetoothLocalDevice::allDevices();
+ foreach (const QBluetoothHostInfo &hostInfo, localDevices) {
+ if (hostInfo.address() == deviceAdapter)
+ return;
+ }
+ d_ptr->error = InvalidBluetoothAdapterError;
+ d_ptr->errorString = tr("Invalid Bluetooth adapter address");
+ }
}
/*!
@@ -234,7 +249,8 @@ void QBluetoothServiceDiscoveryAgent::start(DiscoveryMode mode)
{
Q_D(QBluetoothServiceDiscoveryAgent);
- if (d->discoveryState() == QBluetoothServiceDiscoveryAgentPrivate::Inactive) {
+ if (d->discoveryState() == QBluetoothServiceDiscoveryAgentPrivate::Inactive
+ && d->error != InvalidBluetoothAdapterError) {
d->setDiscoveryMode(mode);
if (d->deviceAddress.isNull()) {
d->startDeviceDiscovery();
diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.h b/src/bluetooth/qbluetoothservicediscoveryagent.h
index f923c2d0..cad89d0d 100644
--- a/src/bluetooth/qbluetoothservicediscoveryagent.h
+++ b/src/bluetooth/qbluetoothservicediscoveryagent.h
@@ -65,6 +65,7 @@ public:
NoError = QBluetoothDeviceDiscoveryAgent::NoError,
InputOutputError = QBluetoothDeviceDiscoveryAgent::InputOutputError,
PoweredOffError = QBluetoothDeviceDiscoveryAgent::PoweredOffError,
+ InvalidBluetoothAdapterError = QBluetoothDeviceDiscoveryAgent::InvalidBluetoothAdapterError,
UnknownError = QBluetoothDeviceDiscoveryAgent::UnknownError //=100
//New Errors must be added after Unknown Error the space before UnknownError is reserved
//for future device discovery errors