From 1adf7f1bcde493ccaacedb0d9778911ad69ff335 Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 4 Sep 2014 01:55:14 +0200 Subject: Initial import --- src/reconnecttimer.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/reconnecttimer.cpp (limited to 'src/reconnecttimer.cpp') diff --git a/src/reconnecttimer.cpp b/src/reconnecttimer.cpp new file mode 100644 index 0000000..eaf6cbb --- /dev/null +++ b/src/reconnecttimer.cpp @@ -0,0 +1,64 @@ +#include + +extern "C" { + #include +} + +#include "reconnecttimer.h" + +static unsigned int num_wait_times = 8; +static unsigned short wait_times[8] = { + 2, 5, 10, 30, 2 * 60, 5 * 60, 10 * 60, 15 * 60 +}; + +ReconnectTimer::ReconnectTimer(QObject *parent) + : QObject(parent), + _iphb(iphb_open(0)), + _notifier(new QSocketNotifier(iphb_get_fd(_iphb), QSocketNotifier::Read, this)), + _active(false) +{ + connect(_notifier, &QSocketNotifier::activated, this, &ReconnectTimer::handleIphbActivity); +} + +ReconnectTimer::~ReconnectTimer() +{ + iphb_close(_iphb); +} + +void ReconnectTimer::start() +{ + _active = true; + _counter = 0; + setupWait(); +} + +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() +{ + iphb_discard_wakeups(_iphb); + + qDebug() << "iphb wakeup"; + + if (!_active) { + // False awakening + return; + } + + emit tick(); + + if (++_counter > num_wait_times) + _counter = num_wait_times; + + setupWait(); +} -- cgit v1.2.3