This patch disables the ncurses feature to build powertop natively on
android. This patch can be disabled by removing the  DISABLE_NCURSES
flag in the Android.mk file. A dummy ncurses.h file is added too

Signed-off-by: John Mathew <[email protected]>
---
 cpu/cpu.cpp            |    5 +++-
 devices/device.cpp     |    2 +
 display.cpp            |   50 ++++++++++++++++++++++++++++++++++++++++++++++++
 display.h              |    3 +-
 lib.cpp                |    5 ++-
 main.cpp               |    6 +++-
 ncurses.h              |    1 +
 process/do_process.cpp |    2 +
 tuning/tuning.cpp      |   21 ++++++++++++++-----
 9 files changed, 83 insertions(+), 12 deletions(-)

diff --git a/cpu/cpu.cpp b/cpu/cpu.cpp
index 21dcc89..6e49ad0 100644
--- a/cpu/cpu.cpp
+++ b/cpu/cpu.cpp
@@ -472,6 +472,7 @@ void html_display_cpu_cstates(void)
 
 void w_display_cpu_cstates(void)
 {
+#ifndef DISABLE_NCURSES
        WINDOW *win;
        char buffer[128];
        char linebuf[1024];
@@ -558,6 +559,7 @@ void w_display_cpu_cstates(void)
 
 
        }
+#endif // DISABLE_NCURSES
 }
 
 
@@ -676,6 +678,7 @@ void html_display_cpu_pstates(void)
 
 void w_display_cpu_pstates(void)
 {
+#ifndef DISABLE_NCURSES
        WINDOW *win;
        char buffer[128];
        char linebuf[1024];
@@ -764,7 +767,7 @@ void w_display_cpu_pstates(void)
 
 
        }
-
+#endif // DISABLE_NCURSES
 }
 
 
diff --git a/devices/device.cpp b/devices/device.cpp
index c38b96c..2db3de0 100644
--- a/devices/device.cpp
+++ b/devices/device.cpp
@@ -141,6 +141,7 @@ 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;
@@ -209,6 +210,7 @@ void report_devices(void)
                        all_devices[i]->human_name()
                        );
        }
+#endif // DISABLE_NCURSES
 }
 
 static const char *line_class(int line)
diff --git a/display.cpp b/display.cpp
index 5ca260e..f486050 100644
--- a/display.cpp
+++ b/display.cpp
@@ -43,6 +43,7 @@ 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)
@@ -277,3 +278,52 @@ 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
\ No newline at end of file
diff --git a/display.h b/display.h
index 5c1ce59..3b24914 100644
--- a/display.h
+++ b/display.h
@@ -43,6 +43,7 @@ extern void cursor_up(void);
 extern void cursor_down(void);
 extern void cursor_enter(void);
 
+#ifndef DISABLE_NCURSES
 class tab_window {
 public:
        int cursor_pos;
@@ -64,8 +65,8 @@ 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 = "");
 
-
 #endif
diff --git a/lib.cpp b/lib.cpp
index ba6be7a..e6684b0 100644
--- a/lib.cpp
+++ b/lib.cpp
@@ -237,9 +237,10 @@ 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, " ");    
+               strcat(buffer, " ");
+#endif 
 }
 
 
diff --git a/main.cpp b/main.cpp
index 7e5a242..801ae85 100644
--- a/main.cpp
+++ b/main.cpp
@@ -98,7 +98,7 @@ static void do_sleep(int seconds)
                sleep(seconds);
                return;
        }
-
+#ifndef DISABLE_NCURSES
        target = time(NULL) + seconds;
        delta = seconds;
        do {
@@ -138,6 +138,7 @@ static void do_sleep(int seconds)
                        break;
                        
        } while (1);
+#endif
 }
 
 
@@ -386,8 +387,9 @@ int main(int argc, char **argv)
                show_cur_tab();
                learn_parameters(15, 0);
        }
-
+#ifndef DISABLE_NCURSES
        endwin();
+#endif
        printf(_("Leaving PowerTOP\n"));
 
 
diff --git a/ncurses.h b/ncurses.h
new file mode 100644
index 0000000..d0d6b85
--- /dev/null
+++ b/ncurses.h
@@ -0,0 +1 @@
+/*Dummy ncurses file*/
diff --git a/process/do_process.cpp b/process/do_process.cpp
index 15dcd92..5c382f1 100644
--- a/process/do_process.cpp
+++ b/process/do_process.cpp
@@ -649,6 +649,7 @@ double total_xwakes(void)
 
 void process_update_display(void)
 {
+#ifndef DISABLE_NCURSES
        unsigned int i;
        WINDOW *win;
        double pw;
@@ -742,6 +743,7 @@ 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/tuning/tuning.cpp b/tuning/tuning.cpp
index c63f1e8..d50d07c 100644
--- a/tuning/tuning.cpp
+++ b/tuning/tuning.cpp
@@ -44,20 +44,23 @@
 
 static void sort_tunables(void);
 
-
+#ifndef DISABLE_NCURSES
 class tuning_window: public tab_window {
 public:
        virtual void repaint(void);
        virtual void cursor_enter(void);
        virtual void expose(void);
 };
-
+#endif // DISABLE_NCURSES
 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"));
+#endif // DISABLE_NCURSES
+
        add_sysfs_tunable(_("Enable Audio codec power management"), 
"/sys/module/snd_hda_intel/parameters/power_save", "1");
        add_sysfs_tunable(_("Enable SATA link power management for /dev/sda"), 
"/sys/class/scsi_host/host0/link_power_management_policy", "min_power");
        add_sysfs_tunable(_("NMI watchdog should be turned off"), 
"/proc/sys/kernel/nmi_watchdog", "0");
@@ -73,13 +76,16 @@ void initialize_tuning(void)
 
        sort_tunables();
 
+#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;
 
@@ -112,18 +118,21 @@ 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);
@@ -138,7 +147,7 @@ void tuning_window::cursor_enter(void)
                return;
        tun->toggle();
 }
-
+#endif // DISABLE_NCURSES
 
 static bool tunables_sort(class tunable * i, class tunable * j)
 {
@@ -168,14 +177,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) {
-- 
1.7.1

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

_______________________________________________
Power mailing list
[email protected]
https://bughost.org/mailman/listinfo/power

Reply via email to