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