diff options
author | Fabian Bumberger <fbumberger@rim.com> | 2013-09-19 20:27:00 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-20 13:36:35 +0200 |
commit | ac2edceb02a61c1d670312385b1d709417961799 (patch) | |
tree | 3195e852c3ba79890ca187fce2373d5fe9f76a99 | |
parent | 559c648e41a5a3b33127fd3a786934bff7ecf828 (diff) |
Refactor device and service discovery errors
- Make them more consistent with other Qt modules
- Propagate the error during device discovery to the QBluetoothServiceDiscoveryAgent
Change-Id: Idcd3e0e6061b85e8b6adad248625740f3b91289a
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
11 files changed, 45 insertions, 66 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp index 69e52378..57136a65 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent.cpp @@ -69,8 +69,8 @@ QT_BEGIN_NAMESPACE Indicates all possible error conditions found during Bluetooth device discovery. \value NoError No error has occurred. - \value PoweredOff The Bluetooth adaptor is powered off, power it on before doing discovery. - \value IOFailure Writing or reading from the device resulted in an error. + \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. */ diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent.h b/src/bluetooth/qbluetoothdevicediscoveryagent.h index 170ef063..a311d14f 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent.h +++ b/src/bluetooth/qbluetoothdevicediscoveryagent.h @@ -64,14 +64,14 @@ public: // FIXME: add bluez error handling enum Error { NoError, - IOFailure, - PoweredOff, - UnknownError = 100 + InputOutputError, + PoweredOffError, + UnknownError = 100 //New errors must be added before Unknown error }; enum InquiryType { GeneralUnlimitedInquiry, - LimitedInquiry, + LimitedInquiry }; QBluetoothDeviceDiscoveryAgent(QObject *parent = 0); diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp index d10dcc4b..257ebf3d 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_bluez.cpp @@ -97,7 +97,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() #ifdef QT_DEVICEDISCOVERY_DEBUG qDebug() << Q_FUNC_INFO << "ERROR: " << errorString; #endif - lastError = QBluetoothDeviceDiscoveryAgent::IOFailure; + lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; Q_Q(QBluetoothDeviceDiscoveryAgent); emit q->error(lastError); return; @@ -115,11 +115,11 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() QDBusPendingReply<QVariantMap> propertiesReply = adapter->GetProperties(); propertiesReply.waitForFinished(); if(propertiesReply.isError()) { + errorString = propertiesReply.error().message(); #ifdef QT_DEVICEDISCOVERY_DEBUG qDebug() << Q_FUNC_INFO << "ERROR: " << errorString; #endif - errorString = propertiesReply.error().message(); - lastError = QBluetoothDeviceDiscoveryAgent::IOFailure; + lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; Q_Q(QBluetoothDeviceDiscoveryAgent); emit q->error(lastError); return; @@ -130,7 +130,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() delete adapter; adapter = 0; errorString = discoveryReply.error().message(); - lastError = QBluetoothDeviceDiscoveryAgent::IOFailure; + lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; Q_Q(QBluetoothDeviceDiscoveryAgent); emit q->error(lastError); #ifdef QT_DEVICEDISCOVERY_DEBUG diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp index b7184eeb..41920dbe 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_p.cpp @@ -67,9 +67,9 @@ bool QBluetoothDeviceDiscoveryAgentPrivate::isActive() const void QBluetoothDeviceDiscoveryAgentPrivate::start() { Q_Q(QBluetoothDeviceDiscoveryAgent); - lastError = QBluetoothDeviceDiscoveryAgent::IOFailure; + lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; errorString = QStringLiteral("No Bluetooth device available"); - emit q->error(QBluetoothDeviceDiscoveryAgent::IOFailure); + emit q->error(QBluetoothDeviceDiscoveryAgent::InputOutputError); } void QBluetoothDeviceDiscoveryAgentPrivate::stop() diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp index b7928749..f911a212 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_qnx.cpp @@ -96,7 +96,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() } else if ((m_rdfd = qt_safe_open("/pps/services/bluetooth/remote_devices/.all", O_RDONLY)) == -1) { qWarning() << Q_FUNC_INFO << "rdfd - failed to open /pps/services/bluetooth/remote_devices/.all" << m_rdfd; - lastError = QBluetoothDeviceDiscoveryAgent::IOFailure; + lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; emit q->error(lastError); stop(); return; @@ -104,7 +104,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() m_rdNotifier = new QSocketNotifier(m_rdfd, QSocketNotifier::Read, this); if (!m_rdNotifier) { qWarning() << Q_FUNC_INFO << "failed to connect to m_rdNotifier"; - lastError = QBluetoothDeviceDiscoveryAgent::IOFailure; + lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; emit q->error(lastError); stop(); return; @@ -118,7 +118,7 @@ void QBluetoothDeviceDiscoveryAgentPrivate::start() } else { qWarning() << "Could not write to control FD"; m_active = false; - q->error(QBluetoothDeviceDiscoveryAgent::IOFailure); + q->error(QBluetoothDeviceDiscoveryAgent::InputOutputError); return; } } @@ -214,18 +214,18 @@ void QBluetoothDeviceDiscoveryAgentPrivate::controlReply(ppsResult result) return; } else { qWarning("A PPS Bluetooth error occurred:"); - q_ptr->error(QBluetoothDeviceDiscoveryAgent::IOFailure); - lastError = QBluetoothDeviceDiscoveryAgent::IOFailure; + lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; errorString = result.errorMsg; + Q_EMIT q_ptr->error(QBluetoothDeviceDiscoveryAgent::InputOutputError); stop(); } processNextOp(); } else if (result.msg == QStringLiteral("cancel_device_search") && m_currentOp == Cancel && !isFinished) { qBBBluetoothDebug() << "Cancel device search"; // if (!result.errorMsg.isEmpty()) { -// lastError = QBluetoothDeviceDiscoveryAgent::IOFailure; +// lastError = QBluetoothDeviceDiscoveryAgent::InputOutputError; // errorString = result.errorMsg; -// q_ptr->error(QBluetoothDeviceDiscoveryAgent::IOFailure); +// q_ptr->error(QBluetoothDeviceDiscoveryAgent::InputOutputError); // } emit q->canceled(); processNextOp(); diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp index 35c2f795..023ffb80 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp @@ -74,9 +74,10 @@ QT_BEGIN_NAMESPACE This enum describes errors that can occur during service discovery. - \value NoError No error. - \value DeviceDiscoveryError Error occurred during device discovery. - \value UnknownError An unidentified error occurred. + \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 UnknownError An unknown error has occurred. */ /*! @@ -362,7 +363,8 @@ void QBluetoothServiceDiscoveryAgentPrivate::stopDeviceDiscovery() void QBluetoothServiceDiscoveryAgentPrivate::_q_deviceDiscoveryFinished() { if (deviceDiscoveryAgent->error() != QBluetoothDeviceDiscoveryAgent::NoError) { - error = QBluetoothServiceDiscoveryAgent::DeviceDiscoveryError; + //Forward the device discovery error + error = static_cast<QBluetoothServiceDiscoveryAgent::Error>(deviceDiscoveryAgent->error()); setDiscoveryState(Inactive); Q_Q(QBluetoothServiceDiscoveryAgent); diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.h b/src/bluetooth/qbluetoothservicediscoveryagent.h index 471ec81b..f4786f7e 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent.h +++ b/src/bluetooth/qbluetoothservicediscoveryagent.h @@ -48,6 +48,7 @@ #include <QtBluetooth/QBluetoothServiceInfo> #include <QtBluetooth/QBluetoothUuid> +#include <QtBluetooth/QBluetoothDeviceDiscoveryAgent> QT_BEGIN_NAMESPACE @@ -61,9 +62,12 @@ class Q_BLUETOOTH_EXPORT QBluetoothServiceDiscoveryAgent : public QObject public: enum Error { - NoError, - DeviceDiscoveryError, - UnknownError = 100 + NoError = QBluetoothDeviceDiscoveryAgent::NoError, + InputOutputError = QBluetoothDeviceDiscoveryAgent::InputOutputError, + PoweredOffError = QBluetoothDeviceDiscoveryAgent::PoweredOffError, + UnknownError = QBluetoothDeviceDiscoveryAgent::UnknownError //=100 + //New Errors must be added after Unknown Error the space before UnknownError is reserved + //for future device discovery errors }; enum DiscoveryMode { diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp index 13f759b2..1d86fed7 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_bluez.cpp @@ -89,7 +89,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr reply.waitForFinished(); if (reply.isError()) { - error = QBluetoothServiceDiscoveryAgent::DeviceDiscoveryError; + error = QBluetoothServiceDiscoveryAgent::InputOutputError; errorString = QBluetoothServiceDiscoveryAgent::tr("Unable to find appointed local adapter"); emit q->error(error); _q_serviceDiscoveryFinished(); @@ -150,7 +150,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_createdDevice(QDBusPendingCallWa deviceObjectPath.waitForFinished(); if (deviceObjectPath.isError()) { if (singleDevice) { - error = QBluetoothServiceDiscoveryAgent::DeviceDiscoveryError; + error = QBluetoothServiceDiscoveryAgent::InputOutputError; errorString = QBluetoothServiceDiscoveryAgent::tr("Unable to access device"); emit q->error(error); } diff --git a/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp b/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp index 60736ab7..c271a47f 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent_qnx.cpp @@ -76,7 +76,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr const char *filePath = QByteArray("/pps/services/bluetooth/remote_devices/").append(address.toString().toUtf8().constData()).constData(); if ((m_rdfd = qt_safe_open(filePath, O_RDONLY)) == -1) { qWarning() << "Failed to open " << filePath; - error = QBluetoothServiceDiscoveryAgent::DeviceDiscoveryError; + error = QBluetoothServiceDiscoveryAgent::InputOutputError; errorString = QStringLiteral("Failed to open remote device file"); q->error(error); _q_serviceDiscoveryFinished(); @@ -89,7 +89,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::start(const QBluetoothAddress &addr connect(rdNotifier, SIGNAL(activated(int)), this, SLOT(remoteDevicesChanged(int))); } else { qWarning() << "Service Discovery: Failed to connect to rdNotifier"; - error = QBluetoothServiceDiscoveryAgent::DeviceDiscoveryError; + error = QBluetoothServiceDiscoveryAgent::InputOutputError; errorString = QStringLiteral("Failed to connect to rdNotifier"); q->error(error); _q_serviceDiscoveryFinished(); @@ -206,7 +206,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::controlReply(ppsResult result) if (!result.errorMsg.isEmpty()) { qWarning() << Q_FUNC_INFO << result.errorMsg; errorString = result.errorMsg; - error = QBluetoothServiceDiscoveryAgent::DeviceDiscoveryError; + error = QBluetoothServiceDiscoveryAgent::InputOutputError; q->error(error); } else { _q_serviceDiscoveryFinished(); @@ -223,7 +223,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::controlEvent(ppsResult result) if (!result.errorMsg.isEmpty()) { qWarning() << Q_FUNC_INFO << result.errorMsg; errorString = result.errorMsg; - error = QBluetoothServiceDiscoveryAgent::DeviceDiscoveryError; + error = QBluetoothServiceDiscoveryAgent::InputOutputError; q->error(error); } else { _q_serviceDiscoveryFinished(); @@ -233,7 +233,7 @@ void QBluetoothServiceDiscoveryAgentPrivate::controlEvent(ppsResult result) void QBluetoothServiceDiscoveryAgentPrivate::queryTimeout() { Q_Q(QBluetoothServiceDiscoveryAgent); - error = QBluetoothServiceDiscoveryAgent::DeviceDiscoveryError; + error = QBluetoothServiceDiscoveryAgent::UnknownError; errorString = QStringLiteral("Service query timed out"); q->error(error); _q_serviceDiscoveryFinished(); diff --git a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp index 47ea4b6d..97265b4f 100644 --- a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp +++ b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel.cpp @@ -135,36 +135,13 @@ void QDeclarativeBluetoothDiscoveryModel::componentComplete() void QDeclarativeBluetoothDiscoveryModel::errorDiscovery(QBluetoothServiceDiscoveryAgent::Error error) { - switch (error) { - case QBluetoothServiceDiscoveryAgent::DeviceDiscoveryError: - d->m_error = DeviceDiscoveryError; - break; - case QBluetoothServiceDiscoveryAgent::UnknownError: - d->m_error = UnknownError; - break; - default: - d->m_error = UnknownError; - break; - } + d->m_error = static_cast<QDeclarativeBluetoothDiscoveryModel::Error>(error); emit errorChanged(); } void QDeclarativeBluetoothDiscoveryModel::errorDeviceDiscovery(QBluetoothDeviceDiscoveryAgent::Error error) { - switch (error) { - case QBluetoothDeviceDiscoveryAgent::IOFailure: - d->m_error = IOFailure; - break; - case QBluetoothDeviceDiscoveryAgent::PoweredOff: - d->m_error = PoweredOffFailure; - break; - case QBluetoothDeviceDiscoveryAgent::UnknownError: - d->m_error = UnknownError; - break; - default: - d->m_error = UnknownError; - break; - } + d->m_error = static_cast<QDeclarativeBluetoothDiscoveryModel::Error>(error); emit errorChanged(); } @@ -185,13 +162,10 @@ void QDeclarativeBluetoothDiscoveryModel::clearModel() \header \li Property \li Description \row \li \c BluetoothDiscoveryModel.NoError \li No error occurred. - \row \li \c BluetoothDiscoveryModel.IOFailure + \row \li \c BluetoothDiscoveryModel.InputOutputError \li An IO failure occurred during device discovery - \row \li \c BluetoothDiscoveryModel.PoweredOffFailure + \row \li \c BluetoothDiscoveryModel.PoweredOffError \li The bluetooth device is not powered on. - \row \li \c BluetoothDiscoveryModel.DeviceDiscoveryError - \li In order to be able to discover services a device discovery is started first. - This error indicates that a problem detected there. \row \li \c BluetoothDiscoveryModel.UnknownError \li An unknown error occurred. \endtable diff --git a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h index a675f1ce..feb1a5e1 100644 --- a/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h +++ b/src/imports/bluetooth/qdeclarativebluetoothdiscoverymodel_p.h @@ -89,9 +89,8 @@ public: enum Error { NoError, - IOFailure, - PoweredOffFailure, - DeviceDiscoveryError, + InputOutputError, + PoweredOffError, UnknownError }; |