Add CUI countdown timer
authorGeoff Levand <geoffrey.levand@am.sony.com>
Thu, 9 Jul 2009 17:40:44 +0000 (10:40 -0700)
committerGeoff Levand <geoffrey.levand@am.sony.com>
Thu, 9 Jul 2009 17:40:44 +0000 (10:40 -0700)
Add support for a petitboot CUI countdown timer.

Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
ui/ncurses/nc-cui.c
ui/ncurses/nc-cui.h

index 2b059eb96b240a146667d686876322ccc18d2b4a..47c09e2e73e1326d43d39c354af81135bc9635b4 100644 (file)
@@ -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;
 }
 
@@ -221,6 +223,24 @@ static int cui_client_process_socket(void *arg)
        return 0;
 }
 
+/**
+ * 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 *dev, void *arg)
 
                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 device *dev, void *arg)
 
        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 pmenu *main, unsigned int default_item)
                if (cui->abort)
                        break;
 
+               ui_timer_process_sig(&cui->timer);
+
                while (cui->resize) {
                        cui->resize = 0;
                        cui_handle_resize(cui);
index 668776ebfc5ecbfd003e9991dce51448ce719594..79c41a4ec90b4d243150838ca0689771790c5327 100644 (file)
 
 #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(struct pmenu_item *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