Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
@@ -10,7 +10,6 @@ LOCAL_MODULE := powertop
10 10
11 11 #LOCAL_CFLAGS += -Wall -O2 -g -fno-omit-frame-pointer -fstack-protector -Wshadow -Wformat -D_FORTIFY_SOURCE=2
12 12 #LOCAL_CPPFLAGS += -Wall -O2 -g -fno-omit-frame-pointer
13   -LOCAL_CPPFLAGS += -DDISABLE_NCURSES -DDISABLE_I18N -DDISABLE_TRYCATCH
14 13
15 14 LOCAL_C_INCLUDES += external/stlport/stlport/ external/stlport/stlport/stl external/stlport/stlport/using/h/ bionic external/libnl/include/
16 15
2  src/cpu/cpu.cpp
@@ -826,7 +826,6 @@ void report_display_cpu_pstates(void)
826 826
827 827 void impl_w_display_cpu_states(int state)
828 828 {
829   -#ifndef DISABLE_NCURSES
830 829 WINDOW *win;
831 830 char buffer[128];
832 831 char linebuf[1024];
@@ -916,7 +915,6 @@ void impl_w_display_cpu_states(int state)
916 915 first_pkg++;
917 916 }
918 917 }
919   -#endif // DISABLE_NCURSES
920 918 }
921 919
922 920 void w_display_cpu_pstates(void)
4 src/devices/ahci.cpp
@@ -169,11 +169,9 @@ void ahci::start_measurement(void)
169 169 }
170 170 file.close();
171 171 }
172   -#ifndef DISABLE_TRYCATCH
173 172 catch (std::ios_base::failure &c) {
174 173 fprintf(stderr, "%s\n", c.what());
175 174 }
176   -#endif
177 175
178 176 }
179 177
@@ -204,11 +202,9 @@ void ahci::end_measurement(void)
204 202 }
205 203 file.close();
206 204 }
207   -#ifndef DISABLE_TRYCATCH
208 205 catch (std::ios_base::failure &c) {
209 206 fprintf(stderr, "%s\n", c.what());
210 207 }
211   -#endif
212 208 if (end_active < start_active)
213 209 end_active = start_active;
214 210
5 src/devices/alsa.cpp
@@ -103,12 +103,9 @@ void alsa::start_measurement(void)
103 103 }
104 104 file.close();
105 105 }
106   -#ifndef DISABLE_TRYCATCH
107 106 catch (std::ios_base::failure &c) {
108 107 fprintf(stderr, "%s\n", c.what());
109 108 }
110   -#endif
111   -
112 109 }
113 110
114 111 void alsa::end_measurement(void)
@@ -132,11 +129,9 @@ void alsa::end_measurement(void)
132 129 }
133 130 file.close();
134 131 }
135   -#ifndef DISABLE_TRYCATCH
136 132 catch (std::ios_base::failure &c) {
137 133 fprintf(stderr, "%s\n", c.what());
138 134 }
139   -#endif
140 135
141 136 p = (end_active - start_active) / (0.001 + end_active + end_inactive - start_active - start_inactive) * 100.0;
142 137 report_utilization(name, p);
2  src/devices/device.cpp
@@ -143,7 +143,6 @@ static bool power_device_sort(class device * i, class device * j)
143 143
144 144 void report_devices(void)
145 145 {
146   -#ifndef DISABLE_NCURSES
147 146 WINDOW *win;
148 147 unsigned int i;
149 148 int show_power;
@@ -212,7 +211,6 @@ void report_devices(void)
212 211 all_devices[i]->human_name()
213 212 );
214 213 }
215   -#endif // DISABLE_NCURSES
216 214 }
217 215
218 216 static const char *line_class(int line)
4 src/devices/device.h
@@ -32,10 +32,6 @@
32 32 struct parameter_bundle;
33 33 struct result_bundle;
34 34
35   -#ifdef DISABLE_TRYCATCH
36   -#define try if(1)
37   -#endif
38   -
39 35 class device {
40 36 public:
41 37 int cached_valid;
50 src/display.cpp
@@ -43,7 +43,6 @@ map<string, string> tab_translations;
43 43
44 44 map<string, string> bottom_lines;
45 45
46   -#ifndef DISABLE_NCURSES
47 46 void create_tab(const string &name, const string &translation, class tab_window *w, string bottom_line)
48 47 {
49 48 if (!w)
@@ -293,52 +292,3 @@ int ncurses_initialized(void)
293 292 return 1;
294 293 return 0;
295 294 }
296   -
297   -#else /* DISABLE_NCURSES - stub implementations*/
298   -
299   -void create_tab(const string &name, const string &translation, class tab_window *w, string bottom_line)
300   -{
301   -}
302   -
303   -
304   -void init_display(void)
305   -{
306   -}
307   -
308   -void reset_display(void)
309   -{
310   -}
311   -
312   -void show_tab(unsigned int tab)
313   -{
314   -}
315   -
316   -void show_next_tab(void)
317   -{
318   -}
319   -
320   -void show_prev_tab(void)
321   -{
322   -}
323   -
324   -void show_cur_tab(void)
325   -{
326   -}
327   -
328   -void cursor_down(void)
329   -{
330   -}
331   -
332   -void cursor_up(void)
333   -{
334   -}
335   -void cursor_enter(void)
336   -{
337   -}
338   -
339   -int ncurses_initialized(void)
340   -{
341   - return 0;
342   -}
343   -
344   -#endif
2  src/display.h
@@ -44,7 +44,6 @@ extern void cursor_down(void);
44 44 extern void cursor_enter(void);
45 45 extern void window_refresh(void);
46 46
47   -#ifndef DISABLE_NCURSES
48 47 class tab_window {
49 48 public:
50 49 int cursor_pos;
@@ -73,7 +72,6 @@ extern map<string, class tab_window *> tab_windows;
73 72 WINDOW *get_ncurses_win(const char *name);
74 73 WINDOW *get_ncurses_win(const string &name);
75 74 WINDOW *get_ncurses_win(int nr);
76   -#endif /* DISABLE_NCURSES */
77 75
78 76 void create_tab(const string &name, const string &translation, class tab_window *w = NULL, string bottom_line = "");
79 77
4 src/lib.cpp
@@ -52,9 +52,7 @@ extern "C" {
52 52 #include <sys/stat.h>
53 53 #include <dirent.h>
54 54 #include <locale.h>
55   -#ifndef DISABLE_I18N
56 55 #include <libintl.h>
57   -#endif
58 56 #include <limits>
59 57 #include <math.h>
60 58 #include <ncurses.h>
@@ -261,10 +259,8 @@ void format_watts(double W, char *buffer, unsigned int len)
261 259 if (W < 0.0001)
262 260 sprintf(buffer, _(" 0 mW"));
263 261
264   -#ifndef DISABLE_NCURSES
265 262 while (mbstowcs(NULL,buffer,0) < len)
266 263 strcat(buffer, " ");
267   -#endif
268 264 }
269 265
270 266
6 src/lib.h
@@ -25,9 +25,7 @@
25 25 #ifndef INCLUDE_GUARD_LIB_H
26 26 #define INCLUDE_GUARD_LIB_H
27 27
28   -#ifndef DISABLE_I18N
29 28 #include <libintl.h>
30   -#endif
31 29 #include <stdint.h>
32 30
33 31 /* Include only for Automake builds */
@@ -35,11 +33,7 @@
35 33 #include "config.h"
36 34 #endif
37 35
38   -#ifndef DISABLE_I18N
39 36 #define _(STRING) gettext(STRING)
40   -#else
41   -#define _(STRING) (STRING)
42   -#endif
43 37
44 38 #define POWERTOP_VERSION "v2.1"
45 39 #define POWERTOP_SHORT_VERSION "2.1"
8 src/main.cpp
@@ -127,7 +127,6 @@ static void do_sleep(int seconds)
127 127 sleep(seconds);
128 128 return;
129 129 }
130   -#ifndef DISABLE_NCURSES
131 130 target = time(NULL) + seconds;
132 131 delta = seconds;
133 132 do {
@@ -174,7 +173,6 @@ static void do_sleep(int seconds)
174 173 break;
175 174
176 175 } while (1);
177   -#endif
178 176 }
179 177
180 178
@@ -338,15 +336,11 @@ int main(int argc, char **argv)
338 336 char workload[4096] = {0,};
339 337 int iterations = 1;
340 338
341   -#ifndef DISABLE_TRYCATCH
342 339 set_new_handler(out_of_memory);
343   -#endif
344 340
345 341 setlocale (LC_ALL, "");
346   -#ifndef DISABLE_I18N
347 342 bindtextdomain (PACKAGE, LOCALEDIR);
348 343 textdomain (PACKAGE);
349   -#endif
350 344
351 345 while (1) { /* parse commandline options */
352 346 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)
438 432 one_measurement(time_out, NULL);
439 433 learn_parameters(15, 0);
440 434 }
441   -#ifndef DISABLE_NCURSES
442 435 endwin();
443   -#endif
444 436 printf("%s\n", _("Leaving PowerTOP"));
445 437
446 438 end_process_data();
2  src/process/do_process.cpp
@@ -783,7 +783,6 @@ double total_xwakes(void)
783 783
784 784 void process_update_display(void)
785 785 {
786   -#ifndef DISABLE_NCURSES
787 786 unsigned int i;
788 787 WINDOW *win;
789 788 double pw;
@@ -881,7 +880,6 @@ void process_update_display(void)
881 880 while (strlen(events) < 12) strcat(events, " ");
882 881 wprintw(win, "%s %s %s %s %s\n", power, usage, events, name, pretty_print(all_power[i]->description(), descr, 128));
883 882 }
884   -#endif // DISABLE_NCURSES
885 883 }
886 884
887 885 static const char *process_class(int line)
17 src/tuning/tuning.cpp
@@ -45,7 +45,6 @@
45 45 static void sort_tunables(void);
46 46 static bool should_clear = false;
47 47
48   -#ifndef DISABLE_NCURSES
49 48 class tuning_window: public tab_window {
50 49 public:
51 50 virtual void repaint(void);
@@ -53,7 +52,6 @@ class tuning_window: public tab_window {
53 52 virtual void expose(void);
54 53 virtual void window_refresh(void);
55 54 };
56   -#endif // DISABLE_NCURSES
57 55
58 56 static void init_tuning(void)
59 57 {
@@ -75,25 +73,20 @@ static void init_tuning(void)
75 73
76 74 void initialize_tuning(void)
77 75 {
78   -#ifndef DISABLE_NCURSES
79 76 class tuning_window *w;
80 77
81 78 w = new tuning_window();
82 79 create_tab("Tunables", _("Tunables"), w, _(" <ESC> Exit | <Enter> Toggle tunable | <r> Window refresh"));
83   -#endif // DISABLE_NCURSES
84 80
85 81 init_tuning();
86 82
87   -#ifndef DISABLE_NCURSES
88 83 w->cursor_max = all_tunables.size() - 1;
89   -#endif // DISABLE_NCURSES
90 84 }
91 85
92 86
93 87
94 88 static void __tuning_update_display(int cursor_pos)
95 89 {
96   -#ifndef DISABLE_NCURSES
97 90 WINDOW *win;
98 91 unsigned int i;
99 92
@@ -128,21 +121,18 @@ static void __tuning_update_display(int cursor_pos)
128 121 }
129 122 wprintw(win, "%s %s\n", _(res), _(desc));
130 123 }
131   -#endif
132 124 }
133 125
134 126 void tuning_update_display(void)
135 127 {
136   -#ifndef DISABLE_NCURSES
137 128 class tab_window *w;
138 129
139 130 w = tab_windows["Tunables"];
140 131 if (!w)
141 132 return;
142 133 w->repaint();
143   -#endif
144 134 }
145   -#ifndef DISABLE_NCURSES
  135 +
146 136 void tuning_window::repaint(void)
147 137 {
148 138 __tuning_update_display(cursor_pos);
@@ -157,7 +147,6 @@ void tuning_window::cursor_enter(void)
157 147 return;
158 148 tun->toggle();
159 149 }
160   -#endif // DISABLE_NCURSES
161 150
162 151 static bool tunables_sort(class tunable * i, class tunable * j)
163 152 {
@@ -193,14 +182,14 @@ static void sort_tunables(void)
193 182 {
194 183 sort(all_tunables.begin(), all_tunables.end(), tunables_sort);
195 184 }
196   -#ifndef DISABLE_NCURSES
  185 +
197 186 void tuning_window::expose(void)
198 187 {
199 188 cursor_pos = 0;
200 189 sort_tunables();
201 190 repaint();
202 191 }
203   -#endif // DISABLE_NCURSES
  192 +
204 193 static const char *tune_class(int line)
205 194 {
206 195 if (line & 1) {

0 comments on commit dc3858c

Please sign in to comment.
Something went wrong with that request. Please try again.