diff mbox

[12/31] petitboot: Add CUI countdown timer

Message ID 20090708001135.743665318@am.sony.com
State New
Headers show

Commit Message

Geoff Levand July 8, 2009, 12:11 a.m. UTC
Add support for a petitboot CUI countdown timer.

Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
---
 ui/ncurses/nc-cui.c |   45 ++++++++++++++++++++++++++++++++++++++-------
 ui/ncurses/nc-cui.h |   14 +++++++++++++-
 2 files changed, 51 insertions(+), 8 deletions(-)
diff mbox

Patch

--- 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 <signal.h>
 
+#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