src/console.h
changeset 93 42ade8285570
parent 92 99661e5aac91
child 137 c607c357c486
equal deleted inserted replaced
92:99661e5aac91 93:42ade8285570
    17 
    17 
    18 /**
    18 /**
    19  * Callbacks for event-based actions
    19  * Callbacks for event-based actions
    20  */
    20  */
    21 struct console_callbacks {
    21 struct console_callbacks {
    22     /** A line was read from the console */
    22     /**
    23     void (*on_line) (char *line, void *arg);
    23      * A line was read from the console. 
       
    24      *
       
    25      * XXX: currently, line might be NULL on EOF, but this is probably a second callback
       
    26      */
       
    27     void (*on_line) (const char *line, void *arg);
    24 };
    28 };
    25 
    29 
    26 /**
    30 /**
    27  * Configuration info for console operation
    31  * Configuration info for console operation
    28  */
    32  */
    30     /** The prompt to use when displaying lines */
    34     /** The prompt to use when displaying lines */
    31     const char *prompt;
    35     const char *prompt;
    32 };
    36 };
    33 
    37 
    34 /**
    38 /**
    35  * The console state...
    39  * The console state.
       
    40  *
       
    41  * You may replace the callbacks/cb_arg field with a new one at any time, using console_set_callbacks().
    36  */
    42  */
    37 struct console {
    43 struct console {
    38     /** The input event */
    44     /** The input event */
    39     struct event *ev;
    45     struct event *ev;
    40 
    46 
    47     /** Already initialized? */
    53     /** Already initialized? */
    48     bool initialized;
    54     bool initialized;
    49 };
    55 };
    50 
    56 
    51 /**
    57 /**
    52  * Initialize the console, setting up the TTY and input handler
    58  * Initialize the console, setting up the TTY and input handler.
       
    59  *
       
    60  * @param console_ptr returned new console struct
       
    61  * @param ev_base the libevent base to use
       
    62  * @param config configuration things for the console
       
    63  * @param callbacks optional callbacks, can be updated later
       
    64  * @param cb_arg option callback argument, can be updated later
       
    65  * @param err returned error info
    53  */
    66  */
    54 err_t console_init (struct console **console_ptr, struct event_base *ev_base, const struct console_config *config,
    67 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);
    68         const struct console_callbacks *callbacks, void *cb_arg, struct error_info *err);
       
    69 
       
    70 /**
       
    71  * Replace the current callbacks with the given new ones.
       
    72  */
       
    73 void console_set_callbacks (struct console *console, const struct console_callbacks *callbacks, void *cb_arg);
    56 
    74 
    57 /**
    75 /**
    58  * Deinitialize the console, restoring the TTY and releasing resources
    76  * Deinitialize the console, restoring the TTY and releasing resources
    59  */
    77  */
    60 void console_destroy (struct console *console);
    78 void console_destroy (struct console *console);