diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2014-02-17 10:38:48 +0100 |
---|---|---|
committer | Alex Blasche <alexander.blasche@digia.com> | 2014-02-17 10:38:48 +0100 |
commit | 8fe7fbe6b552b0d196967cfea85fede5e7c211b9 (patch) | |
tree | b90f246cc3b8847cedaf6b5f8dc045cfc563b9be /src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp | |
parent | 9bcb79f0c741f7805dad17c467a5c2041227a18a (diff) | |
parent | b4bde05d8459cc57c25bac3f7be19fcf03908606 (diff) | |
download | qtconnectivity-8fe7fbe6b552b0d196967cfea85fede5e7c211b9.tar.gz |
Merge branch 'dev' into btle
Conflicts:
examples/bluetooth/bluetooth.pro
src/bluetooth/doc/src/examples.qdoc
src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp
src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp
src/bluetooth/qbluetoothservicediscoveryagent_p.h
src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp
Change-Id: Ie1577e4b0f469cd5a6b05a61cbe94f180a64448d
Diffstat (limited to 'src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp')
-rw-r--r-- | src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp index 017f8410..f866b477 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +#include <QtCore/QLoggingCategory> #include "qbluetoothdevicediscoveryagent.h" #include "qbluetoothdevicediscoveryagent_p.h" #include "qbluetoothaddress.h" @@ -48,10 +49,10 @@ #include "bluez/adapter_p.h" #include "bluez/device_p.h" -//#define QT_DEVICEDISCOVERY_DEBUG - QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(QT_BT_BLUEZ) + QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(const QBluetoothAddress &deviceAdapter) : lastError(QBluetoothDeviceDiscoveryAgent::NoError), m_adapterAddress(deviceAdapter), pendingCancel(false), pendingStart(false), adapter(0) @@ -64,6 +65,7 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(con QBluetoothDeviceDiscoveryAgentPrivate::~QBluetoothDeviceDiscoveryAgentPrivate() { delete manager; + delete adapter; } bool QBluetoothDeviceDiscoveryAgentPrivate::isActive() const @@ -94,9 +96,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() if (reply.isError()) { errorString = reply.error().message(); -#ifdef QT_DEVICEDISCOVERY_DEBUG - qDebug() << Q_FUNC_INFO << "ERROR: " << errorString; -#endif + qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "ERROR: " << errorString; lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; Q_Q(QBluetoothDeviceDiscoveryAgent); emit q->error(lastError); @@ -116,11 +116,23 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() propertiesReply.waitForFinished(); if(propertiesReply.isError()) { errorString = propertiesReply.error().message(); -#ifdef QT_DEVICEDISCOVERY_DEBUG - qDebug() << Q_FUNC_INFO << "ERROR: " << errorString; -#endif + delete adapter; + adapter = 0; + qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "ERROR: " << errorString; lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; Q_Q(QBluetoothDeviceDiscoveryAgent); + delete adapter; + adapter = 0; + emit q->error(lastError); + return; + } + + if (!propertiesReply.value().value(QStringLiteral("Powered")).toBool()) { + qCDebug(QT_BT_BLUEZ) << "Aborting device discovery due to offline Bluetooth Adapter"; + lastError = QBluetoothDeviceDiscoveryAgent::PoweredOffError; + errorString = QBluetoothDeviceDiscoveryAgent::tr("Device is powered off"); + delete adapter; + adapter = 0; emit q->error(lastError); return; } @@ -133,9 +145,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; Q_Q(QBluetoothDeviceDiscoveryAgent); emit q->error(lastError); -#ifdef QT_DEVICEDISCOVERY_DEBUG - qDebug() << Q_FUNC_INFO << "ERROR: " << errorString; -#endif + qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << "ERROR: " << errorString; return; } } @@ -143,9 +153,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() void QBluetoothDeviceDiscoveryAgentPrivate::stop() { if (adapter) { -#ifdef QT_DEVICEDISCOVERY_DEBUG - qDebug() << Q_FUNC_INFO; -#endif + qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO; pendingCancel = true; pendingStart = false; QDBusPendingReply<> reply = adapter->StopDiscovery(); @@ -158,15 +166,13 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_deviceFound(const QString &addres { const QBluetoothAddress btAddress(address); const QString btName = dict.value(QLatin1String("Name")).toString(); - quint32 btClass = dict.value(QLatin1String("Class")).toUInt(); + quint32 btClass = dict.value(QLatin1String("Class")).toUInt(); -#ifdef QT_DEVICEDISCOVERY_DEBUG - qDebug() << "Discovered: " << address << btName + qCDebug(QT_BT_BLUEZ) << "Discovered: " << address << btName << "Num UUIDs" << dict.value(QLatin1String("UUIDs")).toStringList().count() << "total device" << discoveredDevices.count() << "cached" << dict.value(QLatin1String("Cached")).toBool() << "RSSI" << dict.value(QLatin1String("RSSI")).toInt(); -#endif QBluetoothDeviceInfo device(btAddress, btName, btClass); if(dict.value(QLatin1String("RSSI")).isValid()) @@ -190,24 +196,18 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_deviceFound(const QString &addres for(int i = 0; i < discoveredDevices.size(); i++){ if(discoveredDevices[i].address() == device.address()) { if(discoveredDevices[i] == device) { -#ifdef QT_DEVICEDISCOVERY_DEBUG - qDebug() << "Duplicate: " << address; -#endif + qCDebug(QT_BT_BLUEZ) << "Duplicate: " << address; return; } discoveredDevices.replace(i, device); Q_Q(QBluetoothDeviceDiscoveryAgent); -#ifdef QT_DEVICEDISCOVERY_DEBUG - qDebug() << "Updated: " << address; -#endif + qCDebug(QT_BT_BLUEZ) << "Updated: " << address; emit q->deviceDiscovered(device); return; // this works if the list doesn't contain duplicates. Don't let it. } } -#ifdef QT_DEVICEDISCOVERY_DEBUG - qDebug() << "Emit: " << address; -#endif + qCDebug(QT_BT_BLUEZ) << "Emit: " << address; discoveredDevices.append(device); Q_Q(QBluetoothDeviceDiscoveryAgent); emit q->deviceDiscovered(device); @@ -215,10 +215,8 @@ void QBluetoothDeviceDiscoveryAgentPrivate::_q_deviceFound(const QString &addres void QBluetoothDeviceDiscoveryAgentPrivate::_q_propertyChanged(const QString &name, const QDBusVariant &value) -{ -#ifdef QT_DEVICEDISCOVERY_DEBUG - qDebug() << Q_FUNC_INFO << name << value.variant(); -#endif +{ + qCDebug(QT_BT_BLUEZ) << Q_FUNC_INFO << name << value.variant(); if (name == QLatin1String("Discovering") && !value.variant().toBool()) { Q_Q(QBluetoothDeviceDiscoveryAgent); |