Disk ARchive
2.4.5
|
00001 //*********************************************************************/ 00002 // dar - disk archive - a backup/restoration program 00003 // Copyright (C) 2002-2052 Denis Corbin 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // to contact the author : http://dar.linux.free.fr/email.html 00020 /*********************************************************************/ 00021 // $Id$ 00022 // 00023 /*********************************************************************/ 00024 // 00025 00029 00030 #ifndef STATISTICS_HPP 00031 #define STATISTICS_HPP 00032 00033 #include "../my_config.h" 00034 00035 #include "infinint.hpp" 00036 #include "user_interaction.hpp" 00037 00038 extern "C" 00039 { 00040 #if MUTEX_WORKS 00041 #if HAVE_PTHREAD_H 00042 #include <pthread.h> 00043 #endif 00044 #endif 00045 } 00046 00049 00050 #if MUTEX_WORKS 00051 #define LOCK_IN pthread_mutex_lock(&lock_mutex) 00052 #define LOCK_OUT pthread_mutex_unlock(&lock_mutex) 00053 #define LOCK_IN_CONST pthread_mutex_lock(const_cast<pthread_mutex_t *>(&lock_mutex)) 00054 #define LOCK_OUT_CONST pthread_mutex_unlock(const_cast<pthread_mutex_t *>(&lock_mutex)) 00055 #else 00056 #define LOCK_IN // 00057 #define LOCK_OUT // 00058 #define LOCK_IN_CONST // 00059 #define LOCK_OUT_CONST // 00060 #endif 00061 00062 namespace libdar 00063 { 00064 00066 00070 // are their meaning see the archive class constructor and methods documentation 00072 class statistics 00073 { 00074 public: 00076 00082 statistics(bool lock = true) { init(lock); clear(); }; 00083 statistics(const statistics & ref) { copy_from(ref); }; 00084 const statistics & operator = (const statistics & ref) { detruit(); copy_from(ref); return *this; }; 00085 00087 ~statistics() { detruit(); }; 00088 00090 void clear(); 00091 00093 infinint total() const; 00094 00095 void incr_treated() { (this->*increment)(&treated); }; 00096 void incr_hard_links() { (this->*increment)(&hard_links); }; 00097 void incr_skipped() { (this->*increment)(&skipped); }; 00098 void incr_ignored() { (this->*increment)(&ignored); }; 00099 void incr_tooold() { (this->*increment)(&tooold); }; 00100 void incr_errored() { (this->*increment)(&errored); }; 00101 void incr_deleted() { (this->*increment)(&deleted); }; 00102 void incr_ea_treated() { (this->*increment)(&ea_treated); }; 00103 00104 void add_to_ignored(const infinint & val) { (this->*add_to)(&ignored, val); }; 00105 void add_to_errored(const infinint & val) { (this->*add_to)(&errored, val); }; 00106 void add_to_deleted(const infinint & val) { (this->*add_to)(&deleted, val); }; 00107 void add_to_byte_amount(const infinint & val) { (this->*add_to)(&byte_amount, val); }; 00108 00109 void sub_from_treated(const infinint & val) { (this->*sub_from)(&treated, val); }; 00110 void sub_from_ea_treated(const infinint & val) { (this->*sub_from)(&ea_treated, val); }; 00111 void sub_from_hard_links(const infinint & val) { (this->*sub_from)(&hard_links, val); }; 00112 00113 infinint get_treated() const { return (this->*returned)(&treated); }; 00114 infinint get_hard_links() const { return (this->*returned)(&hard_links); }; 00115 infinint get_skipped() const { return (this->*returned)(&skipped); }; 00116 infinint get_ignored() const { return (this->*returned)(&ignored); }; 00117 infinint get_tooold() const { return (this->*returned)(&tooold); }; 00118 infinint get_errored() const { return (this->*returned)(&errored); }; 00119 infinint get_deleted() const { return (this->*returned)(&deleted); }; 00120 infinint get_ea_treated() const { return (this->*returned)(&ea_treated); }; 00121 infinint get_byte_amount() const { return (this->*returned)(&byte_amount); }; 00122 00123 void decr_treated() { (this->*decrement)(&treated); }; 00124 void decr_hard_links() { (this->*decrement)(&hard_links); }; 00125 void decr_skipped() { (this->*decrement)(&skipped); }; 00126 void decr_ignored() { (this->*decrement)(&ignored); }; 00127 void decr_tooold() { (this->*decrement)(&tooold); }; 00128 void decr_errored() { (this->*decrement)(&errored); }; 00129 void decr_deleted() { (this->*decrement)(&deleted); }; 00130 void decr_ea_treated() { (this->*decrement)(&ea_treated); }; 00131 00132 void set_byte_amount(const infinint & val) { (this->*set_to)(&byte_amount, val); }; 00133 00134 // debuging method 00135 void dump(user_interaction & dialog) const; 00136 00137 private: 00138 #if MUTEX_WORKS 00139 pthread_mutex_t lock_mutex; 00140 #endif 00141 bool locking; 00142 00143 infinint treated; 00144 infinint hard_links; 00145 infinint skipped; 00146 infinint ignored; 00147 infinint tooold; 00148 infinint errored; 00149 infinint deleted; 00150 infinint ea_treated; 00151 infinint byte_amount; 00152 00153 00154 void (statistics::*increment)(infinint * var); 00155 void (statistics::*add_to)(infinint * var, const infinint & val); 00156 infinint (statistics::*returned)(const infinint * var) const; 00157 void (statistics::*decrement)(infinint * var); 00158 void (statistics::*set_to)(infinint * var, const infinint & val); 00159 void (statistics::*sub_from)(infinint *var, const infinint & val); 00160 00161 void increment_locked(infinint * var) 00162 { 00163 LOCK_IN; 00164 (*var)++; 00165 LOCK_OUT; 00166 }; 00167 00168 void increment_unlocked(infinint * var) 00169 { 00170 (*var)++; 00171 } 00172 00173 void add_to_locked(infinint * var, const infinint & val) 00174 { 00175 LOCK_IN; 00176 (*var) += val; 00177 LOCK_OUT; 00178 } 00179 00180 void add_to_unlocked(infinint *var, const infinint & val) 00181 { 00182 (*var) += val; 00183 } 00184 00185 infinint returned_locked(const infinint * var) const 00186 { 00187 infinint ret; 00188 00189 LOCK_IN_CONST; 00190 ret = *var; 00191 LOCK_OUT_CONST; 00192 00193 return ret; 00194 }; 00195 00196 infinint returned_unlocked(const infinint * var) const 00197 { 00198 return *var; 00199 }; 00200 00201 void decrement_locked(infinint * var) 00202 { 00203 LOCK_IN; 00204 (*var)--; 00205 LOCK_OUT; 00206 } 00207 00208 void decrement_unlocked(infinint * var) 00209 { 00210 (*var)--; 00211 } 00212 00213 void set_to_locked(infinint *var, const infinint & val) 00214 { 00215 LOCK_IN; 00216 (*var) = val; 00217 LOCK_OUT; 00218 } 00219 00220 void set_to_unlocked(infinint *var, const infinint & val) 00221 { 00222 *var = val; 00223 } 00224 00225 void sub_from_unlocked(infinint *var, const infinint & val) 00226 { 00227 *var -= val; 00228 } 00229 00230 void sub_from_locked(infinint *var, const infinint & val) 00231 { 00232 LOCK_IN; 00233 *var -= val; 00234 LOCK_OUT; 00235 } 00236 00237 00238 void init(bool lock); // set locking & mutex 00239 void detruit(); // release and free the mutex 00240 void copy_from(const statistics & ref); // reset mutex and copy data from the object of reference 00241 00242 }; 00243 00244 } // end of namespace 00245 00247 00248 #endif