diff options
author | Alex Blasche <alexander.blasche@digia.com> | 2013-07-05 10:15:52 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-15 12:36:19 +0200 |
commit | 6c42b93e3f4e06e289af54920e0058baed9b4d33 (patch) | |
tree | deef7875d357204e1bb9958912979f8144ef82b3 /src/bluetooth | |
parent | 1f0771e2782652b7256eb079e38d0dff6a730794 (diff) |
Improve and fix the qbluetoothlocaldevice test
The Bluez code was not passing the test.
Task-number: QTBUG-22017
Change-Id: I0bc2fca7ec9d352481eea24c75b902c21b4fc0da
Reviewed-by: Aaron McCarthy <mccarthy.aaron@gmail.com>
Diffstat (limited to 'src/bluetooth')
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice.cpp | 6 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothlocaldevice_bluez.cpp | 50 |
2 files changed, 37 insertions, 19 deletions
diff --git a/src/bluetooth/qbluetoothlocaldevice.cpp b/src/bluetooth/qbluetoothlocaldevice.cpp index 0e1aa83a..68659d8a 100644 --- a/src/bluetooth/qbluetoothlocaldevice.cpp +++ b/src/bluetooth/qbluetoothlocaldevice.cpp @@ -224,9 +224,11 @@ bool QBluetoothLocalDevice::isValid() const */ /*! - \fn QBluetoothLocalDevice::pairingFinished(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing) + \fn QBluetoothLocalDevice::pairingFinished(const QBluetoothAddress &address, QBluetoothLocalDevice::Pairing pairing) - Pairing has completed with \a address. Current pairing status is in \a pairing. + Pairing or unpairing has completed with \a address. Current pairing status is in \a pairing. + If the pairing request was not successful, this signal will not be emitted. The error() signal + is emitted if the pairing request failed. */ /*! diff --git a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp index 742f0b5a..6a520158 100644 --- a/src/bluetooth/qbluetoothlocaldevice_bluez.cpp +++ b/src/bluetooth/qbluetoothlocaldevice_bluez.cpp @@ -107,20 +107,20 @@ void QBluetoothLocalDevice::setHostMode(QBluetoothLocalDevice::HostMode mode) switch (mode) { case HostDiscoverableLimitedInquiry: case HostDiscoverable: - d_ptr->adapter->SetProperty(QLatin1String("Powered"), QDBusVariant(QVariant::fromValue(true))); + if (hostMode() != HostPoweredOff) + d_ptr->adapter->SetProperty(QLatin1String("Powered"), QDBusVariant(QVariant::fromValue(true))); d_ptr->adapter->SetProperty(QLatin1String("Discoverable"), QDBusVariant(QVariant::fromValue(true))); break; case HostConnectable: - d_ptr->adapter->SetProperty(QLatin1String("Powered"), QDBusVariant(QVariant::fromValue(true))); + if (hostMode() != HostPoweredOff) + d_ptr->adapter->SetProperty(QLatin1String("Powered"), QDBusVariant(QVariant::fromValue(true))); d_ptr->adapter->SetProperty(QLatin1String("Discoverable"), QDBusVariant(QVariant::fromValue(false))); break; case HostPoweredOff: d_ptr->adapter->SetProperty(QLatin1String("Powered"), QDBusVariant(QVariant::fromValue(false))); -// d->adapter->SetProperty(QLatin1String("Discoverable"), -// QDBusVariant(QVariant::fromValue(false))); break; } } @@ -196,6 +196,16 @@ static inline OrgBluezDeviceInterface *getDevice(const QBluetoothAddress &addres void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pairing pairing) { + if (address.isNull()) { + emit error(PairingError); + return; + } + + const Pairing current_pairing = pairingStatus(address); + if (current_pairing == pairing) { + emit pairingFinished(address, pairing); + return; + } if(pairing == Paired || pairing == AuthorizedPaired) { @@ -206,20 +216,23 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai d_ptr->agent = new OrgBluezAgentAdaptor(d_ptr); bool res = QDBusConnection::systemBus().registerObject(d_ptr->agent_path, d_ptr); if(!res){ + emit error(PairingError); qDebug() << "Failed to register agent"; return; } } - Pairing current_pairing = pairingStatus(address); if(current_pairing == Paired && pairing == AuthorizedPaired){ OrgBluezDeviceInterface *device = getDevice(address, d_ptr); - if(!device) + if (!device) { + emit error(PairingError); return; + } QDBusPendingReply<> deviceReply = device->SetProperty(QLatin1String("Trusted"), QDBusVariant(true)); deviceReply.waitForFinished(); if(deviceReply.isError()){ qDebug() << Q_FUNC_INFO << "reply failed" << deviceReply.error(); + emit error(PairingError); return; } delete device; @@ -228,12 +241,15 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai } else if(current_pairing == AuthorizedPaired && pairing == Paired){ OrgBluezDeviceInterface *device = getDevice(address, d_ptr); - if(!device) + if (!device) { + emit error(PairingError); return; + } QDBusPendingReply<> deviceReply = device->SetProperty(QLatin1String("Trusted"), QDBusVariant(false)); deviceReply.waitForFinished(); if(deviceReply.isError()){ qDebug() << Q_FUNC_INFO << "reply failed" << deviceReply.error(); + emit error(PairingError); return; } delete device; @@ -258,20 +274,27 @@ void QBluetoothLocalDevice::requestPairing(const QBluetoothAddress &address, Pai reply.waitForFinished(); if(reply.isError()) { qDebug() << Q_FUNC_INFO << "failed to find device" << reply.error(); + emit error(QBluetoothLocalDevice::PairingError); return; } QDBusPendingReply<> removeReply = this->d_ptr->adapter->RemoveDevice(reply.value()); removeReply.waitForFinished(); if(removeReply.isError()){ qDebug() << Q_FUNC_INFO << "failed to remove device" << removeReply.error(); + emit error(QBluetoothLocalDevice::PairingError); + } else { + QMetaObject::invokeMethod(this, "pairingFinished", Qt::QueuedConnection, Q_ARG(QBluetoothAddress, address), + Q_ARG(QBluetoothLocalDevice::Pairing, QBluetoothLocalDevice::Unpaired)); } - return; } return; } QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluetoothAddress &address) const { + if (address.isNull()) + return Unpaired; + OrgBluezDeviceInterface *device = getDevice(address, d_ptr); if(!device) @@ -284,16 +307,12 @@ QBluetoothLocalDevice::Pairing QBluetoothLocalDevice::pairingStatus(const QBluet QVariantMap map = deviceReply.value(); -// qDebug() << "Paired: " << map.value("Paired"); - - if (map.value(QLatin1String("Trusted")).toBool() && map.value(QLatin1String("Paired")).toBool()) return AuthorizedPaired; else if (map.value(QLatin1String("Paired")).toBool()) return Paired; else return Unpaired; - } QBluetoothLocalDevicePrivate::QBluetoothLocalDevicePrivate(QBluetoothLocalDevice *q, QBluetoothAddress address) @@ -314,8 +333,6 @@ void QBluetoothLocalDevicePrivate::initializeAdapter() if (adapter) return; - qDebug() << "initialize adapter interface"; - OrgBluezManagerInterface manager(QLatin1String("org.bluez"), QLatin1String("/"), QDBusConnection::systemBus()); if (localAddress == QBluetoothAddress()) { @@ -416,7 +433,7 @@ void QBluetoothLocalDevicePrivate::pairingCompleted(QDBusPendingCallWatcher *wat if(reply.isError()) { qDebug() << Q_FUNC_INFO << "failed to create pairing" << reply.error(); - emit q->pairingFinished(address, QBluetoothLocalDevice::Unpaired); + emit q->error(QBluetoothLocalDevice::PairingError); delete watcher; return; } @@ -425,7 +442,7 @@ void QBluetoothLocalDevicePrivate::pairingCompleted(QDBusPendingCallWatcher *wat findReply.waitForFinished(); if(findReply.isError()) { qDebug() << Q_FUNC_INFO << "failed to find device" << findReply.error(); - emit q->pairingFinished(address, QBluetoothLocalDevice::Unpaired); + emit q->error(QBluetoothLocalDevice::PairingError); delete watcher; return; } @@ -515,7 +532,6 @@ void QBluetoothLocalDevicePrivate::PropertyChanged(QString property, QDBusVarian currentMode = mode; } -//#include "qbluetoothlocaldevice.moc" #include "moc_qbluetoothlocaldevice_p.cpp" QT_END_NAMESPACE_BLUETOOTH |