diff options
author | Oleg Shparber <trollixx@gmail.com> | 2014-04-22 03:00:51 -0700 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-22 13:49:51 +0200 |
commit | fe0ced588437b575a6e443f8806269b044ff4f52 (patch) | |
tree | 493a1805485a80c888b1c5f0d0bd82889667df46 /src/imports | |
parent | c71404f34cc6a2fa6b52ab7adcfc72f8fa795b0e (diff) |
Fix crash in QDeclarativeBluetoothService
The crash was caused by the listen() always returning -1 because the
condition m_service->socketProtocol() == UnknownProtocol was always true.
Change-Id: I13725bb13db3e7000e01a80601fdcb3380710798
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/bluetooth/qdeclarativebluetoothservice.cpp | 63 | ||||
-rw-r--r-- | src/imports/bluetooth/qdeclarativebluetoothservice_p.h | 1 |
2 files changed, 23 insertions, 41 deletions
diff --git a/src/imports/bluetooth/qdeclarativebluetoothservice.cpp b/src/imports/bluetooth/qdeclarativebluetoothservice.cpp index adff13db..e246ca8d 100644 --- a/src/imports/bluetooth/qdeclarativebluetoothservice.cpp +++ b/src/imports/bluetooth/qdeclarativebluetoothservice.cpp @@ -102,8 +102,6 @@ public: delete m_service; } - int listen(); - bool m_componentComplete; QBluetoothServiceInfo *m_service; QDeclarativeBluetoothService::Protocol m_protocol; @@ -271,28 +269,6 @@ bool QDeclarativeBluetoothService::isRegistered() const return d->m_service->isRegistered(); } - -int QDeclarativeBluetoothServicePrivate::listen() { - - if (m_service->socketProtocol() == QBluetoothServiceInfo::UnknownProtocol) { - qCWarning(QT_BT_QML) << "Unknown protocol, can't make service" << m_protocol; - return -1; - } - QBluetoothServiceInfo::Protocol serverType = QBluetoothServiceInfo::UnknownProtocol; - if (m_service->socketProtocol() == QBluetoothServiceInfo::L2capProtocol) - serverType = QBluetoothServiceInfo::L2capProtocol; - else if (m_service->socketProtocol() == QBluetoothServiceInfo::RfcommProtocol) - serverType = QBluetoothServiceInfo::RfcommProtocol; - - QBluetoothServer *server = new QBluetoothServer(serverType); - server->setMaxPendingConnections(1); - server->listen(QBluetoothAddress()); - server->serverPort(); - m_server = server; - - return server->serverPort(); -} - void QDeclarativeBluetoothService::setRegistered(bool registered) { if (!d->m_componentComplete) { @@ -308,9 +284,21 @@ void QDeclarativeBluetoothService::setRegistered(bool registered) return; } - d->listen(); - connect(d->m_server, SIGNAL(newConnection()), this, SLOT(new_connection())); + if (d->m_protocol == UnknownProtocol) { + qCWarning(QT_BT_QML) << "Unknown protocol, can't make service" << d->m_protocol; + return; + } + + QBluetoothServer *server + = new QBluetoothServer(static_cast<QBluetoothServiceInfo::Protocol>(d->m_protocol)); + server->setMaxPendingConnections(1); + if (!server->listen()) { + qCWarning(QT_BT_QML) << "Could not start server. Error:" << server->error(); + return; + } + d->m_server = server; + connect(d->m_server, SIGNAL(newConnection()), this, SLOT(new_connection())); d->m_service->setAttribute(QBluetoothServiceInfo::ServiceRecordHandle, (uint)0x00010010); @@ -321,7 +309,7 @@ void QDeclarativeBluetoothService::setRegistered(bool registered) //qDebug() << "name/uuid" << d->m_name << d->m_uuid << d->m_port; d->m_service->setAttribute(QBluetoothServiceInfo::BrowseGroupList, - QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup)); + QBluetoothUuid(QBluetoothUuid::PublicBrowseGroup)); QBluetoothServiceInfo::Sequence protocolDescriptorList; QBluetoothServiceInfo::Sequence protocol; @@ -329,26 +317,19 @@ void QDeclarativeBluetoothService::setRegistered(bool registered) if (d->m_protocol == L2CapProtocol) { protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::L2cap)) << QVariant::fromValue(quint16(d->m_server->serverPort())); - protocolDescriptorList.append(QVariant::fromValue(protocol)); - } - else if (d->m_protocol == RfcommProtocol) { + } else if (d->m_protocol == RfcommProtocol) { protocol << QVariant::fromValue(QBluetoothUuid(QBluetoothUuid::Rfcomm)) << QVariant::fromValue(quint8(d->m_server->serverPort())); - protocolDescriptorList.append(QVariant::fromValue(protocol)); - } - else { - qCWarning(QT_BT_QML) << "No protocol specified for bluetooth service"; } + protocolDescriptorList.append(QVariant::fromValue(protocol)); + d->m_service->setAttribute(QBluetoothServiceInfo::ProtocolDescriptorList, - protocolDescriptorList); + protocolDescriptorList); - if (d->m_service->registerService()) { + if (d->m_service->registerService()) emit registeredChanged(); - } - else { - qCWarning(QT_BT_QML) << "Register service failed"; - //TODO propaget this error to the user - } + else + qCWarning(QT_BT_QML) << "Register service failed"; // TODO: propagate this error to the user } QBluetoothServiceInfo *QDeclarativeBluetoothService::serviceInfo() const diff --git a/src/imports/bluetooth/qdeclarativebluetoothservice_p.h b/src/imports/bluetooth/qdeclarativebluetoothservice_p.h index e7e861c7..644e8905 100644 --- a/src/imports/bluetooth/qdeclarativebluetoothservice_p.h +++ b/src/imports/bluetooth/qdeclarativebluetoothservice_p.h @@ -68,6 +68,7 @@ class QDeclarativeBluetoothService : public QObject, public QQmlParserStatus Q_ENUMS(Protocol) public: + /// TODO: Merge/Replace with QBluetoothServiceInfo::Protocol in Qt 6 enum Protocol { RfcommProtocol = QBluetoothServiceInfo::RfcommProtocol, L2CapProtocol = QBluetoothServiceInfo::L2capProtocol, |