From patchwork Wed Jun 15 13:50:36 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 1924 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id D9ECE23DE6 for ; Wed, 15 Jun 2011 13:52:40 +0000 (UTC) Received: from mail-vw0-f52.google.com (mail-vw0-f52.google.com [209.85.212.52]) by fiordland.canonical.com (Postfix) with ESMTP id 919C9A180BB for ; Wed, 15 Jun 2011 13:52:40 +0000 (UTC) Received: by vws16 with SMTP id 16so416308vws.11 for ; Wed, 15 Jun 2011 06:52:40 -0700 (PDT) Received: by 10.52.75.4 with SMTP id y4mr790474vdv.167.1308145960032; Wed, 15 Jun 2011 06:52:40 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs126626vdc; Wed, 15 Jun 2011 06:52:39 -0700 (PDT) Received: by 10.227.11.148 with SMTP id t20mr613695wbt.98.1308145956574; Wed, 15 Jun 2011 06:52:36 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp05.smtpout.orange.fr [80.12.242.127]) by mx.google.com with ESMTP id fs11si1384290wbb.63.2011.06.15.06.52.36; Wed, 15 Jun 2011 06:52:36 -0700 (PDT) Received-SPF: neutral (google.com: 80.12.242.127 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=80.12.242.127; Authentication-Results: mx.google.com; spf=neutral (google.com: 80.12.242.127 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: from monster.dhcp.lxc ([92.134.76.78]) by mwinf5d28 with ME id wDsa1g00D1hMfSL03DsbAi; Wed, 15 Jun 2011 15:52:35 +0200 From: Daniel Lezcano To: daniel.lezcano@linaro.org Cc: linaro-dev@lists.linaro.org, patches@linaro.org Subject: [powerdebug 02/22] make all pm block own their display data Date: Wed, 15 Jun 2011 15:50:36 +0200 Message-Id: <1308145856-6112-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1308145856-6112-1-git-send-email-daniel.lezcano@linaro.org> References: <1308145856-6112-1-git-send-email-daniel.lezcano@linaro.org> That allows to keep track of the different selections from the different windows. Signed-off-by: Daniel Lezcano --- clocks.c | 20 ++++++------ display.c | 96 ++++++++++++++++++++++++++++++++++++---------------------- powerdebug.c | 4 +- powerdebug.h | 18 +++++----- 4 files changed, 81 insertions(+), 57 deletions(-) diff --git a/clocks.c b/clocks.c index 4d78910..c86a39e 100644 --- a/clocks.c +++ b/clocks.c @@ -163,15 +163,15 @@ void find_parents_for_clock(char *clkname, int complete) strcat(name, clkname); sprintf(str, "Enter Clock Name : %s\n", name); - display_reset_cursor(); - display_print_line(0, str, 1, NULL); - display_refresh_pad(); + display_reset_cursor(CLOCK); + display_print_line(CLOCK, 0, str, 1, NULL); + display_refresh_pad(CLOCK); return; } sprintf(name, "Parents for \"%s\" Clock : \n", clkname); - display_reset_cursor(); - display_print_line(0, name, 1, NULL); - display_refresh_pad(); + display_reset_cursor(CLOCK); + display_print_line(CLOCK, 0, name, 1, NULL); + display_refresh_pad(CLOCK); dump_all_parents(clkname); } @@ -271,7 +271,7 @@ static int clock_print_info_cb(struct tree *t, void *data) if (!buffer) return -1; - display_print_line(*line, buffer, clock->usecount, t); + display_print_line(CLOCK, *line, buffer, clock->usecount, t); (*line)++; @@ -286,18 +286,18 @@ static int clock_print_info(void) print_clock_header(); - display_reset_cursor(); + display_reset_cursor(CLOCK); ret = tree_for_each(clock_tree, clock_print_info_cb, &line); - display_refresh_pad(); + display_refresh_pad(CLOCK); return ret; } int clock_toggle_expanded(void) { - struct tree *t = display_get_row_data(); + struct tree *t = display_get_row_data(CLOCK); struct clock_info *clk = t->private; clk->expanded = !clk->expanded; diff --git a/display.c b/display.c index 98dc955..8712023 100644 --- a/display.c +++ b/display.c @@ -44,21 +44,24 @@ static const int maxrows = 1024; static char footer_items[NUM_FOOTER_ITEMS][64]; -static char *win_names[TOTAL_FEATURE_WINS] = { - "Clocks", - "Regulators", - "Sensors" -}; - struct rowdata { int attr; void *data; }; -static struct rowdata *rowdata; -static int nrdata; -static int scrolling; -static int cursor; +struct windata { + struct rowdata *rowdata; + char *name; + int nrdata; + int scrolling; + int cursor; +}; + +struct windata windata[TOTAL_FEATURE_WINS] = { + { .name = "Clocks" }, + { .name = "Regulators" }, + { .name = "Sensors" }, +}; static void display_fini(void) { @@ -170,8 +173,8 @@ void show_header(int selectedwindow) else wattroff(header_win, A_REVERSE); - print(header_win, curr_pointer, 0, " %s ", win_names[i]); - curr_pointer += strlen(win_names[i]) + 2; + print(header_win, curr_pointer, 0, " %s ", windata[i].name); + curr_pointer += strlen(windata[i].name) + 2; } wrefresh(header_win); werase(footer_win); @@ -274,69 +277,74 @@ void print_sensor_header(void) wrefresh(sensor_win); } -int display_refresh_pad(void) +int display_refresh_pad(int win) { - return prefresh(clock_pad, scrolling, 0, 2, 0, maxy - 2, maxx); + return prefresh(clock_pad, windata[win].scrolling, + 0, 2, 0, maxy - 2, maxx); } -static int inline display_clock_un_select(int line, bool highlight, bool bold) +static int inline display_clock_un_select(int win, int line, + bool highlight, bool bold) { if (mvwchgat(clock_pad, line, 0, -1, highlight ? WA_STANDOUT : bold ? WA_BOLD: WA_NORMAL, 0, NULL) < 0) return -1; - return display_refresh_pad(); + return display_refresh_pad(win); } -int display_clock_select(int line) +int display_select(int win, int line) { - return display_clock_un_select(line, true, false); + return display_clock_un_select(win, line, true, false); } -int display_clock_unselect(int line, bool bold) +int display_unselect(int win, int line, bool bold) { - return display_clock_un_select(line, false, bold); + return display_clock_un_select(win, line, false, bold); } -void *display_get_row_data(void) +void *display_get_row_data(int win) { - return rowdata[cursor].data; + return windata[win].rowdata[windata[win].cursor].data; } -int display_set_row_data(int line, void *data, int attr) +int display_set_row_data(int win, int line, void *data, int attr) { - if (line >= nrdata) { + struct rowdata *rowdata = windata[win].rowdata; + + if (line >= windata[win].nrdata) { rowdata = realloc(rowdata, sizeof(struct rowdata) * (line + 1)); if (!rowdata) return -1; - nrdata = line + 1; + windata[win].nrdata = line + 1; } rowdata[line].data = data; rowdata[line].attr = attr; + windata[win].rowdata = rowdata; return 0; } -int display_reset_cursor(void) +int display_reset_cursor(win) { - nrdata = 0; + windata[win].nrdata = 0; werase(clock_pad); return wmove(clock_pad, 0, 0); } -int display_print_line(int line, char *str, int bold, void *data) +int display_print_line(int win, int line, char *str, int bold, void *data) { int attr = 0; if (bold) attr |= WA_BOLD; - if (line == cursor) + if (line == windata[win].cursor) attr |= WA_STANDOUT; - if (display_set_row_data(line, data, attr)) + if (display_set_row_data(win, line, data, attr)) return -1; if (attr) @@ -350,34 +358,50 @@ int display_print_line(int line, char *str, int bold, void *data) return 0; } -int display_next_line(void) +int display_next_line(int win) { + int cursor = windata[win].cursor; + int nrdata = windata[win].nrdata; + int scrolling = windata[win].scrolling; + struct rowdata *rowdata = windata[win].rowdata; + if (cursor >= nrdata) return cursor; - display_clock_unselect(cursor, rowdata[cursor].attr); + display_unselect(win, cursor, rowdata[cursor].attr); if (cursor < nrdata - 1) { if (cursor >= (maxy - 4 + scrolling)) scrolling++; cursor++; } - display_clock_select(cursor); + display_select(win, cursor); + + windata[win].scrolling = scrolling; + windata[win].cursor = cursor; return cursor; } -int display_prev_line(void) +int display_prev_line(int win) { + int cursor = windata[win].cursor; + int nrdata = windata[win].nrdata; + int scrolling = windata[win].scrolling; + struct rowdata *rowdata = windata[win].rowdata; + if (cursor >= nrdata) return cursor; - display_clock_unselect(cursor, rowdata[cursor].attr); + display_unselect(win, cursor, rowdata[cursor].attr); if (cursor > 0) { if (cursor <= scrolling) scrolling--; cursor--; } - display_clock_select(cursor); + display_select(win, cursor); + + windata[win].scrolling = scrolling; + windata[win].cursor = cursor; return cursor; } diff --git a/powerdebug.c b/powerdebug.c index 1873b1b..3a2edac 100644 --- a/powerdebug.c +++ b/powerdebug.c @@ -177,12 +177,12 @@ int keystroke_callback(bool *enter_hit, bool *findparent_ncurses, if (options->selectedwindow == CLOCK) { if (keystroke == KEY_DOWN) { - display_next_line(); + display_next_line(CLOCK); *cont = true; } if (keystroke == KEY_UP) { - display_prev_line(); + display_prev_line(CLOCK); *cont = true; } diff --git a/powerdebug.h b/powerdebug.h index 502dcaa..8fd2775 100644 --- a/powerdebug.h +++ b/powerdebug.h @@ -35,18 +35,18 @@ extern int print_clock_info(int hrow, int selected); extern void print_string_val(char *name, char *val); extern void print_clock_header(void); -extern int display_print_line(int line, char *str, int bold, void *data); +extern int display_print_line(int window, int line, char *str, + int bold, void *data); -extern int display_refresh_pad(void); -extern int display_reset_cursor(void); -extern int display_next_line(void); -extern int display_prev_line(void); - -extern void *display_get_row_data(void); +extern int display_refresh_pad(int window); +extern int display_reset_cursor(int window); +extern int display_next_line(int window); +extern int display_prev_line(int window); +extern void *display_get_row_data(int window); extern int clock_toggle_expanded(void); -extern int display_clock_select(int line); -extern int display_clock_unselect(int line, bool bold); +extern int display_clock_select(int window, int line); +extern int display_clock_unselect(int window, int line, bool bold); extern void get_sensor_info(char *path, char *name, char *sensor, int verbose); extern int read_and_print_sensor_info(int verbose);