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