expo: Split bootflow_menu_run() into two pieces
Split the starting piece of this function into bootflow_menu_start()
and the polling part into bootflow_menu_poll() so that it is possible
for the caller to be in control of the event loop.
Move the expo_destroy() call into the caller.
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/boot/bootflow_menu.c b/boot/bootflow_menu.c
index f9ebc52..ed7c076 100644
--- a/boot/bootflow_menu.c
+++ b/boot/bootflow_menu.c
@@ -175,20 +175,13 @@
return 0;
}
-int bootflow_menu_run(struct bootstd_priv *std, bool text_mode,
- struct bootflow **bflowp)
+int bootflow_menu_start(struct bootstd_priv *std, bool text_mode,
+ struct expo **expp)
{
- struct bootflow *sel_bflow;
struct udevice *dev;
- struct scene *scn;
struct expo *exp;
- uint sel_id;
- bool done;
int ret;
- sel_bflow = NULL;
- *bflowp = NULL;
-
ret = bootflow_menu_new(&exp);
if (ret)
return log_msg_ret("exp", ret);
@@ -210,58 +203,58 @@
ret = expo_set_scene_id(exp, MAIN);
if (ret)
return log_msg_ret("scn", ret);
- scn = expo_lookup_scene_id(exp, MAIN);
- if (!scn)
- return log_msg_ret("scn", -ENOENT);
if (text_mode)
expo_set_text_mode(exp, text_mode);
- done = false;
- do {
- struct expo_action act;
+ *expp = exp;
- ret = expo_poll(exp, &act);
- if (!ret) {
- switch (act.type) {
- case EXPOACT_SELECT:
- sel_id = act.select.id;
- done = true;
- break;
- case EXPOACT_POINT_ITEM:
- ret = scene_menu_select_item(scn,
- OBJ_MENU, act.select.id);
- if (ret)
- return log_msg_ret("bmp", ret);
- break;
- case EXPOACT_QUIT:
- return -EPIPE;
- default:
- break;
- }
- } else if (ret != -EPIPE && ret != -EAGAIN) {
- return log_msg_ret("bmr", ret);
- }
- } while (!done);
+ return 0;
+}
+
+int bootflow_menu_poll(struct expo *exp, struct bootflow **bflowp)
+{
+ struct bootflow *sel_bflow;
+ struct expo_action act;
+ int ret;
- if (sel_id) {
+ sel_bflow = NULL;
+ *bflowp = NULL;
+
+ ret = expo_poll(exp, &act);
+ if (ret)
+ return log_msg_ret("bmp", ret);
+
+ switch (act.type) {
+ case EXPOACT_SELECT: {
struct bootflow *bflow;
int i;
for (ret = bootflow_first_glob(&bflow), i = 0; !ret && i < 36;
ret = bootflow_next_glob(&bflow), i++) {
- if (i == sel_id - ITEM) {
- sel_bflow = bflow;
- break;
+ if (i == act.select.id - ITEM) {
+ *bflowp = bflow;
+ // printf("found %p\n", bflow);
+ return 0;
}
}
+ break;
}
+ case EXPOACT_POINT_ITEM: {
+ struct scene *scn = expo_lookup_scene_id(exp, MAIN);
- expo_destroy(exp);
-
- if (!sel_bflow)
- return -EAGAIN;
- *bflowp = sel_bflow;
+ if (!scn)
+ return log_msg_ret("bms", -ENOENT);
+ ret = scene_menu_select_item(scn, OBJ_MENU, act.select.id);
+ if (ret)
+ return log_msg_ret("bmp", ret);
+ break;
+ }
+ case EXPOACT_QUIT:
+ return -EPIPE;
+ default:
+ break;
+ }
- return 0;
+ return -EAGAIN;
}