summaryrefslogtreecommitdiff
path: root/daemon/watchconnector.cpp
diff options
context:
space:
mode:
authorTomasz Sterna <tomek@xiaoka.com>2014-07-11 23:41:27 +0200
committerTomasz Sterna <tomek@xiaoka.com>2014-07-11 23:41:27 +0200
commitc84773de3af76832d15806647d8529c2e5b75257 (patch)
tree0e49df1db6e2989629a4fadf5d1ba4c48ac516f9 /daemon/watchconnector.cpp
parent6a8cdaf2f718fef8a826fd98241050a7d3cbfb3d (diff)
Fixed reconnect on disconnection
Reconnection timeut will now raise gradually, to be 1000ms * reconnect attempt. This should help preserve power in the phone, when no Pebble is around. You can speed-up this process by reconnecting manually from manager app or its cover. Also force channel 1 for RFCOMM, as discovery does not work anymore after disconnection.
Diffstat (limited to 'daemon/watchconnector.cpp')
-rw-r--r--daemon/watchconnector.cpp19
1 files changed, 14 insertions, 5 deletions
diff --git a/daemon/watchconnector.cpp b/daemon/watchconnector.cpp
index d999229..d0fcdad 100644
--- a/daemon/watchconnector.cpp
+++ b/daemon/watchconnector.cpp
@@ -4,11 +4,14 @@
using namespace watch;
-static int __reconnect_timeout = 5000; //ms
+static int __reconnect_timeout = 1000; //ms
WatchConnector::WatchConnector(QObject *parent) :
QObject(parent), socket(nullptr), is_connected(false)
-{}
+{
+ reconnectTimer.setSingleShot(true);
+ connect(&reconnectTimer, SIGNAL(timeout()), SLOT(reconnect()));
+}
WatchConnector::~WatchConnector()
{
@@ -43,11 +46,14 @@ void WatchConnector::disconnect()
logger()->debug() << __FUNCTION__;
socket->close();
socket->deleteLater();
+ reconnectTimer.stop();
+ logger()->debug() << "Stopped reconnect timer";
}
void WatchConnector::handleWatch(const QString &name, const QString &address)
{
logger()->debug() << "handleWatch " << name << " " << address;
+ reconnectTimer.stop();
if (socket != nullptr && socket->isOpen()) {
socket->close();
socket->deleteLater();
@@ -67,7 +73,7 @@ void WatchConnector::handleWatch(const QString &name, const QString &address)
connect(socket, SIGNAL(error(QBluetoothSocket::SocketError)), this, SLOT(onError(QBluetoothSocket::SocketError)));
// FIXME: Assuming port 1 (with Pebble)
- socket->connectToService(QBluetoothAddress(address), QBluetoothUuid(QBluetoothUuid::SerialPort));
+ socket->connectToService(QBluetoothAddress(address), 1);
}
QString WatchConnector::decodeEndpoint(unsigned int val)
@@ -158,6 +164,8 @@ void WatchConnector::onConnected()
logger()->debug() << "Connected!";
bool was_connected = is_connected;
is_connected = true;
+ reconnectTimer.stop();
+ reconnectTimer.setInterval(0);
if (not was_connected) emit connectedChanged();
}
@@ -175,8 +183,9 @@ void WatchConnector::onDisconnected()
socket->deleteLater();
- // Try to connect again after a timeout
- QTimer::singleShot(__reconnect_timeout, this, SLOT(reconnect()));
+ reconnectTimer.setInterval(reconnectTimer.interval() + __reconnect_timeout);
+ reconnectTimer.start();
+ logger()->debug() << "Will reconnect in " << reconnectTimer.interval() << " ms";
}
void WatchConnector::onError(QBluetoothSocket::SocketError error) {