Back to index

nordugrid-arc-nox  1.1.0~rc6
DataSpeed.h
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifndef __ARC_DATASPEED_H__
00004 #define __ARC_DATASPEED_H__
00005 
00006 #include <string>
00007 
00008 #include <arc/Logger.h>
00009 
00010 #define DATASPEED_AVERAGING_PERIOD 60
00011 
00012 namespace Arc {
00013 
00015 
00016   class DataSpeed {
00017   private:
00018     time_t first_time;
00019     time_t last_time;
00020     time_t last_activity_time;
00021     unsigned long long int N;
00022     unsigned long long int Nall;
00023     unsigned long long int Nmax;
00024     time_t first_speed_failure;
00025     time_t last_printed;
00026 
00027     time_t T;
00028     time_t min_speed_time;
00029     time_t max_inactivity_time;
00030     unsigned long long int min_speed;
00031     unsigned long long int min_average_speed;
00032     bool be_verbose;
00033     std::string verbose_prefix;
00034 
00035     bool min_speed_failed;
00036     bool min_average_speed_failed;
00037     bool max_inactivity_time_failed;
00038 
00039     bool disabled;
00040     static Logger logger;
00041 
00042   public:
00043     typedef void (*show_progress_t)(FILE *o, const char *s, unsigned int t,
00044                                     unsigned long long int all,
00045                                     unsigned long long int max,
00046                                     double instant, double average);
00047   private:
00048     show_progress_t show_progress;
00049     void print_statistics(FILE *o, time_t t);
00050   public:
00053     DataSpeed(time_t base = DATASPEED_AVERAGING_PERIOD);
00064     DataSpeed(unsigned long long int min_speed, time_t min_speed_time,
00065               unsigned long long int min_average_speed,
00066               time_t max_inactivity_time,
00067               time_t base = DATASPEED_AVERAGING_PERIOD);
00069     ~DataSpeed(void);
00072     void verbose(bool val);
00075     void verbose(const std::string& prefix);
00077     bool verbose(void);
00083     void set_min_speed(unsigned long long int min_speed,
00084                        time_t min_speed_time);
00088     void set_min_average_speed(unsigned long long int min_average_speed);
00092     void set_max_inactivity_time(time_t max_inactivity_time);
00094     time_t get_max_inactivity_time() { return max_inactivity_time; };
00097     void set_base(time_t base_ = DATASPEED_AVERAGING_PERIOD);
00100     void set_max_data(unsigned long long int max = 0);
00104     void set_progress_indicator(show_progress_t func = NULL);
00106     void reset(void);
00111     bool transfer(unsigned long long int n = 0);
00114     void hold(bool disable);
00116     bool min_speed_failure() {
00117       return min_speed_failed;
00118     }
00120     bool min_average_speed_failure() {
00121       return min_average_speed_failed;
00122     }
00124     bool max_inactivity_time_failure() {
00125       return max_inactivity_time_failed;
00126     }
00128     unsigned long long int transfered_size(void) {
00129       return Nall;
00130     }
00131   };
00132 
00133 } // namespace Arc
00134 
00135 #endif // __ARC_DATASPEED_H__