git-svn-id: svn://db.shs.com.ru/pip@755 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2019-02-15 14:45:34 +00:00
parent e1d1853235
commit 0af7eabf56
10 changed files with 140 additions and 63 deletions

View File

@@ -60,40 +60,56 @@ PIDiagnostics::State::State() {
PIDiagnostics::PIDiagnostics(bool start_): PITimer(/*PITimer::Pool*/) {
disconn_ = 0.;
setInterval(100);
piCout << "PIDiagnostics construct";
setInterval(500);
reset();
setDisconnectTimeout(3.);
changeDisconnectTimeout(3.);
if (start_) start(100);
if (start_) PITimer::start(500);
piCout << "PIDiagnostics construct done";
}
PIDiagnostics::~PIDiagnostics() {
piCout << "~PIDiagnostics start...";
PITimer::stop();
piCout << "~PIDiagnostics done!";
}
PIDiagnostics::State PIDiagnostics::state() const {
constLock();
mutex_state.lock();
State ret = cur_state;
constUnlock();
mutex_state.unlock();
return ret;
}
PIDiagnostics::Quality PIDiagnostics::quality() const {
PIDiagnostics::Quality ret;
mutex_state.lock();
ret = cur_state.quality;
mutex_state.unlock();
return ret;
}
PIString PIDiagnostics::receiveSpeed() const {
constLock();
mutex_state.lock();
PIString ret = cur_state.receive_speed;
constUnlock();
mutex_state.unlock();
return ret;
}
PIString PIDiagnostics::sendSpeed() const {
constLock();
mutex_state.lock();
PIString ret = cur_state.send_speed;
constUnlock();
mutex_state.unlock();
return ret;
}
void PIDiagnostics::reset() {
lock();
mutex_state.lock();
cur_state = State();
if (disconn_ != 0.) {
int hist_size = history_rec.size();
@@ -102,12 +118,12 @@ void PIDiagnostics::reset() {
history_rec.resize(hist_size);
history_send.resize(hist_size);
}
unlock();
mutex_state.unlock();
}
void PIDiagnostics::received(int size, bool correct) {
lock();
mutex_state.lock();
Entry & e(history_rec.front());
if (correct) {
e.cnt_ok++;
@@ -121,24 +137,25 @@ void PIDiagnostics::received(int size, bool correct) {
cur_state.received_bytes_wrong += size;
}
e.empty = false;
unlock();
mutex_state.unlock();
}
void PIDiagnostics::sended(int size) {
lock();
mutex_state.lock();
Entry & e(history_send.front());
e.cnt_ok++;
e.bytes_ok += size;
cur_state.sended_packets++;
cur_state.sended_bytes += size;
e.empty = false;
unlock();
mutex_state.unlock();
}
void PIDiagnostics::tick(void * , int ) {
lock();
mutex_state.lock();
//piCoutObj << "lock";
int tcnt_recv = 0;
int tcnt_send = 0;
Entry send = calcHistory(history_send, tcnt_send);
@@ -161,7 +178,7 @@ void PIDiagnostics::tick(void * , int ) {
cur_state.sended_packets_per_sec = ullong(float(send.cnt_ok) / its);
cur_state.sended_bytes_per_sec = ullong(double(send.bytes_ok) / its);
}
// piCoutObj << "tick" << recv.cnt_ok << send.cnt_ok;
//piCoutObj << "tick" << recv.cnt_ok << send.cnt_ok;
// speedRecv = PIString::readableSize(ullong(double(history_rec.front().bytes_ok) / hz)) + "/s";
// speedSend = PIString::readableSize(ullong(double(history_send.front().bytes_ok) / hz)) + "/s";
cur_state.receive_speed = PIString::readableSize(cur_state.received_bytes_per_sec) + "/s";
@@ -192,7 +209,8 @@ void PIDiagnostics::tick(void * , int ) {
qualityChanged(diag, cur_state.quality);
cur_state.quality = diag;
}
unlock();
mutex_state.unlock();
//piCoutObj << "unlock";
}
@@ -219,7 +237,8 @@ void PIDiagnostics::propertyChanged(const PIString &) {
void PIDiagnostics::changeDisconnectTimeout(float disct) {
lock();
//PITimer::stop();
mutex_state.lock();
disconn_ = piMaxf(disct, interval() / 1000.f);
if (interval() > 0) {
int hist_size = piClampi(int(disconn_ * 1000.f / float(interval())), 1, 65536);
@@ -231,15 +250,16 @@ void PIDiagnostics::changeDisconnectTimeout(float disct) {
history_send.resize(1);
}
//piCoutObj << hist_size << disconn_ << interval();
unlock();
mutex_state.unlock();
//PITimer::start();
}
void PIDiagnostics::constLock() const {
const_cast<PIDiagnostics*>(this)->lock();
}
//void PIDiagnostics::constLock() const {
// const_cast<PIDiagnostics*>(this)->lock();
//}
void PIDiagnostics::constUnlock() const {
const_cast<PIDiagnostics*>(this)->unlock();
}
//void PIDiagnostics::constUnlock() const {
// const_cast<PIDiagnostics*>(this)->unlock();
//}