git-svn-id: svn://db.shs.com.ru/pip@755 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -26,11 +26,14 @@ PIBaseTransfer::PIBaseTransfer(): crc(standardCRC_16()), diag(false) {
|
||||
setPacketSize(4096);
|
||||
#endif
|
||||
randomize();
|
||||
piCout << "PIBaseTransfer" << &diag;
|
||||
}
|
||||
|
||||
|
||||
PIBaseTransfer::~PIBaseTransfer() {
|
||||
piCout << "~PIBaseTransfer" << &diag;
|
||||
diag.stop();
|
||||
piCout << "~PIBaseTransfer done";
|
||||
break_ = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
//}
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
//! Constructs an empty diagnostics and if "start_" start it
|
||||
PIDiagnostics(bool start_ = true);
|
||||
|
||||
virtual ~PIDiagnostics() {;}
|
||||
virtual ~PIDiagnostics();
|
||||
|
||||
//! Connection quality
|
||||
enum Quality {
|
||||
@@ -77,6 +77,7 @@ public:
|
||||
//! Returns period of full disconnect in seconds and period of averaging frequency
|
||||
void setDisconnectTimeout(float s) {setProperty("disconnectTimeout", s);}
|
||||
|
||||
/*
|
||||
//! Returns immediate receive frequency, packets/s
|
||||
float immediateFrequency() const {return cur_state.immediate_freq;}
|
||||
|
||||
@@ -112,9 +113,10 @@ public:
|
||||
|
||||
//! Returns overall sended packets count
|
||||
ullong sendCount() const {return cur_state.sended_packets;}
|
||||
*/
|
||||
|
||||
//! Returns connection quality
|
||||
PIDiagnostics::Quality quality() const {return cur_state.quality;}
|
||||
PIDiagnostics::Quality quality() const;
|
||||
|
||||
//! Returns receive speed in format "n {B|kB|MB|GB|TB}/s"
|
||||
PIString receiveSpeed() const;
|
||||
@@ -122,7 +124,7 @@ public:
|
||||
//! Returns send speed in format "n {B|kB|MB|GB|TB}/s"
|
||||
PIString sendSpeed() const;
|
||||
|
||||
|
||||
/* DEPRECATED
|
||||
//! Returns immediate receive frequency pointer, packets/s. Useful for output to PIConsole
|
||||
const float * immediateFrequency_ptr() const {return &cur_state.immediate_freq;}
|
||||
|
||||
@@ -166,9 +168,9 @@ public:
|
||||
const PIString * receiveSpeed_ptr() const {return &cur_state.receive_speed;}
|
||||
|
||||
//! Returns send speed pointer in format "n {B|kB|MB|GB|TB}/s". Useful for output to PIConsole
|
||||
const PIString * sendSpeed_ptr() const {return &cur_state.send_speed;}
|
||||
const PIString * sendSpeed_ptr() const {return &cur_state.send_speed;}*/
|
||||
|
||||
EVENT_HANDLER0(void, start) {start(100.); changeDisconnectTimeout(disconn_);}
|
||||
EVENT_HANDLER0(void, start) {PITimer::start(100.); changeDisconnectTimeout(disconn_);}
|
||||
EVENT_HANDLER1(void, start, double, msecs) {if (msecs > 0.) {PITimer::start(msecs); changeDisconnectTimeout(disconn_);}}
|
||||
EVENT_HANDLER0(void, stop) {PITimer::stop();}
|
||||
EVENT_HANDLER0(void, reset);
|
||||
@@ -220,12 +222,13 @@ private:
|
||||
Entry calcHistory(PIQueue<Entry> & hist, int & cnt);
|
||||
void propertyChanged(const PIString &);
|
||||
void changeDisconnectTimeout(float disct);
|
||||
void constLock() const;
|
||||
void constUnlock() const;
|
||||
// void constLock() const;
|
||||
// void constUnlock() const;
|
||||
|
||||
PIQueue<Entry> history_rec, history_send;
|
||||
float disconn_;
|
||||
State cur_state;
|
||||
mutable PIMutex mutex_state;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user