summaryrefslogtreecommitdiffstats
path: root/ui/ncurses/nc-cui.c
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2014-03-12 14:59:03 +0800
committerJeremy Kerr <jk@ozlabs.org>2014-04-10 11:18:24 +0800
commit1bbd230d618162ccd5ea97540a413c766a07c0cb (patch)
tree8bf596660165d015328d54930ba2f91ed4c4effd /ui/ncurses/nc-cui.c
parente07bd59ad5f4ba9cd113f8dfdcc72e6ca2e69819 (diff)
downloadtalos-petitboot-1bbd230d618162ccd5ea97540a413c766a07c0cb.tar.gz
talos-petitboot-1bbd230d618162ccd5ea97540a413c766a07c0cb.zip
ui/ncurses: Separate menu item creation & initialisation from insertion
Currently, the menu item creation is has two main functions: pmenu_item_alloc and pmenu_item_setup. The latter does initialisation (it sets item->name), and inserts the item into the menu. We have pmenu_item_init to combine this into one, but that means we need to do further initialisation (eg, to set on_execute) after the item has been added to the menu. Instead, this change use a more direct _create and _insert interface. Create does the allocation and initialisation, while _insert does the actual insertion. This means new_item failures will be detected at creation time, rather than during pmenu_insert. Also, we're now insert a completely-populated item into the menu, rather than populating on_edit, on_execute and data after insertion. Because we can detect errors from creation (ie, from new_item failing), we add handling code to cui_boot_option_add and cui_boot_editor_on_exit. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'ui/ncurses/nc-cui.c')
-rw-r--r--ui/ncurses/nc-cui.c55
1 files changed, 30 insertions, 25 deletions
diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c
index e8aaf9a..3a89869 100644
--- a/ui/ncurses/nc-cui.c
+++ b/ui/ncurses/nc-cui.c
@@ -175,22 +175,27 @@ static void cui_boot_editor_on_exit(struct cui *cui,
if (!item) {
int insert_pt;
+ cod = talloc_zero(NULL, struct cui_opt_data);
+ cod->name = talloc_asprintf(cod, "User item %u", ++user_idx);
+
+ item = pmenu_item_create(menu, cod->name);
+ if (!item) {
+ talloc_free(cod);
+ goto out;
+ }
+
+ item->on_edit = cui_item_edit;
+ item->on_execute = cui_boot;
+ item->data = cod;
+
+ talloc_steal(item, cod);
+
/* Detach the items array. */
set_menu_items(menu->ncm, NULL);
/* Insert new item at insert_pt. */
insert_pt = pmenu_grow(menu, 1);
- item = pmenu_item_alloc(menu);
- item->on_edit = cui_item_edit;
- item->on_execute = cui_boot;
- item->data = cod = talloc_zero(item, struct cui_opt_data);
-
- cod->name = talloc_asprintf(cod, "User item %u:", ++user_idx);
- if (pmenu_item_setup(menu, item, insert_pt,
- talloc_strdup(item, cod->name)) == NULL) {
- talloc_free(item);
- item = NULL;
- }
+ pmenu_item_insert(menu, item, insert_pt);
/* Re-attach the items array. */
set_menu_items(menu->ncm, menu->items);
@@ -201,8 +206,8 @@ static void cui_boot_editor_on_exit(struct cui *cui,
cod->bd = talloc_steal(cod, bd);
- if (item)
- set_current_item(item->pmenu->ncm, item->nci);
+ set_current_item(item->pmenu->ncm, item->nci);
+out:
cui_set_current(cui, &cui->main->scr);
talloc_free(cui->boot_editor);
cui->boot_editor = NULL;
@@ -407,19 +412,11 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt,
if (cui->current == &cui->main->scr)
nc_scr_unpost(cui->current);
- /* This disconnects items array from menu. */
-
- result = set_menu_items(cui->main->ncm, NULL);
-
- if (result)
- pb_log("%s: set_menu_items failed: %d\n", __func__, result);
-
- /* Insert new items at insert_pt. */
- insert_pt = pmenu_grow(cui->main, 1);
-
/* Save the item in opt->ui_info for cui_device_remove() */
- opt->ui_info = i = pmenu_item_alloc(cui->main);
+ opt->ui_info = i = pmenu_item_create(cui->main, opt->name);
+ if (!i)
+ return -1;
i->on_edit = cui_item_edit;
i->on_execute = cui_boot;
@@ -436,7 +433,15 @@ static int cui_boot_option_add(struct device *dev, struct boot_option *opt,
cod->bd->dtb = talloc_strdup(cod->bd, opt->dtb_file);
cod->bd->args = talloc_strdup(cod->bd, opt->boot_args);
- pmenu_item_setup(cui->main, i, insert_pt, cod->name);
+ /* This disconnects items array from menu. */
+ result = set_menu_items(cui->main->ncm, NULL);
+
+ if (result)
+ pb_log("%s: set_menu_items failed: %d\n", __func__, result);
+
+ /* Insert new items at insert_pt. */
+ insert_pt = pmenu_grow(cui->main, 1);
+ pmenu_item_insert(cui->main, i, insert_pt);
pb_log("%s: adding opt '%s'\n", __func__, cod->name);
pb_log(" image '%s'\n", cod->bd->image);
OpenPOWER on IntegriCloud