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