]> git.ozlabs.org Git - petitboot/commitdiff
ui/ncurses: Add cancel-default reporting
authorJeremy Kerr <jk@ozlabs.org>
Tue, 21 May 2013 06:26:12 +0000 (14:26 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Mon, 24 Jun 2013 04:52:50 +0000 (12:52 +0800)
When we first see key input, we can tell the discover server to cancel
the default boot.

Untested on ps3.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
ui/ncurses/generic-main.c
ui/ncurses/nc-cui.c
ui/ncurses/nc-cui.h
ui/ncurses/ps3-main.c

index 560e3e5683e9b32b9ee9c965a4df01e32580a458..6280a341987617a45c6d869beb0c935191a7944e 100644 (file)
@@ -259,7 +259,6 @@ int main(int argc, char *argv[])
                return EXIT_FAILURE;
 
        pb.mm = pb_mm_init(&pb);
-       ui_timer_disable(&pb.cui->timer);
 
        cui_result = cui_run(pb.cui, pb.mm, 0);
 
index bd4f6b8ae84a175699d9f312555bdd23f2c11205..82e534db817e4f5f8e6252b25bb20fe5731d6658 100644 (file)
@@ -222,7 +222,10 @@ static int cui_process_key(void *arg)
 
        assert(cui->current);
 
-       ui_timer_disable(&cui->timer);
+       if (!cui->has_input)
+               discover_client_cancel_default(cui->client);
+       cui->has_input = true;
+
        for (;;) {
                int c = getch();
 
@@ -257,24 +260,6 @@ static int cui_process_js(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.
  */
@@ -399,12 +384,6 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt,
        pb_log("   initrd '%s'\n", cod->bd->initrd);
        pb_log("   args   '%s'\n", cod->bd->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. */
        result = set_menu_items(cui->main->ncm, cui->main->items);
 
@@ -459,11 +438,6 @@ static void cui_device_remove(struct device *dev, void *arg)
 
                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. */
@@ -527,7 +501,6 @@ struct cui *cui_init(void* platform_info,
 
        cui->c_sig = pb_cui_sig;
        cui->platform_info = platform_info;
-       cui->timer.handle_timeout = cui_handle_timeout;
        cui->waitset = waitset_create(cui);
 
        /* Loop here for scripts that just started the server. */
index 69c15d46e03518d7e88a6ffa1675fd03fd6f9b63..a5ac5d5f427e7aee92ffbd86d8fa72de44f4c5a3 100644 (file)
@@ -22,7 +22,6 @@
 #include <signal.h>
 
 #include "ui/common/joystick.h"
-#include "ui/common/timer.h"
 #include "nc-menu.h"
 #include "nc-boot-editor.h"
 
@@ -49,11 +48,11 @@ struct cui_opt_data {
 
 struct cui {
        enum pb_nc_sig c_sig;
+       bool has_input;
        sig_atomic_t abort;
        sig_atomic_t resize;
        struct nc_scr *current;
        struct pmenu *main;
-       struct ui_timer timer;
        struct waitset *waitset;
        struct discover_client *client;
        struct pjs *pjs;
@@ -94,15 +93,4 @@ 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
index 3b9fab167af22e444e4a3f67e1fc68240dbea32e..57350556dc9489539c72490300a1a853ab269840 100644 (file)
@@ -70,7 +70,6 @@ struct opts {
        enum opt_value show_help;
        const char *log_file;
        enum opt_value reset_defaults;
-       enum opt_value use_timeout;
        enum opt_value show_version;
 };
 
@@ -84,11 +83,10 @@ static int opts_parse(struct opts *opts, int argc, char *argv[])
                {"help",           no_argument,       NULL, 'h'},
                {"log",            required_argument, NULL, 'l'},
                {"reset-defaults", no_argument,       NULL, 'r'},
-               {"timeout",        no_argument,       NULL, 't'},
                {"version",        no_argument,       NULL, 'V'},
                { NULL, 0, NULL, 0},
        };
-       static const char short_options[] = "hl:trV";
+       static const char short_options[] = "hl:rV";
        static const struct opts default_values = {
                .log_file = "/var/log/petitboot/petitboot-nc.log",
        };
@@ -109,9 +107,6 @@ static int opts_parse(struct opts *opts, int argc, char *argv[])
                case 'l':
                        opts->log_file = optarg;
                        break;
-               case 't':
-                       opts->use_timeout = opt_yes;
-                       break;
                case 'r':
                        opts->reset_defaults = opt_yes;
                        break;
@@ -398,21 +393,6 @@ static int ps3_hot_key(struct pmenu __attribute__((unused)) *menu,
        return c;
 }
 
-/**
- * ps3_timer_update - Timer callback.
- */
-
-static void ps3_timer_update(struct ui_timer *timer, unsigned int timeout)
-{
-       struct ps3_cui *ps3 = ps3_from_cui(cui_from_timer(timer));
-
-       //FIXME: make scr:timer.
-       // nc_scr_timer_update(&ps3.mm->scr, timeout);
-
-       nc_scr_status_printf(&ps3->mm->scr,
-               "Welcome to Petitboot (timeout %u sec)", timeout);
-}
-
 /**
  * ps3_mm_init - Setup the main menu instance.
  */
@@ -566,10 +546,6 @@ static void sig_handler(int signum)
        DBGS("%d\n", signum);
 
        switch (signum) {
-       case SIGALRM:
-               if (ps3.cui)
-                       ui_timer_sigalrm(&ps3.cui->timer);
-               break;
        case SIGWINCH:
                if (ps3.cui)
                        cui_resize(ps3.cui);
@@ -666,14 +642,6 @@ int main(int argc, char *argv[])
        ps3.mm = ps3_mm_init(&ps3);
        ps3.svm = ps3_svm_init(&ps3);
 
-       if (opts.use_timeout != opt_yes
-               || ps3.values.timeout == ps3_timeout_forever)
-               ui_timer_disable(&ps3.cui->timer);
-       else {
-               ps3.cui->timer.update_display = ps3_timer_update;
-               ui_timer_init(&ps3.cui->timer, ps3.values.timeout);
-       }
-
        cui_result = cui_run(ps3.cui, ps3.mm, ps3.values.default_item);
 
        pmenu_delete(ps3.mm);