From ed40a7f1cbc1da5ae21c58882df241fc0071c2f7 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sat, 6 Sep 2014 03:25:38 +0200 Subject: adding initial UI to select device --- src/reconnecttimer.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/reconnecttimer.cpp') diff --git a/src/reconnecttimer.cpp b/src/reconnecttimer.cpp index eaf6cbb..a58a13e 100644 --- a/src/reconnecttimer.cpp +++ b/src/reconnecttimer.cpp @@ -15,33 +15,33 @@ ReconnectTimer::ReconnectTimer(QObject *parent) : QObject(parent), _iphb(iphb_open(0)), _notifier(new QSocketNotifier(iphb_get_fd(_iphb), QSocketNotifier::Read, this)), - _active(false) + _active(false), + _counter(0) { connect(_notifier, &QSocketNotifier::activated, this, &ReconnectTimer::handleIphbActivity); } ReconnectTimer::~ReconnectTimer() { - iphb_close(_iphb); + _active = false; + _iphb = iphb_close(_iphb); } -void ReconnectTimer::start() +void ReconnectTimer::scheduleNextAttempt() { _active = true; - _counter = 0; - setupWait(); + + time_t res = iphb_wait2(_iphb, wait_times[_counter] / 2, wait_times[_counter], 0, 0); + + if (res == -1) { + qErrnoWarning("Failed to iphb_wait"); + } } void ReconnectTimer::stop() { _active = false; _counter = 0; - iphb_wait(_iphb, 0, 0, 0); -} - -void ReconnectTimer::setupWait() -{ - iphb_wait(_iphb, wait_times[_counter] / 2, wait_times[_counter], 0); } void ReconnectTimer::handleIphbActivity() @@ -55,10 +55,9 @@ void ReconnectTimer::handleIphbActivity() return; } - emit tick(); - + _active = false; if (++_counter > num_wait_times) _counter = num_wait_times; - setupWait(); + emit tryReconnect(); } -- cgit v1.2.3