From: Sergey Senozhatsky <sergey.senozhatsky at gmail.com>
To: powertop@lists.01.org
Subject: [Powertop] [RFC][PATCH] Small rework on report formatter side
Date: Wed, 10 Oct 2012 11:13:52 -0700 [thread overview]
Message-ID: <20121010181352.GA4628@swordfish.datadirect.datadirectnet.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 15248 bytes --]
Hello,
below is initial version of rework I was talking about. Igor did most part of it (introduced
report_formatter_base class), so mine are just minor tweaks. I'm glad still no one mentioned
templates, just kidding.
one thing I don't really like so far is
else if (type == REPORT_OFF)
formatter = new report_formatter();
which is just cryptic and thus look wrong.
perhaps we need something like `new report_formatter_basic()' here (which will require header
file rename).
please review and comment.
------------------------------------------------------------------------
Small rework on report formatter side:
- make report_formatter a basic class (previously was interface). hence we can
remove empty report_formatter interface implementation.
- drop report-formatter-null class
- in report maker now we create report_formatter instance for REPORT_OFF mode
- rename report_formatter_base to report_formatter_string_base, so class name tells
a bit more, later we can create report_formatter_xml_base/report_formatter_json_base/etc.
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky(a)gmail.com>
---
src/Makefile.am | 1 -
src/report/report-formatter-base.cpp | 14 +--
src/report/report-formatter-base.h | 2 +-
src/report/report-formatter-csv.h | 2 +-
src/report/report-formatter-html.h | 2 +-
src/report/report-formatter-null.cpp | 179 -----------------------------------
src/report/report-formatter-null.h | 66 -------------
src/report/report-formatter.h | 38 ++++----
src/report/report-maker.cpp | 3 +-
9 files changed, 30 insertions(+), 277 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index ccf3f0c..1a64622 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,7 +34,6 @@ powertop_SOURCES = parameters/persistent.cpp parameters/learn.cpp parameters/par
report/report-formatter-base.cpp report/report-formatter-base.h \
report/report-formatter-csv.cpp report/report-formatter-csv.h \
report/report-formatter-html.cpp report/report-formatter-html.h \
- report/report-formatter-null.cpp report/report-formatter-null.h \
main.cpp css.h powertop.css cpu/intel_gpu.cpp
diff --git a/src/report/report-formatter-base.cpp b/src/report/report-formatter-base.cpp
index 4b448be..c6d5d9d 100644
--- a/src/report/report-formatter-base.cpp
+++ b/src/report/report-formatter-base.cpp
@@ -36,7 +36,7 @@
/* ************************************************************************ */
const char *
-report_formatter_base::get_result()
+report_formatter_string_base::get_result()
{
return result.c_str();
}
@@ -44,7 +44,7 @@ report_formatter_base::get_result()
/* ************************************************************************ */
void
-report_formatter_base::clear_result()
+report_formatter_string_base::clear_result()
{
result.clear();
}
@@ -52,7 +52,7 @@ report_formatter_base::clear_result()
/* ************************************************************************ */
void
-report_formatter_base::add(const char *str)
+report_formatter_string_base::add(const char *str)
{
assert(str);
@@ -62,7 +62,7 @@ report_formatter_base::add(const char *str)
/* ************************************************************************ */
void
-report_formatter_base::add_exact(const char *str)
+report_formatter_string_base::add_exact(const char *str)
{
assert(str);
@@ -74,7 +74,7 @@ report_formatter_base::add_exact(const char *str)
#define LINE_SIZE 8192
void
-report_formatter_base::addv(const char *fmt, va_list ap)
+report_formatter_string_base::addv(const char *fmt, va_list ap)
{
char str[LINE_SIZE];
@@ -87,7 +87,7 @@ report_formatter_base::addv(const char *fmt, va_list ap)
/* ************************************************************************ */
void
-report_formatter_base::addf(const char *fmt, ...)
+report_formatter_string_base::addf(const char *fmt, ...)
{
va_list ap;
@@ -101,7 +101,7 @@ report_formatter_base::addf(const char *fmt, ...)
/* ************************************************************************ */
void
-report_formatter_base::addf_exact(const char *fmt, ...)
+report_formatter_string_base::addf_exact(const char *fmt, ...)
{
char str[LINE_SIZE];
va_list ap;
diff --git a/src/report/report-formatter-base.h b/src/report/report-formatter-base.h
index 7063174..e35a2ff 100644
--- a/src/report/report-formatter-base.h
+++ b/src/report/report-formatter-base.h
@@ -28,7 +28,7 @@
#include "report-formatter.h"
-class report_formatter_base: public report_formatter
+class report_formatter_string_base: public report_formatter
{
public:
virtual const char *get_result();
diff --git a/src/report/report-formatter-csv.h b/src/report/report-formatter-csv.h
index fbec0c9..8dd2976 100644
--- a/src/report/report-formatter-csv.h
+++ b/src/report/report-formatter-csv.h
@@ -44,7 +44,7 @@
/* ************************************************************************ */
-class report_formatter_csv: public report_formatter_base
+class report_formatter_csv: public report_formatter_string_base
{
public:
report_formatter_csv();
diff --git a/src/report/report-formatter-html.h b/src/report/report-formatter-html.h
index 1c3eb4a..4d00efe 100644
--- a/src/report/report-formatter-html.h
+++ b/src/report/report-formatter-html.h
@@ -55,7 +55,7 @@ struct html_cell {
/* ************************************************************************ */
-class report_formatter_html: public report_formatter_base
+class report_formatter_html: public report_formatter_string_base
{
public:
report_formatter_html();
diff --git a/src/report/report-formatter-null.cpp b/src/report/report-formatter-null.cpp
deleted file mode 100644
index 22da7a0..0000000
--- a/src/report/report-formatter-null.cpp
+++ /dev/null
@@ -1,179 +0,0 @@
-/* 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.
- *
- * Null report generator.
- * Written by Igor Zhbanov <i.zhbanov(a)samsung.com>
- * 2012.10 */
-
-#include <stdarg.h>
-
-#include "report-formatter-null.h"
-
-/* ************************************************************************ */
-
-report_formatter_null::report_formatter_null()
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::finish_report()
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-const char *
-report_formatter_null::get_result()
-{
- return "";
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::clear_result()
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::add(const char *str UNUSED)
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::addv(const char *fmt UNUSED, va_list ap UNUSED)
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::add_header(const char *header UNUSED, int level UNUSED)
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::begin_section(section_type stype UNUSED)
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::end_section()
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::begin_table(table_type ttype UNUSED)
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::end_table()
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::begin_row(row_type rtype UNUSED)
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::end_row()
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::begin_cell(cell_type ctype UNUSED)
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::end_cell()
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::add_empty_cell()
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::begin_paragraph()
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::end_paragraph()
-{
- /* Do nothing */
-}
-
-/* ************************************************************************ */
-
-void
-report_formatter_null::set_cpu_number(int nr UNUSED)
-{
- /* Do nothing */
-}
diff --git a/src/report/report-formatter-null.h b/src/report/report-formatter-null.h
deleted file mode 100644
index 51493ee..0000000
--- a/src/report/report-formatter-null.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/* 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.
- *
- * Null report generator.
- * Written by Igor Zhbanov <i.zhbanov(a)samsung.com>
- * 2012.10 */
-
-#ifndef _REPORT_FORMATTER_NULL_H_
-#define _REPORT_FORMATTER_NULL_H_
-
-#include "report-formatter.h"
-
-/* ************************************************************************ */
-
-class report_formatter_null: public report_formatter
-{
-public:
- report_formatter_null();
-
- void finish_report();
- const char *get_result();
- void clear_result();
-
- void add(const char *str);
- void addv(const char *fmt, va_list ap);
-
- void add_header(const char *header, int level);
-
- void begin_section(section_type stype);
- void end_section();
-
- void begin_table(table_type ttype);
- void end_table();
-
- void begin_row(row_type rtype);
- void end_row();
-
- void begin_cell(cell_type ctype);
- void end_cell();
- void add_empty_cell();
-
- void begin_paragraph();
- void end_paragraph();
-
- void set_cpu_number(int nr);
-};
-
-#endif /* _REPORT_FORMATTER_NULL_H_ */
diff --git a/src/report/report-formatter.h b/src/report/report-formatter.h
index cec0796..7f9f544 100644
--- a/src/report/report-formatter.h
+++ b/src/report/report-formatter.h
@@ -28,38 +28,38 @@
#include "report-maker.h"
-class report_formatter /* Interface */
+class report_formatter
{
public:
virtual ~report_formatter() {}
- virtual void finish_report() = 0;
- virtual const char *get_result() = 0;
- virtual void clear_result() = 0;
+ virtual void finish_report() {};
+ virtual const char *get_result() {return "Basic report_formatter::get_resul call\n";};
+ virtual void clear_result() {};
- virtual void add(const char *str) = 0;
- virtual void addv(const char *fmt, va_list ap) = 0;
+ virtual void add(const char *str) {};
+ virtual void addv(const char *fmt, va_list ap) {};
- virtual void add_header(const char *header, int level) = 0;
+ virtual void add_header(const char *header, int level) {};
- virtual void begin_section(section_type stype) = 0;
- virtual void end_section() = 0;
+ virtual void begin_section(section_type stype) {};
+ virtual void end_section() {};
- virtual void begin_table(table_type ttype) = 0;
- virtual void end_table() = 0;
+ virtual void begin_table(table_type ttype) {};
+ virtual void end_table() {};
- virtual void begin_row(row_type rtype) = 0;
- virtual void end_row() = 0;
+ virtual void begin_row(row_type rtype) {};
+ virtual void end_row() {};
- virtual void begin_cell(cell_type ctype) = 0;
- virtual void end_cell() = 0;
- virtual void add_empty_cell() = 0;
+ virtual void begin_cell(cell_type ctype) {};
+ virtual void end_cell() {};
+ virtual void add_empty_cell() {};
- virtual void begin_paragraph() = 0;
- virtual void end_paragraph() = 0;
+ virtual void begin_paragraph() {};
+ virtual void end_paragraph() {};
/* For quad-colouring CPU tables in HTML */
- virtual void set_cpu_number(int nr) = 0;
+ virtual void set_cpu_number(int nr) {};
};
#endif /* _REPORT_FORMATTER_H_ */
diff --git a/src/report/report-maker.cpp b/src/report/report-maker.cpp
index 4a68a8c..eef0fb1 100644
--- a/src/report/report-maker.cpp
+++ b/src/report/report-maker.cpp
@@ -31,7 +31,6 @@
#include "report-maker.h"
#include "report-formatter-csv.h"
#include "report-formatter-html.h"
-#include "report-formatter-null.h"
/* ************************************************************************ */
@@ -114,7 +113,7 @@ report_maker::setup_report_formatter()
else if (type == REPORT_CSV)
formatter = new report_formatter_csv();
else if (type == REPORT_OFF)
- formatter = new report_formatter_null();
+ formatter = new report_formatter();
else
assert(false);
}
next reply other threads:[~2012-10-10 18:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-10 18:13 Sergey Senozhatsky [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-10-10 23:03 [Powertop] [RFC][PATCH] Small rework on report formatter side Sergey Senozhatsky
2012-10-11 21:55 Chris Ferron
2012-10-12 13:46 Igor Zhbanov
2012-10-13 13:31 Sergey Senozhatsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20121010181352.GA4628@swordfish.datadirect.datadirectnet.com \
--to=powertop@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.