|
Disk ARchive
2.4.12
|
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 00025 00026 #ifndef STATISTICS_HPP 00027 #define STATISTICS_HPP 00028 00029 #include "../my_config.h" 00030 00031 #include "infinint.hpp" 00032 #include "user_interaction.hpp" 00033 00034 extern "C" 00035 { 00036 #if MUTEX_WORKS 00037 #if HAVE_PTHREAD_H 00038 #include <pthread.h> 00039 #endif 00040 #endif 00041 } 00042 00045 00046 #if MUTEX_WORKS 00047 #define LOCK_IN pthread_mutex_lock(&lock_mutex) 00048 #define LOCK_OUT pthread_mutex_unlock(&lock_mutex) 00049 #define LOCK_IN_CONST pthread_mutex_lock(const_cast<pthread_mutex_t *>(&lock_mutex)) 00050 #define LOCK_OUT_CONST pthread_mutex_unlock(const_cast<pthread_mutex_t *>(&lock_mutex)) 00051 #else 00052 #define LOCK_IN // 00053 #define LOCK_OUT // 00054 #define LOCK_IN_CONST // 00055 #define LOCK_OUT_CONST // 00056 #endif 00057 00058 namespace libdar 00059 { 00060 00062 00066 // are their meaning see the archive class constructor and methods documentation 00068 class statistics 00069 { 00070 public: 00072 00078 statistics(bool lock = true) { init(lock); clear(); }; 00079 statistics(const statistics & ref) { copy_from(ref); }; 00080 const statistics & operator = (const statistics & ref) { detruit(); copy_from(ref); return *this; }; 00081 00083 ~statistics() { detruit(); }; 00084 00086 void clear(); 00087 00089 infinint total() const; 00090 00091 void incr_treated() { (this->*increment)(&treated); }; 00092 void incr_hard_links() { (this->*increment)(&hard_links); }; 00093 void incr_skipped() { (this->*increment)(&skipped); }; 00094 void incr_ignored() { (this->*increment)(&ignored); }; 00095 void incr_tooold() { (this->*increment)(&tooold); }; 00096 void incr_errored() { (this->*increment)(&errored); }; 00097 void incr_deleted() { (this->*increment)(&deleted); }; 00098 void incr_ea_treated() { (this->*increment)(&ea_treated); }; 00099 00100 void add_to_ignored(const infinint & val) { (this->*add_to)(&ignored, val); }; 00101 void add_to_errored(const infinint & val) { (this->*add_to)(&errored, val); }; 00102 void add_to_deleted(const infinint & val) { (this->*add_to)(&deleted, val); }; 00103 void add_to_byte_amount(const infinint & val) { (this->*add_to)(&byte_amount, val); }; 00104 00105 void sub_from_treated(const infinint & val) { (this->*sub_from)(&treated, val); }; 00106 void sub_from_ea_treated(const infinint & val) { (this->*sub_from)(&ea_treated, val); }; 00107 void sub_from_hard_links(const infinint & val) { (this->*sub_from)(&hard_links, val); }; 00108 00109 infinint get_treated() const { return (this->*returned)(&treated); }; 00110 infinint get_hard_links() const { return (this->*returned)(&hard_links); }; 00111 infinint get_skipped() const { return (this->*returned)(&skipped); }; 00112 infinint get_ignored() const { return (this->*returned)(&ignored); }; 00113 infinint get_tooold() const { return (this->*returned)(&tooold); }; 00114 infinint get_errored() const { return (this->*returned)(&errored); }; 00115 infinint get_deleted() const { return (this->*returned)(&deleted); }; 00116 infinint get_ea_treated() const { return (this->*returned)(&ea_treated); }; 00117 infinint get_byte_amount() const { return (this->*returned)(&byte_amount); }; 00118 00119 void decr_treated() { (this->*decrement)(&treated); }; 00120 void decr_hard_links() { (this->*decrement)(&hard_links); }; 00121 void decr_skipped() { (this->*decrement)(&skipped); }; 00122 void decr_ignored() { (this->*decrement)(&ignored); }; 00123 void decr_tooold() { (this->*decrement)(&tooold); }; 00124 void decr_errored() { (this->*decrement)(&errored); }; 00125 void decr_deleted() { (this->*decrement)(&deleted); }; 00126 void decr_ea_treated() { (this->*decrement)(&ea_treated); }; 00127 00128 void set_byte_amount(const infinint & val) { (this->*set_to)(&byte_amount, val); }; 00129 00130 // debuging method 00131 void dump(user_interaction & dialog) const; 00132 00133 private: 00134 #if MUTEX_WORKS 00135 pthread_mutex_t lock_mutex; 00136 #endif 00137 bool locking; 00138 00139 infinint treated; 00140 infinint hard_links; 00141 infinint skipped; 00142 infinint ignored; 00143 infinint tooold; 00144 infinint errored; 00145 infinint deleted; 00146 infinint ea_treated; 00147 infinint byte_amount; 00148 00149 00150 void (statistics::*increment)(infinint * var); 00151 void (statistics::*add_to)(infinint * var, const infinint & val); 00152 infinint (statistics::*returned)(const infinint * var) const; 00153 void (statistics::*decrement)(infinint * var); 00154 void (statistics::*set_to)(infinint * var, const infinint & val); 00155 void (statistics::*sub_from)(infinint *var, const infinint & val); 00156 00157 void increment_locked(infinint * var) 00158 { 00159 LOCK_IN; 00160 (*var)++; 00161 LOCK_OUT; 00162 }; 00163 00164 void increment_unlocked(infinint * var) 00165 { 00166 (*var)++; 00167 } 00168 00169 void add_to_locked(infinint * var, const infinint & val) 00170 { 00171 LOCK_IN; 00172 (*var) += val; 00173 LOCK_OUT; 00174 } 00175 00176 void add_to_unlocked(infinint *var, const infinint & val) 00177 { 00178 (*var) += val; 00179 } 00180 00181 infinint returned_locked(const infinint * var) const 00182 { 00183 infinint ret; 00184 00185 LOCK_IN_CONST; 00186 ret = *var; 00187 LOCK_OUT_CONST; 00188 00189 return ret; 00190 }; 00191 00192 infinint returned_unlocked(const infinint * var) const 00193 { 00194 return *var; 00195 }; 00196 00197 void decrement_locked(infinint * var) 00198 { 00199 LOCK_IN; 00200 (*var)--; 00201 LOCK_OUT; 00202 } 00203 00204 void decrement_unlocked(infinint * var) 00205 { 00206 (*var)--; 00207 } 00208 00209 void set_to_locked(infinint *var, const infinint & val) 00210 { 00211 LOCK_IN; 00212 (*var) = val; 00213 LOCK_OUT; 00214 } 00215 00216 void set_to_unlocked(infinint *var, const infinint & val) 00217 { 00218 *var = val; 00219 } 00220 00221 void sub_from_unlocked(infinint *var, const infinint & val) 00222 { 00223 *var -= val; 00224 } 00225 00226 void sub_from_locked(infinint *var, const infinint & val) 00227 { 00228 LOCK_IN; 00229 *var -= val; 00230 LOCK_OUT; 00231 } 00232 00233 00234 void init(bool lock); // set locking & mutex 00235 void detruit(); // release and free the mutex 00236 void copy_from(const statistics & ref); // reset mutex and copy data from the object of reference 00237 00238 }; 00239 00240 } // end of namespace 00241 00243 00244 #endif
1.7.6.1