diff options
Diffstat (limited to 'rockworkd/libpebble/watchconnection.cpp')
| -rw-r--r-- | rockworkd/libpebble/watchconnection.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/rockworkd/libpebble/watchconnection.cpp b/rockworkd/libpebble/watchconnection.cpp index 0778a1d..dabacf4 100644 --- a/rockworkd/libpebble/watchconnection.cpp +++ b/rockworkd/libpebble/watchconnection.cpp @@ -32,7 +32,7 @@ UploadManager *WatchConnection::uploadManager() const void WatchConnection::scheduleReconnect() { - if (m_connectionAttempts == 0) { + if (m_connectionAttempts < 2) { reconnect(); } else if (m_connectionAttempts < 25) { qDebug() << "Attempting to reconnect in 10 seconds"; @@ -49,21 +49,27 @@ void WatchConnection::scheduleReconnect() void WatchConnection::reconnect() { QBluetoothLocalDevice localBtDev; + qDebug() << "Reconnection"; if (localBtDev.pairingStatus(m_pebbleAddress) == QBluetoothLocalDevice::Unpaired) { // Try again in one 10 secs, give the user some time to pair it + qDebug() << "Unpaired."; m_connectionAttempts = 1; scheduleReconnect(); return; } if (m_socket) { + qDebug() << "Socket exists."; if (m_socket->state() == QBluetoothSocket::ConnectedState) { qDebug() << "Already connected."; return; } - delete m_socket; + m_socket->deleteLater(); } + m_connectionAttempts++; + + qDebug() << "Creating socket."; m_socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol, this); connect(m_socket, &QBluetoothSocket::connected, this, &WatchConnection::pebbleConnected); connect(m_socket, &QBluetoothSocket::readyRead, this, &WatchConnection::readyRead); @@ -71,7 +77,6 @@ void WatchConnection::reconnect() connect(m_socket, &QBluetoothSocket::disconnected, this, &WatchConnection::pebbleDisconnected); //connect(socket, SIGNAL(bytesWritten(qint64)), SLOT(onBytesWritten(qint64))); - m_connectionAttempts++; // FIXME: Assuming port 1 (with Pebble) m_socket->connectToService(m_pebbleAddress, 1); @@ -141,8 +146,12 @@ void WatchConnection::pebbleConnected() void WatchConnection::pebbleDisconnected() { qDebug() << "Disconnected"; - m_socket->close(); + emit watchDisconnected(); + QBluetoothSocket *socket = qobject_cast<QBluetoothSocket *>(sender()); + if (!socket) return; + + socket->deleteLater(); if (!m_reconnectTimer.isActive()) { scheduleReconnect(); } @@ -152,7 +161,6 @@ void WatchConnection::socketError(QBluetoothSocket::SocketError error) { Q_UNUSED(error); // We seem to get UnknownError anyways all the time qDebug() << "SocketError" << error; - m_socket->close(); emit watchConnectionFailed(); if (!m_reconnectTimer.isActive()) { scheduleReconnect(); |
