1 #ifndef __reporter_h__
2 #define __reporter_h__
3 
4 #include <string>
5 #include <vector>
6 
7 #include "asserts.h"
8 #include "types.h"
9 #include "timer.h"
10 #include "table.h"
11 
12 /** Vault stats report */
13 class vault_stats_report
14 {
15 public:
16 	vault_stats_report();
17 	vault_stats_report(const vault_stats_report& a_class);
18 	vault_stats_report(
19 		const std::string& a_message,
20 		const filesystem& a_class
21 		);
22 	~vault_stats_report();
23 
24 	void clear(void);
25 
26 	void assign(
27 		const vault_stats_report& a_class
28 		);
29 	void assign(
30 		const std::string& a_message,
31 		const filesystem& a_class
32 		);
33 	void assign(
34 		const std::string& a_message,
35 		const uint64 a_total_blocks,
36 		const uint64 a_free_blocks,
37 		const uint64 a_total_inodes,
38 		const uint64 a_free_inodes
39 		);
40 	void assign(
41 		const std::string& a_message,
42 		const std::string& a_time,
43 		const uint64 a_total_blocks,
44 		const uint64 a_free_blocks,
45 		const uint64 a_total_inodes,
46 		const uint64 a_free_inodes
47 		);
48 
49 	const std::string& time(void) const;
50 	const std::string& message(void) const;
51 	const uint64 total_blocks(void) const;
52 	const uint64 free_blocks(void) const;
53 	const uint64 total_inodes(void) const;
54 	const uint64 free_inodes(void) const;
55 
56 	vault_stats_report& operator=(const vault_stats_report& a_class);
57 
58 private:
59 	std::string m_time;
60 	std::string m_message;
61 	uint64 m_total_blocks;
62 	uint64 m_free_blocks;
63 	uint64 m_total_inodes;
64 	uint64 m_free_inodes;
65 };
66 
67 /** Vault selection and usage report */
68 class vault_report
69 {
70 public:
71 	vault_report();
72 	~vault_report();
73 
74 	void clear(void);
75 
76 	void add_report(const vault_stats_report& a_class);
77 
78 	void write_report(std::ostream& a_out);
79 
80 	void format_synopsis(table& a_table);
81 private:
82 	std::vector<vault_stats_report> m_reports;
83 };
84 
85 /** Job report for an rsync run on a single path */
86 class job_path_report
87 {
88 public:
89 	job_path_report();
90 	job_path_report(const job_path_report& a_class);
91 	job_path_report(
92 		const std::string a_source,
93 		const timer a_time,
94 		const uint16 a_exit_code,
95 		const uint16 a_signal_num,
96 		const rsync_behavior::value_type a_behavior,
97 		const std::string a_error_message
98 		);
99 	~job_path_report();
100 
101 	void clear(void);
102 
103 	void assign(const job_path_report& a_class);
104 	void assign(
105 		const std::string a_source,
106 		const timer a_time,
107 		const uint16 a_exit_code,
108 		const uint16 a_signal_num,
109 		const rsync_behavior::value_type a_behavior,
110 		const std::string a_error_message
111 		);
112 
113 	const bool status(void) const;
114 	void source(const std::string& a_class);
115 	const std::string& source(void) const;
116 	void time(const timer& a_class);
117 	const timer& time(void) const;
118 	void exit_code(const int a_exit_code);
119 	const int exit_code(void) const;
120 	void signal_num(const int a_signal_num);
121 	const int signal_num(void) const;
122 	const rsync_behavior::value_type behavior(void) const;
123 	void error_msg(const std::string& a_class);
124 	const std::string& error_msg(void) const;
125 
126 	job_path_report& operator=(const job_path_report& a_class);
127 
128 private:
129 	std::string m_source;
130 	timer m_time;
131 	int m_exit_code;
132 	int m_signal_num;
133 	std::string m_error_msg;
134 	rsync_behavior::value_type m_behavior;
135 };
136 
137 /** Submit or parse a job path report */
138 class reportio
139 {
140 public:
141 	enum source_type {
142 		rsync,
143 		report
144 	};
145 	static const char *tags[];
146 
147 	void write_rsync_out(const std::string& a_str);
148 	void write_rsync_err(const std::string& a_str);
149 	void write_report(
150 		const std::string a_source,
151 		const timer& a_timer,
152 		const int a_exit_code,
153 		const int a_signal_num,
154 		const rsync_behavior::value_type& a_behavior,
155 		const std::string& a_error_msg
156 		);
157 
158 	job_path_report parse(const std::string& a_str);
159 
160 	bool is_report(const std::string& a_str);
161 };
162 
163 /** A single job report */
164 class single_job_report
165 {
166 public:
167 	single_job_report();
168 	~single_job_report();
169 
170 	void clear(void);
171 
172 	void add_report(const job_path_report& a_class);
173 	const std::vector<job_path_report>& reports(void) const;
174 
175 	void id(const std::string& a_str);
176 	const std::string& id(void) const;
177 
178 	const bool status(void) const;
179 
180 private:
181 	std::vector<job_path_report> m_reports;
182 	std::string m_id;
183 };
184 
185 /** All job reports */
186 class jobs_report
187 {
188 public:
189 	jobs_report();
190 	~jobs_report();
191 
192 	void clear(void);
193 
194 	void add_report(const single_job_report& a_class);
195 	const std::vector<single_job_report>& reports(void) const;
196 
197 	void write_report(std::ostream& a_out);
198 
199 	void format_synopsis(table& a_table);
200 
201 private:
202 	std::vector<single_job_report> m_jobs;
203 };
204 
205 /** The report manager
206 
207 	Process reports coming in both from the parent and from children, then
208 	format and print a finalized report.
209  */
210 class report_manager
211 {
212 public:
213 	report_manager();
214 	~report_manager();
215 
216 	void init(void);
217 	const bool initialized(void) const;
218 	void clear(void);
219 
220 	void set_total_time(const timer& a_class);
221 
222 	vault_report& vault(void);
223 	jobs_report& jobs(void);
224 
225 	void print_report(void);
226 	void file_report(void);
227 	void write_report(std::ostream& a_out);
228 
229 	void format_synopsis(table& a_table);
230 
231 private:
232 	bool m_initialized;
233 	timer m_total_time;
234 	vault_report m_vault;
235 	jobs_report m_jobs;
236 
237 	void mf_write_header(std::ostream& a_out);
238 	void mf_write_synopsis(std::ostream& a_out);
239 };
240 
241 extern report_manager reporter;
242 
243 #endif
244