|
1 #ifndef CONSOLE_H |
|
2 #define CONSOLE_H |
|
3 |
|
4 /** |
|
5 * @file |
|
6 * |
|
7 * An interactive line-based console interface for runtime configuration. |
|
8 * |
|
9 * This uses the GNU readline library to implement the console, and hence, the console uses global state, and there |
|
10 * can only be one console per process - not that it should matter, since the console requires a tty. |
|
11 * |
|
12 * XXX: the log module interferes with this |
|
13 */ |
|
14 #include "error.h" |
|
15 #include <event2/event.h> |
|
16 #include <stdbool.h> |
|
17 |
|
18 /** |
|
19 * Callbacks for event-based actions |
|
20 */ |
|
21 struct console_callbacks { |
|
22 /** A line was read from the console */ |
|
23 void (*on_line) (char *line, void *arg); |
|
24 }; |
|
25 |
|
26 /** |
|
27 * Configuration info for console operation |
|
28 */ |
|
29 struct console_config { |
|
30 /** The prompt to use when displaying lines */ |
|
31 const char *prompt; |
|
32 }; |
|
33 |
|
34 /** |
|
35 * The console state... |
|
36 */ |
|
37 struct console { |
|
38 /** The input event */ |
|
39 struct event *ev; |
|
40 |
|
41 /** The callback functions */ |
|
42 const struct console_callbacks *callbacks; |
|
43 |
|
44 /** The callback context argument */ |
|
45 void *cb_arg; |
|
46 |
|
47 /** Already initialized? */ |
|
48 bool initialized; |
|
49 }; |
|
50 |
|
51 /** |
|
52 * Initialize the console, setting up the TTY and input handler |
|
53 */ |
|
54 err_t console_init (struct console **console_ptr, struct event_base *ev_base, const struct console_config *config, |
|
55 const struct console_callbacks *callbacks, void *cb_arg, struct error_info *err); |
|
56 |
|
57 /** |
|
58 * Deinitialize the console, restoring the TTY and releasing resources |
|
59 */ |
|
60 void console_destroy (struct console *console); |
|
61 |
|
62 #endif /* CONSOLE_H */ |