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 std::string a_error_message
00097                 );
00098         ~job_path_report();
00099 
00100         void clear(void);
00101 
00102         void assign(const job_path_report& a_class);
00103         void assign(
00104                 const std::string a_source,
00105                 const timer a_time,
00106                 const uint16 a_exit_code,
00107                 const uint16 a_signal_num,
00108                 const std::string a_error_message
00109                 );
00110         
00111         const bool status(void) const;
00112         void source(const std::string& a_class);
00113         const std::string& source(void) const;
00114         void time(const timer& a_class);
00115         const timer& time(void) const;
00116         void exit_code(const int a_exit_code);
00117         const int exit_code(void) const;
00118         void signal_num(const int a_signal_num);
00119         const int signal_num(void) const;
00120         void error_msg(const std::string& a_class);
00121         const std::string& error_msg(void) const;
00122 
00123         job_path_report& operator=(const job_path_report& a_class);
00124 
00125 private:
00126         std::string m_source;
00127         timer m_time;
00128         int m_exit_code;
00129         int m_signal_num;
00130         std::string m_error_msg;
00131 };
00132 
00133 /** Submit or parse a job path report */
00134 class reportio
00135 {
00136 public:
00137         enum source_type {
00138                 rsync,
00139                 report
00140         };
00141         static const char *tags[];
00142 
00143         void write_rsync_out(const std::string& a_str);
00144         void write_rsync_err(const std::string& a_str);
00145         void write_report(
00146                 const std::string a_source,
00147                 const timer& a_timer,
00148                 const int a_exit_code,
00149                 const int a_signal_num,
00150                 const std::string& a_error_msg
00151                 );
00152 
00153         job_path_report parse(const std::string& a_str);
00154 
00155         bool is_report(const std::string& a_str);
00156 };
00157 
00158 /** A single job report */
00159 class single_job_report
00160 {
00161 public:
00162         single_job_report();
00163         ~single_job_report();
00164 
00165         void clear(void);
00166 
00167         void add_report(const job_path_report& a_class);
00168         const std::vector<job_path_report>& reports(void) const;
00169 
00170         void id(const std::string& a_str);
00171         const std::string& id(void) const;
00172 
00173         const bool status(void) const;
00174 
00175 private:
00176         std::vector<job_path_report> m_reports;
00177         std::string m_id;
00178 };
00179 
00180 /** All job reports */
00181 class jobs_report
00182 {
00183 public:
00184         jobs_report();
00185         ~jobs_report();
00186 
00187         void clear(void);
00188 
00189         void add_report(const single_job_report& a_class);
00190         const std::vector<single_job_report>& reports(void) const;
00191 
00192         void write_report(std::ostream& a_out);
00193 
00194         void format_synopsis(table& a_table);
00195 
00196 private:
00197         std::vector<single_job_report> m_jobs;
00198 };
00199 
00200 /** The report manager
00201 
00202         Process reports coming in both from the parent and from children, then
00203         format and print a finalized report.
00204  */
00205 class report_manager
00206 {
00207 public:
00208         report_manager();
00209         ~report_manager();
00210 
00211         void init(void);
00212         const bool initialized(void) const;
00213         void clear(void);
00214 
00215         void set_total_time(const timer& a_class);
00216 
00217         vault_report& vault(void);
00218         jobs_report& jobs(void);
00219 
00220         void print_report(void);
00221         void file_report(void);
00222         void write_report(std::ostream& a_out);
00223 
00224         void format_synopsis(table& a_table);
00225 
00226 private:
00227         bool m_initialized;
00228         timer m_total_time;
00229         vault_report m_vault;
00230         jobs_report m_jobs;
00231 
00232         void mf_write_header(std::ostream& a_out);
00233         void mf_write_synopsis(std::ostream& a_out);
00234 };
00235 
00236 extern report_manager reporter;
00237 
00238 #endif

Generated on Tue Jul 1 12:09:28 2008 for rvm by  doxygen 1.5.1