aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris E Ferron <chris.e.ferron@linux.intel.com>2012-08-20 09:48:06 -0700
committerChris E Ferron <chris.e.ferron@linux.intel.com>2012-08-20 09:48:06 -0700
commitdc3858ccdf2040f8233726f899f1d3c2318cc6ba (patch)
tree9a4abd695037f12229fe2d82c781cef6e954aea3
parentf9a936c1d53f8801cb6006b53e9c3a17dd731d02 (diff)
Removed unwanted defines from PowerTOP.
It is desired that PowerTOP not use ifdef's for the majority. It is understood that if may just need to stub some code out, but this should be a rare case. To clean up code there are three defines identified -- DISABLE_NCURSES -- DISABLE_TRYCATCH -- DISABLE_I18N that are not really needed. They were put in the code originally to quickly support android. After evaluation it has occurred to us that there are better ways of dealing this distribution specific issues. It is preferred for the project, that stubs be created by those how need or care about such issues, and should be a separate stub.
-rw-r--r--Android.mk1
-rw-r--r--src/cpu/cpu.cpp2
-rw-r--r--src/devices/ahci.cpp4
-rw-r--r--src/devices/alsa.cpp5
-rw-r--r--src/devices/device.cpp2
-rw-r--r--src/devices/device.h4
-rw-r--r--src/display.cpp50
-rw-r--r--src/display.h2
-rw-r--r--src/lib.cpp4
-rw-r--r--src/lib.h6
-rw-r--r--src/main.cpp8
-rw-r--r--src/process/do_process.cpp2
-rw-r--r--src/tuning/tuning.cpp17
13 files changed, 3 insertions, 104 deletions
diff --git a/Android.mk b/Android.mk
index a46a288..a52ecfd 100644
--- a/Android.mk
+++ b/Android.mk
@@ -10,7 +10,6 @@ LOCAL_MODULE := powertop
#LOCAL_CFLAGS += -Wall -O2 -g -fno-omit-frame-pointer -fstack-protector -Wshadow -Wformat -D_FORTIFY_SOURCE=2
#LOCAL_CPPFLAGS += -Wall -O2 -g -fno-omit-frame-pointer
-LOCAL_CPPFLAGS += -DDISABLE_NCURSES -DDISABLE_I18N -DDISABLE_TRYCATCH
LOCAL_C_INCLUDES += external/stlport/stlport/ external/stlport/stlport/stl external/stlport/stlport/using/h/ bionic external/libnl/include/
diff --git a/src/cpu/cpu.cpp b/src/cpu/cpu.cpp
index 26c09b4..368d3dd 100644
--- a/src/cpu/cpu.cpp
+++ b/src/cpu/cpu.cpp
@@ -826,7 +826,6 @@ void report_display_cpu_pstates(void)
void impl_w_display_cpu_states(int state)
{
-#ifndef DISABLE_NCURSES
WINDOW *win;
char buffer[128];
char linebuf[1024];
@@ -916,7 +915,6 @@ void impl_w_display_cpu_states(int state)
first_pkg++;
}
}
-#endif // DISABLE_NCURSES
}
void w_display_cpu_pstates(void)
diff --git a/src/devices/ahci.cpp b/src/devices/ahci.cpp
index 21f9d19..1fe39c7 100644
--- a/src/devices/ahci.cpp
+++ b/src/devices/ahci.cpp
@@ -169,11 +169,9 @@ void ahci::start_measurement(void)
}
file.close();
}
-#ifndef DISABLE_TRYCATCH
catch (std::ios_base::failure &c) {
fprintf(stderr, "%s\n", c.what());
}
-#endif
}
@@ -204,11 +202,9 @@ void ahci::end_measurement(void)
}
file.close();
}
-#ifndef DISABLE_TRYCATCH
catch (std::ios_base::failure &c) {
fprintf(stderr, "%s\n", c.what());
}
-#endif
if (end_active < start_active)
end_active = start_active;
diff --git a/src/devices/alsa.cpp b/src/devices/alsa.cpp
index 40cb1f5..4f5d3f9 100644
--- a/src/devices/alsa.cpp
+++ b/src/devices/alsa.cpp
@@ -103,12 +103,9 @@ void alsa::start_measurement(void)
}
file.close();
}
-#ifndef DISABLE_TRYCATCH
catch (std::ios_base::failure &c) {
fprintf(stderr, "%s\n", c.what());
}
-#endif
-
}
void alsa::end_measurement(void)
@@ -132,11 +129,9 @@ void alsa::end_measurement(void)
}
file.close();
}
-#ifndef DISABLE_TRYCATCH
catch (std::ios_base::failure &c) {
fprintf(stderr, "%s\n", c.what());
}
-#endif
p = (end_active - start_active) / (0.001 + end_active + end_inactive - start_active - start_inactive) * 100.0;
report_utilization(name, p);
diff --git a/src/devices/device.cpp b/src/devices/device.cpp
index d98e9b8..2556439 100644
--- a/src/devices/device.cpp
+++ b/src/devices/device.cpp
@@ -143,7 +143,6 @@ static bool power_device_sort(class device * i, class device * j)
void report_devices(void)
{
-#ifndef DISABLE_NCURSES
WINDOW *win;
unsigned int i;
int show_power;
@@ -212,7 +211,6 @@ void report_devices(void)
all_devices[i]->human_name()
);
}
-#endif // DISABLE_NCURSES
}
static const char *line_class(int line)
diff --git a/src/devices/device.h b/src/devices/device.h
index 9741243..a373875 100644
--- a/src/devices/device.h
+++ b/src/devices/device.h
@@ -32,10 +32,6 @@
struct parameter_bundle;
struct result_bundle;
-#ifdef DISABLE_TRYCATCH
-#define try if(1)
-#endif
-
class device {
public:
int cached_valid;
diff --git a/src/display.cpp b/src/display.cpp
index caa66d0..e17745d 100644
--- a/src/display.cpp
+++ b/src/display.cpp
@@ -43,7 +43,6 @@ map<string, string> tab_translations;
map<string, string> bottom_lines;
-#ifndef DISABLE_NCURSES
void create_tab(const string &name, const string &translation, class tab_window *w, string bottom_line)
{
if (!w)
@@ -293,52 +292,3 @@ int ncurses_initialized(void)
return 1;
return 0;
}
-
-#else /* DISABLE_NCURSES - stub implementations*/
-
-void create_tab(const string &name, const string &translation, class tab_window *w, string bottom_line)
-{
-}
-
-
-void init_display(void)
-{
-}
-
-void reset_display(void)
-{
-}
-
-void show_tab(unsigned int tab)
-{
-}
-
-void show_next_tab(void)
-{
-}
-
-void show_prev_tab(void)
-{
-}
-
-void show_cur_tab(void)
-{
-}
-
-void cursor_down(void)
-{
-}
-
-void cursor_up(void)
-{
-}
-void cursor_enter(void)
-{
-}
-
-int ncurses_initialized(void)
-{
- return 0;
-}
-
-#endif
diff --git a/src/display.h b/src/display.h
index e0f66a3..72f771a 100644
--- a/src/display.h
+++ b/src/display.h
@@ -44,7 +44,6 @@ extern void cursor_down(void);
extern void cursor_enter(void);
extern void window_refresh(void);
-#ifndef DISABLE_NCURSES
class tab_window {
public:
int cursor_pos;
@@ -73,7 +72,6 @@ extern map<string, class tab_window *> tab_windows;
WINDOW *get_ncurses_win(const char *name);
WINDOW *get_ncurses_win(const string &name);
WINDOW *get_ncurses_win(int nr);
-#endif /* DISABLE_NCURSES */
void create_tab(const string &name, const string &translation, class tab_window *w = NULL, string bottom_line = "");
diff --git a/src/lib.cpp b/src/lib.cpp
index 77e49a2..8753421 100644
--- a/src/lib.cpp
+++ b/src/lib.cpp
@@ -52,9 +52,7 @@ extern "C" {
#include <sys/stat.h>
#include <dirent.h>
#include <locale.h>
-#ifndef DISABLE_I18N
#include <libintl.h>
-#endif
#include <limits>
#include <math.h>
#include <ncurses.h>
@@ -261,10 +259,8 @@ void format_watts(double W, char *buffer, unsigned int len)
if (W < 0.0001)
sprintf(buffer, _(" 0 mW"));
-#ifndef DISABLE_NCURSES
while (mbstowcs(NULL,buffer,0) < len)
strcat(buffer, " ");
-#endif
}
diff --git a/src/lib.h b/src/lib.h
index 260b444..8cf4632 100644
--- a/src/lib.h
+++ b/src/lib.h
@@ -25,9 +25,7 @@
#ifndef INCLUDE_GUARD_LIB_H
#define INCLUDE_GUARD_LIB_H
-#ifndef DISABLE_I18N
#include <libintl.h>
-#endif
#include <stdint.h>
/* Include only for Automake builds */
@@ -35,11 +33,7 @@
#include "config.h"
#endif
-#ifndef DISABLE_I18N
#define _(STRING) gettext(STRING)
-#else
-#define _(STRING) (STRING)
-#endif
#define POWERTOP_VERSION "v2.1"
#define POWERTOP_SHORT_VERSION "2.1"
diff --git a/src/main.cpp b/src/main.cpp
index 29b0095..139b514 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -127,7 +127,6 @@ static void do_sleep(int seconds)
sleep(seconds);
return;
}
-#ifndef DISABLE_NCURSES
target = time(NULL) + seconds;
delta = seconds;
do {
@@ -174,7 +173,6 @@ static void do_sleep(int seconds)
break;
} while (1);
-#endif
}
@@ -338,15 +336,11 @@ int main(int argc, char **argv)
char workload[4096] = {0,};
int iterations = 1;
-#ifndef DISABLE_TRYCATCH
set_new_handler(out_of_memory);
-#endif
setlocale (LC_ALL, "");
-#ifndef DISABLE_I18N
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
-#endif
while (1) { /* parse commandline options */
c = getopt_long (argc, argv, "ch:C:i:t:uV:w:q", long_options, &option_index);
@@ -438,9 +432,7 @@ int main(int argc, char **argv)
one_measurement(time_out, NULL);
learn_parameters(15, 0);
}
-#ifndef DISABLE_NCURSES
endwin();
-#endif
printf("%s\n", _("Leaving PowerTOP"));
end_process_data();
diff --git a/src/process/do_process.cpp b/src/process/do_process.cpp
index 2700230..cb7c672 100644
--- a/src/process/do_process.cpp
+++ b/src/process/do_process.cpp
@@ -783,7 +783,6 @@ double total_xwakes(void)
void process_update_display(void)
{
-#ifndef DISABLE_NCURSES
unsigned int i;
WINDOW *win;
double pw;
@@ -881,7 +880,6 @@ void process_update_display(void)
while (strlen(events) < 12) strcat(events, " ");
wprintw(win, "%s %s %s %s %s\n", power, usage, events, name, pretty_print(all_power[i]->description(), descr, 128));
}
-#endif // DISABLE_NCURSES
}
static const char *process_class(int line)
diff --git a/src/tuning/tuning.cpp b/src/tuning/tuning.cpp
index 865d986..4893597 100644
--- a/src/tuning/tuning.cpp
+++ b/src/tuning/tuning.cpp
@@ -45,7 +45,6 @@
static void sort_tunables(void);
static bool should_clear = false;
-#ifndef DISABLE_NCURSES
class tuning_window: public tab_window {
public:
virtual void repaint(void);
@@ -53,7 +52,6 @@ public:
virtual void expose(void);
virtual void window_refresh(void);
};
-#endif // DISABLE_NCURSES
static void init_tuning(void)
{
@@ -75,25 +73,20 @@ static void init_tuning(void)
void initialize_tuning(void)
{
-#ifndef DISABLE_NCURSES
class tuning_window *w;
w = new tuning_window();
create_tab("Tunables", _("Tunables"), w, _(" <ESC> Exit | <Enter> Toggle tunable | <r> Window refresh"));
-#endif // DISABLE_NCURSES
init_tuning();
-#ifndef DISABLE_NCURSES
w->cursor_max = all_tunables.size() - 1;
-#endif // DISABLE_NCURSES
}
static void __tuning_update_display(int cursor_pos)
{
-#ifndef DISABLE_NCURSES
WINDOW *win;
unsigned int i;
@@ -128,21 +121,18 @@ static void __tuning_update_display(int cursor_pos)
}
wprintw(win, "%s %s\n", _(res), _(desc));
}
-#endif
}
void tuning_update_display(void)
{
-#ifndef DISABLE_NCURSES
class tab_window *w;
w = tab_windows["Tunables"];
if (!w)
return;
w->repaint();
-#endif
}
-#ifndef DISABLE_NCURSES
+
void tuning_window::repaint(void)
{
__tuning_update_display(cursor_pos);
@@ -157,7 +147,6 @@ void tuning_window::cursor_enter(void)
return;
tun->toggle();
}
-#endif // DISABLE_NCURSES
static bool tunables_sort(class tunable * i, class tunable * j)
{
@@ -193,14 +182,14 @@ static void sort_tunables(void)
{
sort(all_tunables.begin(), all_tunables.end(), tunables_sort);
}
-#ifndef DISABLE_NCURSES
+
void tuning_window::expose(void)
{
cursor_pos = 0;
sort_tunables();
repaint();
}
-#endif // DISABLE_NCURSES
+
static const char *tune_class(int line)
{
if (line & 1) {