Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit dc3858ccdf2040f8233726f899f1d3c2318cc6ba 1 parent f9a936c
Chris Ferron ceferron authored
1  Android.mk
View
@@ -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/
2  src/cpu/cpu.cpp
View
@@ -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)
4 src/devices/ahci.cpp
View
@@ -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;
5 src/devices/alsa.cpp
View
@@ -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);
2  src/devices/device.cpp
View
@@ -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)
4 src/devices/device.h
View
@@ -32,10 +32,6 @@
struct parameter_bundle;
struct result_bundle;
-#ifdef DISABLE_TRYCATCH
-#define try if(1)
-#endif
-
class device {
public:
int cached_valid;
50 src/display.cpp
View
@@ -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
2  src/display.h
View
@@ -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 = "");
4 src/lib.cpp
View
@@ -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
}
6 src/lib.h
View
@@ -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"
8 src/main.cpp
View
@@ -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();
2  src/process/do_process.cpp
View
@@ -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)
17 src/tuning/tuning.cpp
View
@@ -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 @@ class tuning_window: public tab_window {
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) {
Please sign in to comment.
Something went wrong with that request. Please try again.