From patchwork Mon Jun 20 22:58:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 2103 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 1BDAF23E54 for ; Mon, 20 Jun 2011 22:59:01 +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 DFE62A1805E for ; Mon, 20 Jun 2011 22:59:00 +0000 (UTC) Received: by mail-vw0-f52.google.com with SMTP id 16so4124077vws.11 for ; Mon, 20 Jun 2011 15:59:00 -0700 (PDT) Received: by 10.52.98.97 with SMTP id eh1mr8205058vdb.7.1308610735430; Mon, 20 Jun 2011 15:58:55 -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 em2cs32804vdc; Mon, 20 Jun 2011 15:58:55 -0700 (PDT) Received: by 10.227.132.210 with SMTP id c18mr5614665wbt.44.1308610733435; Mon, 20 Jun 2011 15:58:53 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp03.smtpout.orange.fr [80.12.242.125]) by mx.google.com with ESMTP id et14si10255588wbb.108.2011.06.20.15.58.52; Mon, 20 Jun 2011 15:58:53 -0700 (PDT) Received-SPF: neutral (google.com: 80.12.242.125 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=80.12.242.125; Authentication-Results: mx.google.com; spf=neutral (google.com: 80.12.242.125 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.95.191]) by mwinf5d06 with ME id yNyp1g00347kPVY03NysCw; Tue, 21 Jun 2011 00:58:52 +0200 From: Daniel Lezcano To: linaro-dev@lists.linaro.org Subject: [powerdebug 06/17] Factor out display code Date: Tue, 21 Jun 2011 00:58:14 +0200 Message-Id: <1308610705-23281-6-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1308610705-23281-1-git-send-email-daniel.lezcano@linaro.org> References: <1308610705-23281-1-git-send-email-daniel.lezcano@linaro.org> Signed-off-by: Daniel Lezcano --- clocks.c | 20 ++++++++++++++++++-- display.c | 40 +++------------------------------------- display.h | 6 +----- regulator.c | 20 +++++++++++++++++++- sensor.c | 17 ++++++++++++++++- 5 files changed, 57 insertions(+), 46 deletions(-) diff --git a/clocks.c b/clocks.c index 684bf88..411fcb2 100644 --- a/clocks.c +++ b/clocks.c @@ -286,14 +286,30 @@ static int clock_print_info_cb(struct tree *t, void *data) return 0; } +static int clock_print_header(void) +{ + char *buf; + int ret; + + if (asprintf(&buf, "%-55s %-16s %-12s %-9s %-8s", + "Name", "Flags", "Rate", "Usecount", "Children") < 0) + return -1; + + ret = display_header_footer(CLOCK, buf); + + free(buf); + + return ret; +} + static int clock_print_info(void) { int ret, line = 0; - print_clock_header(); - display_reset_cursor(CLOCK); + clock_print_header(); + ret = tree_for_each(clock_tree, clock_print_info_cb, &line); display_refresh_pad(CLOCK); diff --git a/display.c b/display.c index bd5971a..d32783f 100644 --- a/display.c +++ b/display.c @@ -375,49 +375,15 @@ int display_init(int wdefault) return display_refresh(wdefault); } -void print_regulator_header(void) +int display_header_footer(int win, const char *line) { werase(main_win); wattron(main_win, A_BOLD); - mvwprintw(main_win, 0, 0, "Name"); - mvwprintw(main_win, 0, 12, "Status"); - mvwprintw(main_win, 0, 24, "State"); - mvwprintw(main_win, 0, 36, "Type"); - mvwprintw(main_win, 0, 48, "Users"); - mvwprintw(main_win, 0, 60, "Microvolts"); - mvwprintw(main_win, 0, 72, "Min u-volts"); - mvwprintw(main_win, 0, 84, "Max u-volts"); + mvwprintw(main_win, 0, 0, "%s", line); wattroff(main_win, A_BOLD); wrefresh(main_win); - show_header_footer(REGULATOR); -} - -void print_clock_header(void) -{ - werase(main_win); - wattron(main_win, A_BOLD); - mvwprintw(main_win, 0, 0, "Name"); - mvwprintw(main_win, 0, 56, "Flags"); - mvwprintw(main_win, 0, 75, "Rate"); - mvwprintw(main_win, 0, 88, "Usecount"); - mvwprintw(main_win, 0, 98, "Children"); - wattroff(main_win, A_BOLD); - wrefresh(main_win); - - show_header_footer(CLOCK); -} - -void print_sensor_header(void) -{ - werase(main_win); - wattron(main_win, A_BOLD); - mvwprintw(main_win, 0, 0, "Name"); - mvwprintw(main_win, 0, 36, "Value"); - wattroff(main_win, A_BOLD); - wrefresh(main_win); - - show_header_footer(SENSOR); + return show_header_footer(win); } int display_register(int win, struct display_ops *ops) diff --git a/display.h b/display.h index 749d8a3..8586f5e 100644 --- a/display.h +++ b/display.h @@ -29,9 +29,5 @@ extern void *display_get_row_data(int window); extern int display_init(int wdefault); extern int display_register(int win, struct display_ops *ops); +extern int display_header_footer(int win, const char *line); extern int display_refresh(int win); - -/* FIXME */ -extern void print_sensor_header(void); -extern void print_clock_header(void); -extern void print_regulator_header(void); diff --git a/regulator.c b/regulator.c index 696ed10..4151fdb 100644 --- a/regulator.c +++ b/regulator.c @@ -138,13 +138,31 @@ static int regulator_display_cb(struct tree *t, void *data) return 0; } +static int regulator_print_header(void) +{ + char *buf; + int ret; + + if (asprintf(&buf, "%-11s %-11s %-11s %-11s %-11s %-11s %-11s %-12s", + "Name", "Status", "State", "Type", "Users", "Microvolts", + "Min u-volts", "Max u-volts") < 0) + return -1; + + ret = display_header_footer(REGULATOR, buf); + + free(buf); + + return ret; + +} + int regulator_display(void) { int ret, line = 0; display_reset_cursor(REGULATOR); - print_regulator_header(); + regulator_print_header(); ret = tree_for_each(reg_tree, regulator_display_cb, &line); diff --git a/sensor.c b/sensor.c index db58137..20602c0 100644 --- a/sensor.c +++ b/sensor.c @@ -235,13 +235,28 @@ static int sensor_display_cb(struct tree *t, void *data) return 0; } +static int sensor_print_header(void) +{ + char *buf; + int ret; + + if (asprintf(&buf, "%-36s%s", "Name", "Value") < 0) + return -1; + + ret = display_header_footer(SENSOR, buf); + + free(buf); + + return ret; +} + int sensor_display(void) { int ret, line = 0; display_reset_cursor(SENSOR); - print_sensor_header(); + sensor_print_header(); ret = tree_for_each(sensor_tree, sensor_display_cb, &line);