/*! \file pidiagnostics.h * \brief Connection quality diagnostics */ /* PIP - Platform Independent Primitives Speed and quality in/out diagnostics Copyright (C) 2013 Ivan Pelipenko peri4ko@gmail.com, Bychkov Andrey wapmobil@gmail.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef PIDIAGNOSTICS_H #define PIDIAGNOSTICS_H #include "pitimer.h" class PIP_EXPORT PIDiagnostics: private PITimer { PIOBJECT(PIDiagnostics) public: PIDiagnostics(bool start_ = true); virtual ~PIDiagnostics() {;} enum Quality {Unknown = 1, Failure = 2, Bad = 3, Average = 4, Good = 5}; EVENT_HANDLER0(void, start) {start(1000.);} EVENT_HANDLER1(void, start, double, msecs) {if (msecs > 0.) PITimer::start(msecs);} EVENT_HANDLER0(void, reset); EVENT_HANDLER1(void, received, int, size) {received(size, true);} EVENT_HANDLER2(void, received, int, size, bool, correct); EVENT_HANDLER1(void, sended, int, size); float immediateFrequency() const {return immediate_freq;} float integralFrequency() const {return integral_freq;} ullong receiveCountPerSec() const {return packets_in_sec;} ullong sendCountPerSec() const {return packets_out_sec;} ullong receiveBytesPerSec() const {return bytes_in_sec;} ullong sendBytesPerSec() const {return bytes_out_sec;} ullong receiveCount() const {return receive_count;} ullong wrongCount() const {return wrong_count;} ullong sendCount() const {return send_count;} PIDiagnostics::Quality quality() const {return qual;} PIString receiveSpeed() const {return speedIn;} PIString sendSpeed() const {return speedOut;} const float * immediateFrequency_ptr() const {return &immediate_freq;} const float * integralFrequency_ptr() const {return &integral_freq;} const ullong * receiveCountPerSec_ptr() const {return &packets_in_sec;} const ullong * sendCountPerSec_ptr() const {return &packets_out_sec;} const ullong * receiveBytesPerSec_ptr() const {return &bytes_in_sec;} const ullong * sendBytesPerSec_ptr() const {return &bytes_out_sec;} const ullong * receiveCount_ptr() const {return &receive_count;} const ullong * wrongCount_ptr() const {return &wrong_count;} const ullong * sendCount_ptr() const {return &send_count;} const int * quality_ptr() const {return (int * )&qual;} const PIString * receiveSpeed_ptr() const {return &speedIn;} const PIString * sendSpeed_ptr() const {return &speedOut;} EVENT2(qualityChanged, PIDiagnostics::Quality, new_quality, PIDiagnostics::Quality, old_quality) private: void tick(void * data, int delimiter); void changeDisconnectTimeout(); PIDiagnostics::Quality qual; PIString speedIn, speedOut; float ifreq, immediate_freq, integral_freq; int packets[2]; char cur_pckt, rec_once; ullong wrong_count, receive_count, send_count; ullong packets_in_sec, packets_out_sec, bytes_in_sec, bytes_out_sec; }; #endif // PIDIAGNOSTICS_H