1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
/* Copyright (c) 2012 Samsung Electronics Co., Ltd.
* http://www.samsung.com/
*
* This file is part of PowerTOP
*
* This program file is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program in a file named COPYING; if not, write to the
* Free Software Foundation, Inc,
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
* or just google for it.
*
* Generic report generator.
* Written by Igor Zhbanov <i.zhbanov@samsung.com>
* 2012.10 */
#ifndef _REPORT_MAKER_H_
#define _REPORT_MAKER_H_
/* This report generator implements the following document structure:
* body
* \---> section
* |---> Title
* |---> paragraph
* |---> table
* |---> list
*
* The report body consists of a number of sections (a.k.a. <div>s,
* a.k.a. tabs).
* Each section can contain titles (<h2>), paragraphs (<p>)
* and tables (<table>).
*
* A header is a single line of text.
*
* Paragraphs can contain only text.
*
*
* Each section, table, row or cell could have its own formatting.
*
* Example of usage:
* report_maker report(REPORT_OFF);
*
* report.set_type(REPORT_HTML);
* report.add_div
* report.add_title
* report.add_list
* report.add_table
* report.finish_report();
* const char *result = report.get_result();
*/
#include <stdarg.h>
#include <string>
using namespace std;
/* Conditional gettext. We need original strings for CSV. */
#ifdef ENABLE_NLS
#define __(STRING) \
((report.get_type() == REPORT_CSV) ? (STRING) : gettext(STRING))
#else
#define __(STRING) (STRING)
#endif
#ifndef UNUSED
#define UNUSED __attribute__((unused))
#endif /* UNUSED */
/* ************************************************************************ */
enum report_type {
REPORT_OFF,
REPORT_HTML,
REPORT_CSV
};
/* ************************************************************************ */
enum section_type {
SECTION_DEFAULT,
SECTION_SYSINFO,
SECTION_CPUIDLE,
SECTION_CPUFREQ,
SECTION_DEVFREQ,
SECTION_DEVPOWER,
SECTION_SOFTWARE,
SECTION_SUMMARY,
SECTION_TUNING,
SECTION_MAX /* Must be last in this enum */
};
/* ************************************************************************ */
class report_formatter;
class report_maker
{
public:
report_maker(report_type t);
~report_maker();
report_type get_type();
void set_type(report_type t);
void addf(const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
void finish_report();
const char *get_result();
void clear_result();
void add(const char *str);
/* *** Report Style *** */
void add_header();
void end_header();
void add_logo();
void add_div(struct tag_attr *div_attr);
void end_div();
void add_title(struct tag_attr *att_title, const char *title);
void add_navigation();
void add_summary_list(string *list, int size);
void add_table(string *system_data, struct table_attributes *tb_attr);
private:
void setup_report_formatter();
report_type type;
report_formatter *formatter;
};
#endif /* _REPORT_MAKER_H_ */
|