]> git.ozlabs.org Git - petitboot/blob - ui/ncurses/nc-cui.h
418df711204ea3f95ea176ba4b8f71c6263bc8cd
[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/joystick.h"
25 #include "nc-menu.h"
26 #include "nc-helpscreen.h"
27
28 struct cui_opt_data {
29         const char *name;
30         struct pb_boot_data *bd;
31
32         /* optional data */
33         const struct device *dev;
34         const struct boot_option *opt;
35         uint32_t opt_hash;
36 };
37
38 /**
39  * struct cui - Data structure defining a cui state machine.
40  * @c_sig: Signature for callback type checking, should be cui_sig.
41  * @abort: When set to true signals the state machine to exit.
42  * @current: Pointer to the active nc object.
43  * @main: Pointer to the user supplied main menu.
44  *
45  * Device boot_options are dynamically added and removed from the @main
46  * menu.
47  */
48
49 struct cui {
50         enum pb_nc_sig c_sig;
51         bool has_input;
52         sig_atomic_t abort;
53         sig_atomic_t resize;
54         struct nc_scr *current;
55         struct pmenu *main;
56         struct waitset *waitset;
57         struct discover_client *client;
58         struct system_info *sysinfo;
59         struct statuslog *statuslog;
60         struct sysinfo_screen *sysinfo_screen;
61         struct config *config;
62         struct config_screen *config_screen;
63         struct add_url_screen *add_url_screen;
64         struct boot_editor *boot_editor;
65         struct lang_screen *lang_screen;
66         struct help_screen *help_screen;
67         struct subset_screen *subset_screen;
68         struct statuslog_screen *statuslog_screen;
69         struct pjs *pjs;
70         void *platform_info;
71         unsigned int default_item;
72         int (*on_boot)(struct cui *cui, struct cui_opt_data *cod);
73 };
74
75 struct cui *cui_init(void* platform_info,
76                 int (*js_map)(const struct js_event *e),
77                 int start_daemon, int timeout);
78 struct nc_scr *cui_set_current(struct cui *cui, struct nc_scr *scr);
79 int cui_run(struct cui *cui);
80 void cui_item_edit(struct pmenu_item *item);
81 void cui_item_new(struct pmenu *menu);
82 void cui_show_sysinfo(struct cui *cui);
83 void cui_show_config(struct cui *cui);
84 void cui_show_lang(struct cui *cui);
85 void cui_show_statuslog(struct cui *cui);
86 void cui_show_help(struct cui *cui, const char *title,
87                 const struct help_text *text);
88 void cui_show_subset(struct cui *cui, const char *title,
89                 void *arg);
90 void cui_show_add_url(struct cui *cui);
91 int cui_send_config(struct cui *cui, struct config *config);
92 int cui_send_url(struct cui *cui, char *url);
93 void cui_send_reinit(struct cui *cui);
94
95 /* convenience routines */
96
97 void cui_abort(struct cui *cui);
98 void cui_resize(struct cui *cui);
99 void cui_on_exit(struct pmenu *menu);
100 void cui_on_open(struct pmenu *menu);
101 int cui_run_cmd(struct pmenu_item *item);
102
103 static inline struct cui *cui_from_arg(void *arg)
104 {
105         struct cui *cui = (struct cui *)arg;
106
107         assert(cui->c_sig == pb_cui_sig);
108         return cui;
109 }
110
111 static inline struct cui *cui_from_pmenu(struct pmenu *menu)
112 {
113         return cui_from_arg(menu->scr.ui_ctx);
114 }
115
116 static inline struct cui *cui_from_item(struct pmenu_item *item)
117 {
118         return cui_from_pmenu(item->pmenu);
119 }
120
121 #endif