diff options
-rw-r--r-- | src/bluetooth/qbluetoothsocket.cpp | 12 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket_android.cpp | 15 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket_bluez.cpp | 1 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket_bluezdbus.cpp | 5 | ||||
-rw-r--r-- | src/bluetooth/qbluetoothsocket_winrt.cpp | 3 |
5 files changed, 16 insertions, 20 deletions
diff --git a/src/bluetooth/qbluetoothsocket.cpp b/src/bluetooth/qbluetoothsocket.cpp index 36e4a54c..62633bb1 100644 --- a/src/bluetooth/qbluetoothsocket.cpp +++ b/src/bluetooth/qbluetoothsocket.cpp @@ -518,10 +518,20 @@ QBluetooth::SecurityFlags QBluetoothSocket::preferredSecurityFlags() const void QBluetoothSocket::setSocketState(QBluetoothSocket::SocketState state) { Q_D(QBluetoothSocketBase); - SocketState old = d->state; + const SocketState old = d->state; + if (state == old) + return; + d->state = state; if(old != d->state) emit stateChanged(state); + if (state == QBluetoothSocket::ConnectedState) { + emit connected(); + } else if ((old == QBluetoothSocket::ConnectedState + || old == QBluetoothSocket::ClosingState) + && state == QBluetoothSocket::UnconnectedState) { + emit disconnected(); + } if(state == ListeningState){ // TODO: look at this, is this really correct? // if we're a listening socket we can't handle connects? diff --git a/src/bluetooth/qbluetoothsocket_android.cpp b/src/bluetooth/qbluetoothsocket_android.cpp index abb0c5e9..a478819b 100644 --- a/src/bluetooth/qbluetoothsocket_android.cpp +++ b/src/bluetooth/qbluetoothsocket_android.cpp @@ -626,7 +626,6 @@ void QBluetoothSocketPrivateAndroid::socketConnectSuccess(const QAndroidJniObjec q->setOpenMode(QIODevice::ReadWrite|QIODevice::Unbuffered); q->setSocketState(QBluetoothSocket::ConnectedState); - emit q->connected(); } void QBluetoothSocketPrivateAndroid::defaultSocketConnectFailed( @@ -714,10 +713,9 @@ void QBluetoothSocketPrivateAndroid::abort() // close() without further feedback. Therefore we have to set // Unconnected (now) in advance Q_Q(QBluetoothSocket); - q->setSocketState(QBluetoothSocket::UnconnectedState); q->setOpenMode(QIODevice::NotOpen); + q->setSocketState(QBluetoothSocket::UnconnectedState); emit q->readChannelFinished(); - emit q->disconnected(); } } } @@ -841,10 +839,9 @@ void QBluetoothSocketPrivateAndroid::inputThreadError(int errorCode) } } - q->setSocketState(QBluetoothSocket::UnconnectedState); q->setOpenMode(QIODevice::NotOpen); + q->setSocketState(QBluetoothSocket::UnconnectedState); emit q->readChannelFinished(); - emit q->disconnected(); } void QBluetoothSocketPrivateAndroid::close() @@ -917,10 +914,6 @@ bool QBluetoothSocketPrivateAndroid::setSocketDescriptor(const QAndroidJniObject this, SLOT(inputThreadError(int)), Qt::QueuedConnection); inputThread->run(); - - q->setSocketState(socketState); - q->setOpenMode(openMode | QIODevice::Unbuffered); - // WorkerThread manages all sockets for us // When we come through here the socket was already connected by // server socket listener (see QBluetoothServer) @@ -929,8 +922,8 @@ bool QBluetoothSocketPrivateAndroid::setSocketDescriptor(const QAndroidJniObject workerThread->setupWorker(this, socketObject, QAndroidJniObject(), !USE_FALLBACK); workerThread->start(); - if (socketState == QBluetoothSocket::ConnectedState) - emit q->connected(); + q->setOpenMode(openMode | QIODevice::Unbuffered); + q->setSocketState(socketState); return true; } diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp index 26ab40dd..f19c81b8 100644 --- a/src/bluetooth/qbluetoothsocket_bluez.cpp +++ b/src/bluetooth/qbluetoothsocket_bluez.cpp @@ -325,7 +325,6 @@ void QBluetoothSocketPrivateBluez::_q_writeNotify() } q->setSocketState(QBluetoothSocket::ConnectedState); - emit q->connected(); connectWriteNotifier->setEnabled(false); connecting = false; diff --git a/src/bluetooth/qbluetoothsocket_bluezdbus.cpp b/src/bluetooth/qbluetoothsocket_bluezdbus.cpp index c3055d63..c98d0c26 100644 --- a/src/bluetooth/qbluetoothsocket_bluezdbus.cpp +++ b/src/bluetooth/qbluetoothsocket_bluezdbus.cpp @@ -345,7 +345,6 @@ void QBluetoothSocketPrivateBluezDBus::abort() q->setOpenMode(QIODevice::NotOpen); q->setSocketState(QBluetoothSocket::UnconnectedState); emit q->readChannelFinished(); - emit q->disconnected(); } } @@ -542,7 +541,6 @@ void QBluetoothSocketPrivateBluezDBus::remoteConnected(const QDBusUnixFileDescri socket = descriptor; q->setSocketState(QBluetoothSocket::ConnectedState); - emit q->connected(); } } @@ -556,10 +554,9 @@ void QBluetoothSocketPrivateBluezDBus::socketStateChanged(QLocalSocket::LocalSoc break; case QLocalSocket::UnconnectedState: clearSocket(); - q->setSocketState(QBluetoothSocket::UnconnectedState); q->setOpenMode(QIODevice::NotOpen); + q->setSocketState(QBluetoothSocket::UnconnectedState); emit q->readChannelFinished(); - emit q->disconnected(); break; default: // ConnectingState and ConnectedState not mapped diff --git a/src/bluetooth/qbluetoothsocket_winrt.cpp b/src/bluetooth/qbluetoothsocket_winrt.cpp index f985952a..b4ffc61c 100644 --- a/src/bluetooth/qbluetoothsocket_winrt.cpp +++ b/src/bluetooth/qbluetoothsocket_winrt.cpp @@ -523,7 +523,6 @@ void QBluetoothSocketPrivateWinRT::abort() if (wasConnected) { q->setOpenMode(QIODevice::NotOpen); emit q->readChannelFinished(); - emit q->disconnected(); } } @@ -739,7 +738,6 @@ void QBluetoothSocketPrivateWinRT::handleError(QBluetoothSocket::SocketError err if (wasConnected) { q->setOpenMode(QIODevice::NotOpen); emit q->readChannelFinished(); - emit q->disconnected(); } } @@ -810,7 +808,6 @@ HRESULT QBluetoothSocketPrivateWinRT::handleConnectOpFinished(ABI::Windows::Foun q->setOpenMode(requestedOpenMode); q->setSocketState(QBluetoothSocket::ConnectedState); m_worker->startReading(); - emit q->connected(); return S_OK; } |