diff options
Diffstat (limited to 'src/imports/bluetooth/qdeclarativebluetoothservice.cpp')
-rw-r--r-- | src/imports/bluetooth/qdeclarativebluetoothservice.cpp | 63 |
1 files changed, 22 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 |