]> git.ozlabs.org Git - petitboot/blob - ui/ncurses/nc-cui.h
Add PS3 reset default option
[petitboot] / ui / ncurses / nc-cui.h
1 /*
2  *  Copyright (C) 2009 Sony Computer Entertainment Inc.
3  *  Copyright 2009 Sony Corp.
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; version 2 of the License.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #if !defined(_PB_NC_CUI_H)
20 #define _PB_NC_CUI_H
21
22 #include <signal.h>
23
24 #include "ui/common/timer.h"
25 #include "nc-menu.h"
26 #include "nc-ked.h"
27
28 struct cui_opt_data {
29         const struct device *dev;
30         const struct boot_option *opt;
31         uint32_t opt_hash;
32         struct pb_kexec_data *kd;
33 };
34
35 /**
36  * struct cui - Data structure defining a cui state machine.
37  * @c_sig: Signature for callback type checking, should be cui_sig.
38  * @abort: When set to true signals the state machine to exit.
39  * @current: Pointer to the active nc object.
40  * @main: Pointer to the user supplied main menu.
41  *
42  * Device boot_options are dynamically added and removed from the @main
43  * menu.
44  */
45
46 struct cui {
47         enum pb_nc_sig c_sig;
48         sig_atomic_t abort;
49         sig_atomic_t resize;
50         struct nc_scr *current;
51         struct pmenu *main;
52         struct ui_timer timer;
53         void *platform_info;
54         unsigned int default_item;
55         int (*on_kexec)(struct cui *cui, struct cui_opt_data *cod);
56 };
57
58 struct cui *cui_init(void* platform_info,
59         int (*on_kexec)(struct cui *, struct cui_opt_data *));
60 struct nc_scr *cui_set_current(struct cui *cui, struct nc_scr *scr);
61 int cui_run(struct cui *cui, struct pmenu *main, unsigned int default_item);
62 int cui_ked_run(struct pmenu_item *item);
63
64 /* convenience routines */
65
66 void cui_abort(struct cui *cui);
67 void cui_resize(struct cui *cui);
68 void cui_on_exit(struct pmenu *menu);
69 int cui_run_cmd(struct pmenu_item *item);
70
71 static inline struct cui *cui_from_arg(void *arg)
72 {
73         struct cui *cui = (struct cui *)arg;
74
75         assert(cui->c_sig == pb_cui_sig);
76         return cui;
77 }
78
79 static inline struct cui *cui_from_pmenu(struct pmenu *menu)
80 {
81         return cui_from_arg(menu->scr.ui_ctx);
82 }
83
84 static inline struct cui *cui_from_item(struct pmenu_item *item)
85 {
86         return cui_from_pmenu(item->pmenu);
87 }
88
89 static inline struct cui *cui_from_timer(struct ui_timer *timer)
90 {
91         struct cui *cui;
92
93         cui = (struct cui *)((char *)timer
94                 - (size_t)&((struct cui *)0)->timer);
95         assert(cui->c_sig == pb_cui_sig);
96
97         return cui;
98 }
99
100 #endif