root/src/noit_console.h

Revision a7f575acc420cc6e5ca474d23cf07149299a3bbd, 2.6 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 6 years ago)

start the framework for a console state machine

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  */
5
6 #ifndef _NOIT_CONSOLE_H
7 #define _NOIT_CONSOLE_H
8
9 #include "noit_defines.h"
10 #include "eventer/eventer.h"
11 #include "noitedit/histedit.h"
12 #include "noit_console_telnet.h"
13 #include "utils/noit_hash.h"
14 #include <stdarg.h>
15
16 struct _console_state;
17 struct __noit_console_closure;
18
19 typedef int (*console_cmd_func_t)(struct __noit_console_closure *,
20                                   int, char **);
21 typedef char *(*console_prompt_func_t)(EditLine *);
22 typedef void (*state_free_func_t)(struct _console_state *);
23
24 typedef struct cmd_info {
25   const char          *name;
26   console_cmd_func_t   func;
27 } cmd_info_t;
28
29 typedef struct _console_state {
30   console_prompt_func_t  console_prompt_function;
31   noit_hash_table        cmds;
32   struct _console_state *stacked;
33   state_free_func_t      statefree;
34 } noit_console_state_t;
35
36 typedef struct __noit_console_closure {
37   eventer_t e;           /* The event it is attached to.  This
38                           * is needed so it can write itself out */
39   int   wants_shutdown;  /* Set this to 1 to have it die */
40
41   /* nice console support */
42   EditLine *el;
43   History *hist;
44
45   noit_console_state_t *state;
46
47   int   pty_master;
48   int   pty_slave;
49
50   /* Output buffer for non-blocking sends */
51   char *outbuf;
52   int   outbuf_allocd;
53   int   outbuf_len;
54   int   outbuf_cooked;
55   int   outbuf_completed;
56
57   /* This tracks telnet protocol state (if we're doing telnet) */
58   noit_console_telnet_closure_t telnet;
59   void (*output_cooker)(struct __noit_console_closure *);
60 } * noit_console_closure_t;
61
62 API_EXPORT(void) noit_console_init();
63
64 API_EXPORT(int)
65   noit_console_handler(eventer_t e, int mask, void *closure,
66                        struct timeval *now);
67
68
69 API_EXPORT(int)
70   nc_printf(noit_console_closure_t ncct, const char *fmt, ...);
71
72 API_EXPORT(int)
73   nc_vprintf(noit_console_closure_t ncct, const char *fmt, va_list arg);
74
75 API_EXPORT(int)
76   nc_write(noit_console_closure_t ncct, void *buf, int len);
77
78 API_EXPORT(int)
79   noit_console_continue_sending(noit_console_closure_t ncct,
80                                 int *mask);
81
82 API_EXPORT(int)
83   noit_console_state_init(noit_console_closure_t ncct);
84
85 API_EXPORT(char *)
86   noit_console_state_prompt(EditLine *el);
87
88 API_EXPORT(int)
89   noit_console_state_pop(noit_console_closure_t ncct, int argc, char **argv);
90
91 API_EXPORT(noit_console_state_t *)
92   noit_console_state_initial();
93
94 API_EXPORT(void)
95   noit_console_state_free(noit_console_state_t *st);
96
97 API_EXPORT(int)
98   noit_console_state_do(noit_console_closure_t ncct, int argc, char **argv);
99
100 #endif
Note: See TracBrowser for help on using the browser.