#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(); }