Skip to content

Commit

Permalink
Issue #14
Browse files Browse the repository at this point in the history
  • Loading branch information
alexis031182 committed Mar 17, 2014
1 parent e97e202 commit 442bbc2
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 5 deletions.
17 changes: 15 additions & 2 deletions abackuppoolhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
// Конструктор.
// ========================================================================== //
ABackupPoolHandler::ABackupPoolHandler(QObject *parent)
: QObject(parent), _timer(new QTimer(this)), _pool_index(0) {
: QObject(parent), _timer(new QTimer(this)), _pool_index(0)
, _checking_timeout(5) {

_timer->setSingleShot(false);
connect(_timer, SIGNAL(timeout()), this, SLOT(onTimerTimeout()));
Expand Down Expand Up @@ -50,7 +51,7 @@ void ABackupPoolHandler::nextPool() {++_pool_index; onTimerTimeout();}
// Слот активации таймера.
// ========================================================================== //
void ABackupPoolHandler::onTimerTimeout() {
int checking_interval = 5;
int checking_interval = 5, checking_timeout = 5;

QSettings settings(_fname, QSettings::IniFormat);

Expand All @@ -69,6 +70,18 @@ void ABackupPoolHandler::onTimerTimeout() {
emit checkingIntervalChanged(checking_interval);
}

if(settings.contains("checking-timeout")) {
const int interval = settings.value("checking-timeout").toInt();
if(interval > 0) checking_timeout = interval;
else settings.remove("checking-timeout");

} else settings.setValue("checking-timeout", checking_timeout);

if(_checking_timeout != checking_timeout) {
_checking_timeout = checking_timeout;
emit checkingIntervalChanged(checking_timeout);
}

const int pools = settings.beginReadArray("Pools");
if(_pool_index > 0 && _pool_index >= pools) {
_pool.clear(); _pool_index = 0;
Expand Down
3 changes: 2 additions & 1 deletion abackuppoolhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ABackupPoolHandler : public QObject {
void poolChanged(const QString &pool);

void checkingIntervalChanged(int interval);
void checkingTimeoutChanged(int interval);

public:
//! Конструктор.
Expand Down Expand Up @@ -41,7 +42,7 @@ class ABackupPoolHandler : public QObject {

QString _fname, _pool;

int _pool_index;
int _pool_index, _checking_timeout;

private slots:
//! Слот активации таймера.
Expand Down
18 changes: 16 additions & 2 deletions amainpoolhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Конструктор.
// ========================================================================== //
AMainPoolHandler::AMainPoolHandler(QObject *parent)
: QObject(parent), _timer(new QTimer(this)) {
: QObject(parent), _timer(new QTimer(this)), _checking_timeout(5) {

_timer->setSingleShot(false);
connect(_timer, SIGNAL(timeout()), this, SLOT(onTimerTimeout()));
Expand Down Expand Up @@ -42,7 +42,9 @@ void AMainPoolHandler::stop() {_timer->stop();}
// Слот активации таймера.
// ========================================================================== //
void AMainPoolHandler::onTimerTimeout() {
int checking_interval = 5; QString pool("localhost:3336");
int checking_interval = 5, checking_timeout = 5;

QString pool("localhost:3336");

QSettings settings(_fname, QSettings::IniFormat);

Expand All @@ -61,6 +63,18 @@ void AMainPoolHandler::onTimerTimeout() {
emit checkingIntervalChanged(checking_interval);
}

if(settings.contains("checking-timeout")) {
const int interval = settings.value("checking-timeout").toInt();
if(interval > 0) checking_timeout = interval;
else settings.remove("checking-timeout");

} else settings.setValue("checking-timeout", checking_timeout);

if(_checking_timeout != checking_timeout) {
_checking_timeout = checking_timeout;
emit checkingIntervalChanged(checking_timeout);
}

if(settings.contains("stratum")) {
const QString p = settings.value("stratum").toString();
if(!p.isEmpty()) pool = p; else settings.remove("stratum");
Expand Down
3 changes: 3 additions & 0 deletions amainpoolhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class AMainPoolHandler : public QObject {
void poolChanged(const QString &pool);

void checkingIntervalChanged(int interval);
void checkingTimeoutChanged(int interval);

public:
//! Конструктор.
Expand All @@ -36,6 +37,8 @@ class AMainPoolHandler : public QObject {
private:
QTimer *_timer;

int _checking_timeout;

QString _fname, _pool;

private slots:
Expand Down
8 changes: 8 additions & 0 deletions apoolchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ void APoolChecker::check(const QString &host, int port) {
}


// ========================================================================== //
// Слот установки интервала.
// ========================================================================== //
void APoolChecker::changeCheckingTimeout(int interval) {
_timer->setInterval(interval*1000);
}


// ========================================================================== //
// Слот подключения сокета к хосту.
// ========================================================================== //
Expand Down
3 changes: 3 additions & 0 deletions apoolchecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ class APoolChecker : public QObject {
//! Слот проверки активности пула.
void check(const QString &host, int port);

//! Слот установки интервала.
void changeCheckingTimeout(int interval);

private:
QTcpSocket *_socket;

Expand Down
8 changes: 8 additions & 0 deletions apoolmonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ void APoolMonitor::changeCheckingInterval(int interval) {
}


// ========================================================================== //
// Слот установки интервала.
// ========================================================================== //
void APoolMonitor::changeCheckingTimeout(int interval) {
_pool_checker->changeCheckingTimeout(interval);
}


// ========================================================================== //
// Слот активации мониторинга.
// ========================================================================== //
Expand Down
3 changes: 3 additions & 0 deletions apoolmonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class APoolMonitor : public QObject {
//! Слот установки интервала.
void changeCheckingInterval(int interval);

//! Слот установки интервала.
void changeCheckingTimeout(int interval);

//! Слот активации мониторинга.
void start();

Expand Down
4 changes: 4 additions & 0 deletions aproxymachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ AProxyMachine::AProxyMachine(QObject *parent)
, _main_pool_monitor, SLOT(changePool(const QString&)));
connect(_main_pool_handler, SIGNAL(checkingIntervalChanged(int))
, _main_pool_monitor, SLOT(changeCheckingInterval(int)));
connect(_main_pool_handler, SIGNAL(checkingTimeoutChanged(int))
, _main_pool_monitor, SLOT(changeCheckingTimeout(int)));

connect(_main_pool_monitor, SIGNAL(succeed())
, this, SLOT(onMainPoolSucceed()));
Expand All @@ -52,6 +54,8 @@ AProxyMachine::AProxyMachine(QObject *parent)
, _backup_pool_monitor, SLOT(changePool(const QString&)));
connect(_backup_pool_handler, SIGNAL(checkingIntervalChanged(int))
, _backup_pool_monitor, SLOT(changeCheckingInterval(int)));
connect(_backup_pool_handler, SIGNAL(checkingTimeoutChanged(int))
, _backup_pool_monitor, SLOT(changeCheckingTimeout(int)));

connect(_backup_pool_monitor, SIGNAL(succeed())
, this, SLOT(onBackupPoolSucceed()));
Expand Down

0 comments on commit 442bbc2

Please sign in to comment.