rvm 1.08

reporter.h

Go to the documentation of this file.
00001 #ifndef __reporter_h__
00002 #define __reporter_h__
00003 
00004 #include <string>
00005 #include <vector>
00006 
00007 #include "asserts.h"
00008 #include "types.h"
00009 #include "timer.h"
00010 #include "table.h"
00011 
00012 /** Vault stats report */
00013 class vault_stats_report
00014 {
00015 public:
00016         vault_stats_report();
00017         vault_stats_report(const vault_stats_report& a_class);
00018         vault_stats_report(
00019                 const std::string& a_message,
00020                 const filesystem& a_class
00021                 );
00022         ~vault_stats_report();
00023 
00024         void clear(void);
00025 
00026         void assign(
00027                 const vault_stats_report& a_class
00028                 );
00029         void assign(
00030                 const std::string& a_message,
00031                 const filesystem& a_class
00032                 );
00033         void assign(
00034                 const std::string& a_message,
00035                 const uint64 a_total_blocks,
00036                 const uint64 a_free_blocks,
00037                 const uint64 a_total_inodes,
00038                 const uint64 a_free_inodes
00039                 );
00040         void assign(
00041                 const std::string& a_message,
00042                 const std::string& a_time,
00043                 const uint64 a_total_blocks,
00044                 const uint64 a_free_blocks,
00045                 const uint64 a_total_inodes,
00046                 const uint64 a_free_inodes
00047                 );
00048 
00049         const std::string& time(void) const;
00050         const std::string& message(void) const;
00051         const uint64 total_blocks(void) const;
00052         const uint64 free_blocks(void) const;
00053         const uint64 total_inodes(void) const;
00054         const uint64 free_inodes(void) const;
00055 
00056         vault_stats_report& operator=(const vault_stats_report& a_class);
00057 
00058 private:
00059         std::string m_time;
00060         std::string m_message;
00061         uint64 m_total_blocks;
00062         uint64 m_free_blocks;
00063         uint64 m_total_inodes;
00064         uint64 m_free_inodes;
00065 };
00066 
00067 /** Vault selection and usage report */
00068 class vault_report
00069 {
00070 public:
00071         vault_report();
00072         ~vault_report();
00073 
00074         void clear(void);
00075 
00076         void add_report(const vault_stats_report& a_class);
00077         
00078         void write_report(std::ostream& a_out);
00079 
00080         void format_synopsis(table& a_table);
00081 private:
00082         std::vector<vault_stats_report> m_reports;
00083 };
00084 
00085 /** Job report for an rsync run on a single path */
00086 class job_path_report
00087 {
00088 public:
00089         job_path_report();
00090         job_path_report(const job_path_report& a_class);
00091         job_path_report(
00092                 const std::string a_source,
00093                 const timer a_time,
00094                 const uint16 a_exit_code,
00095                 const uint16 a_signal_num,
00096                 const rsync_behavior::value_type a_behavior,
00097                 const std::string a_error_message
00098                 );
00099         ~job_path_report();
00100 
00101         void clear(void);
00102 
00103         void assign(const job_path_report& a_class);
00104         void assign(
00105                 const std::string a_source,
00106                 const timer a_time,
00107                 const uint16 a_exit_code,
00108                 const uint16 a_signal_num,
00109                 const rsync_behavior::value_type a_behavior,
00110                 const std::string a_error_message
00111                 );
00112         
00113         const bool status(void) const;
00114         void source(const std::string& a_class);
00115         const std::string& source(void) const;
00116         void time(const timer& a_class);
00117         const timer& time(void) const;
00118         void exit_code(const int a_exit_code);
00119         const int exit_code(void) const;
00120         void signal_num(const int a_signal_num);
00121         const int signal_num(void) const;
00122         const rsync_behavior::value_type behavior(void) const;
00123         void error_msg(const std::string& a_class);
00124         const std::string& error_msg(void) const;
00125 
00126         job_path_report& operator=(const job_path_report& a_class);
00127 
00128 private:
00129         std::string m_source;
00130         timer m_time;
00131         int m_exit_code;
00132         int m_signal_num;
00133         std::string m_error_msg;
00134         rsync_behavior::value_type m_behavior;
00135 };
00136 
00137 /** Submit or parse a job path report */
00138 class reportio
00139 {
00140 public:
00141         enum source_type {
00142                 rsync,
00143                 report
00144         };
00145         static const char *tags[];
00146 
00147         void write_rsync_out(const std::string& a_str);
00148         void write_rsync_err(const std::string& a_str);
00149         void write_report(
00150                 const std::string a_source,
00151                 const timer& a_timer,
00152                 const int a_exit_code,
00153                 const int a_signal_num,
00154                 const rsync_behavior::value_type& a_behavior,
00155                 const std::string& a_error_msg
00156                 );
00157 
00158         job_path_report parse(const std::string& a_str);
00159 
00160         bool is_report(const std::string& a_str);
00161 };
00162 
00163 /** A single job report */
00164 class single_job_report
00165 {
00166 public:
00167         single_job_report();
00168         ~single_job_report();
00169 
00170         void clear(void);
00171 
00172         void add_report(const job_path_report& a_class);
00173         const std::vector<job_path_report>& reports(void) const;
00174 
00175         void id(const std::string& a_str);
00176         const std::string& id(void) const;
00177 
00178         const bool status(void) const;
00179 
00180 private:
00181         std::vector<job_path_report> m_reports;
00182         std::string m_id;
00183 };
00184 
00185 /** All job reports */
00186 class jobs_report
00187 {
00188 public:
00189         jobs_report();
00190         ~jobs_report();
00191 
00192         void clear(void);
00193 
00194         void add_report(const single_job_report& a_class);
00195         const std::vector<single_job_report>& reports(void) const;
00196 
00197         void write_report(std::ostream& a_out);
00198 
00199         void format_synopsis(table& a_table);
00200 
00201 private:
00202         std::vector<single_job_report> m_jobs;
00203 };
00204 
00205 /** The report manager
00206 
00207         Process reports coming in both from the parent and from children, then
00208         format and print a finalized report.
00209  */
00210 class report_manager
00211 {
00212 public:
00213         report_manager();
00214         ~report_manager();
00215 
00216         void init(void);
00217         const bool initialized(void) const;
00218         void clear(void);
00219 
00220         void set_total_time(const timer& a_class);
00221 
00222         vault_report& vault(void);
00223         jobs_report& jobs(void);
00224 
00225         void print_report(void);
00226         void file_report(void);
00227         void write_report(std::ostream& a_out);
00228 
00229         void format_synopsis(table& a_table);
00230 
00231 private:
00232         bool m_initialized;
00233         timer m_total_time;
00234         vault_report m_vault;
00235         jobs_report m_jobs;
00236 
00237         void mf_write_header(std::ostream& a_out);
00238         void mf_write_synopsis(std::ostream& a_out);
00239 };
00240 
00241 extern report_manager reporter;
00242 
00243 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines