From patchwork Wed Jul 8 00:11:46 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 29555 Return-Path: X-Original-To: patchwork-incoming@bilbo.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (ozlabs.org [203.10.76.45]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mx.ozlabs.org", Issuer "CA Cert Signing Authority" (verified OK)) by bilbo.ozlabs.org (Postfix) with ESMTPS id 78CEBB709E for ; Wed, 8 Jul 2009 10:20:59 +1000 (EST) Received: by ozlabs.org (Postfix) id 7B997DE6C3; Wed, 8 Jul 2009 10:19:46 +1000 (EST) Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 736DFDE6C2 for ; Wed, 8 Jul 2009 10:19:46 +1000 (EST) X-Original-To: cbe-oss-dev@ozlabs.org Delivered-To: cbe-oss-dev@ozlabs.org Received: from hera.kernel.org (hera.kernel.org [140.211.167.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CD14ADDF85; Wed, 8 Jul 2009 10:18:15 +1000 (EST) Received: from hera.kernel.org (IDENT:U2FsdGVkX18EXpz+c+DybGmtiaxGM3E4J2izTZeUAb0@localhost [127.0.0.1]) by hera.kernel.org (8.14.2/8.14.2) with ESMTP id n680I8ZK026574 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 8 Jul 2009 00:18:08 GMT Received: (from geoff@localhost) by hera.kernel.org (8.14.2/8.13.1/Submit) id n680I7Et026573; Wed, 8 Jul 2009 00:18:07 GMT Message-Id: <20090708001135.743665318@am.sony.com> User-Agent: quilt/0.47-1 Date: Tue, 07 Jul 2009 17:11:46 -0700 From: Geoff Levand To: Jeremy Kerr In-Reply-To: <20090708001134.934244536@am.sony.com> References: <20090708001134.934244536@am.sony.com> Content-Disposition: inline; filename=nc-timer.diff X-Virus-Scanned: ClamAV 0.93.3/9541/Tue Jul 7 17:31:53 2009 on hera.kernel.org X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on hera.kernel.org X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0 (hera.kernel.org [127.0.0.1]); Wed, 08 Jul 2009 00:18:08 +0000 (UTC) Cc: cbe-oss-dev@ozlabs.org Subject: [Cbe-oss-dev] [patch 12/31] petitboot: Add CUI countdown timer X-BeenThere: cbe-oss-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Discussion about Open Source Software for the Cell Broadband Engine List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Add support for a petitboot CUI countdown timer. Signed-off-by: Geoff Levand --- ui/ncurses/nc-cui.c | 45 ++++++++++++++++++++++++++++++++++++++------- ui/ncurses/nc-cui.h | 14 +++++++++++++- 2 files changed, 51 insertions(+), 8 deletions(-) --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -30,7 +30,6 @@ #include "ui/common/discover-client.h" #include "nc-cui.h" - static struct cui_opt_data *cod_from_item(struct pmenu_item *item) { return item->data; @@ -205,7 +204,10 @@ static int cui_process_key(void *arg) struct cui *cui = cui_from_arg(arg); assert(cui->current); + + ui_timer_disable(&cui->timer); cui->current->process_key(cui->current); + return 0; } @@ -222,6 +224,24 @@ static int cui_client_process_socket(voi } /** + * cui_handle_timeout - Handle the timeout. + */ + +static void cui_handle_timeout(struct ui_timer *timer) +{ + struct cui *cui = cui_from_timer(timer); + struct pmenu_item *i = pmenu_find_selected(cui->main); + +#if defined(DEBUG) + { + struct cui_opt_data *cod = cod_from_item(i); + assert(cod && (cod->opt_hash == cui->default_item)); + } +#endif + i->on_execute(i); +} + +/** * cui_handle_resize - Handle the term resize. */ @@ -320,15 +340,17 @@ static int cui_device_add(struct device insert_pt++; - /* If this is the default_item select it. */ - - if (cod->opt_hash == cui->default_item) - selected = i->nci; - pb_log("%s: adding opt '%s'\n", __func__, cod->opt->name); pb_log(" image '%s'\n", cod->kd->image); pb_log(" initrd '%s'\n", cod->kd->initrd); pb_log(" args '%s'\n", cod->kd->args); + + /* If this is the default_item select it and start timer. */ + + if (cod->opt_hash == cui->default_item) { + selected = i->nci; + ui_timer_kick(&cui->timer); + } } /* Re-attach the items array. */ @@ -379,9 +401,15 @@ static void cui_device_remove(struct dev list_for_each_entry(&dev->boot_options, opt, list) { struct pmenu_item *i = pmenu_item_from_arg(opt->ui_info); + struct cui_opt_data *cod = cod_from_item(i); - assert(pb_protocol_device_cmp(dev, cod_from_item(i)->dev)); + assert(pb_protocol_device_cmp(dev, cod->dev)); pmenu_remove(cui->main, i); + + /* If this is the default_item disable timer. */ + + if (cod->opt_hash == cui->default_item) + ui_timer_disable(&cui->timer); } /* Re-attach the items array. */ @@ -434,6 +462,7 @@ struct cui *cui_init(void* platform_info cui->c_sig = pb_cui_sig; cui->platform_info = platform_info; cui->on_kexec = on_kexec; + cui->timer.handle_timeout = cui_handle_timeout; /* Loop here for scripts that just started the server. */ @@ -501,6 +530,8 @@ int cui_run(struct cui *cui, struct pmen if (cui->abort) break; + ui_timer_process_sig(&cui->timer); + while (cui->resize) { cui->resize = 0; cui_handle_resize(cui); --- a/ui/ncurses/nc-cui.h +++ b/ui/ncurses/nc-cui.h @@ -21,10 +21,10 @@ #include +#include "ui/common/timer.h" #include "nc-menu.h" #include "nc-ked.h" - struct cui_opt_data { const struct device *dev; const struct boot_option *opt; @@ -49,6 +49,7 @@ struct cui { sig_atomic_t resize; struct nc_scr *current; struct pmenu *main; + struct ui_timer timer; void *platform_info; unsigned int default_item; int (*on_kexec)(struct cui *cui, struct cui_opt_data *cod); @@ -85,4 +86,15 @@ static inline struct cui *cui_from_item( return cui_from_pmenu(item->pmenu); } +static inline struct cui *cui_from_timer(struct ui_timer *timer) +{ + struct cui *cui; + + cui = (struct cui *)((char *)timer + - (size_t)&((struct cui *)0)->timer); + assert(cui->c_sig == pb_cui_sig); + + return cui; +} + #endif