root/src/noit_console.h

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

refs #37... lots of progress here

  • 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 "utils/noit_skiplist.h"
15 #include <stdarg.h>
16
17 struct _console_state;
18 struct _console_state_stack;
19 struct __noit_console_closure;
20
21 typedef int (*console_cmd_func_t)(struct __noit_console_closure *,
22                                   int, char **,
23                                   struct _console_state *, void *);
24 typedef char * (*console_opt_func_t)(struct __noit_console_closure *,
25                                      struct _console_state_stack *stack,
26                                      struct _console_state *state,
27                                      int argc, char **argv,
28                                      int idx);
29 typedef char *(*console_prompt_func_t)(EditLine *);
30 typedef void (*state_free_func_t)(struct _console_state *);
31 typedef void (*state_userdata_free_func_t)(void *);
32
33 typedef struct {
34   const char            *name;
35   console_cmd_func_t     func;
36   console_opt_func_t     autocomplete;
37   struct _console_state *dstate;
38   void                  *closure;
39 } cmd_info_t;
40
41 /* This performs a pop (exiting if at toplevel) */
42 extern cmd_info_t console_command_exit;
43 extern cmd_info_t console_command_help;
44 extern cmd_info_t console_command_shutdown;
45 extern cmd_info_t console_command_restart;
46
47 typedef struct {
48   char                      *name;
49   void                      *data;
50   state_userdata_free_func_t freefunc;
51 } noit_console_userdata_t;
52
53 API_EXPORT(void)
54   noit_console_userdata_set(struct __noit_console_closure *,
55                             const char *name, void *data,
56                             state_userdata_free_func_t freefunc);
57 API_EXPORT(void *)
58   noit_console_userdata_get(struct __noit_console_closure *,
59                             const char *name);
60
61 typedef struct _console_state {
62   console_prompt_func_t      console_prompt_function;
63   /*noit_hash_table            cmds; */
64   noit_skiplist              cmds;
65   state_free_func_t          statefree;
66 } noit_console_state_t;
67
68 typedef struct _console_state_stack {
69   char *name;
70   noit_console_state_t *state;
71   void *userdata;
72   struct _console_state_stack *last;
73 } noit_console_state_stack_t;
74
75 typedef struct __noit_console_closure {
76   int initialized;
77   char feed_path[128];
78   eventer_t e;           /* The event it is attached to.  This
79                           * is needed so it can write itself out */
80   int   wants_shutdown;  /* Set this to 1 to have it die */
81
82   /* nice console support */
83   EditLine *el;
84   History *hist;
85   noit_hash_table userdata;
86   /* This is console completion magic */
87   int noit_edit_complete_cmdnum;
88   int rl_point;
89   int rl_end;
90
91   noit_console_state_stack_t *state_stack;
92
93   int   pty_master;
94   int   pty_slave;
95
96   /* Output buffer for non-blocking sends */
97   char *outbuf;
98   int   outbuf_allocd;
99   int   outbuf_len;
100   int   outbuf_cooked;
101   int   outbuf_completed;
102
103   /* This tracks telnet protocol state (if we're doing telnet) */
104   noit_console_telnet_closure_t telnet;
105   void (*output_cooker)(struct __noit_console_closure *);
106 } * noit_console_closure_t;
107
108 API_EXPORT(void) noit_console_init();
109
110 API_EXPORT(int)
111   noit_console_handler(eventer_t e, int mask, void *closure,
112                        struct timeval *now);
113
114
115 API_EXPORT(int)
116   nc_printf(noit_console_closure_t ncct, const char *fmt, ...);
117
118 API_EXPORT(int)
119   nc_vprintf(noit_console_closure_t ncct, const char *fmt, va_list arg);
120
121 API_EXPORT(int)
122   nc_write(noit_console_closure_t ncct, const void *buf, int len);
123
124 API_EXPORT(int)
125   noit_console_continue_sending(noit_console_closure_t ncct,
126                                 int *mask);
127
128 API_EXPORT(int)
129   noit_console_state_init(noit_console_closure_t ncct);
130
131 API_EXPORT(int)
132   noit_console_state_pop(noit_console_closure_t ncct, int argc, char **argv,
133                          noit_console_state_t *, void *);
134
135 API_EXPORT(int)
136   noit_console_help(noit_console_closure_t ncct, int argc, char **argv,
137                     noit_console_state_t *, void *);
138
139 API_EXPORT(int)
140   noit_console_shutdown(noit_console_closure_t ncct, int argc, char **argv,
141                         noit_console_state_t *, void *);
142
143 API_EXPORT(int)
144   noit_console_restart(noit_console_closure_t ncct, int argc, char **argv,
145                        noit_console_state_t *, void *);
146
147 API_EXPORT(int)
148   noit_console_state_add_cmd(noit_console_state_t *state,
149                              cmd_info_t *cmd);
150
151 API_EXPORT(cmd_info_t *)
152   noit_console_state_get_cmd(noit_console_state_t *state,
153                              const char *name);
154
155 API_EXPORT(noit_console_state_t *)
156   noit_console_state_build(console_prompt_func_t promptf, cmd_info_t **clist,
157                            state_free_func_t sfreef);
158
159 API_EXPORT(void)
160   noit_console_state_push_state(noit_console_closure_t ncct,
161                                 noit_console_state_t *);
162
163 API_EXPORT(noit_console_state_t *)
164   noit_console_state_initial();
165
166 API_EXPORT(noit_console_state_t *)
167   noit_console_state_alloc(void);
168
169 API_EXPORT(void)
170   noit_console_state_free(noit_console_state_t *st);
171
172 API_EXPORT(int)
173   noit_console_state_do(noit_console_closure_t ncct, int argc, char **argv);
174
175 API_EXPORT(int)
176   _noit_console_state_do(noit_console_closure_t ncct,
177                          noit_console_state_stack_t *stack,
178                          int argc, char **argv);
179
180 API_EXPORT(int)
181   noit_console_state_delegate(noit_console_closure_t ncct,
182                               int argc, char **argv,
183                               noit_console_state_t *dstate,
184                               void *closure);
185  
186 API_EXPORT(cmd_info_t *)
187   NCSCMD(const char *name, console_cmd_func_t func, console_opt_func_t ac,
188          noit_console_state_t *dstate, void *closure);
189
190 API_EXPORT(int)
191   noit_console_write_xml(void *vncct, const char *buffer, int len);
192
193 API_EXPORT(int)
194   noit_console_close_xml(void *vncct);
195
196 API_EXPORT(void)
197   noit_console_add_help(const char *topic, console_cmd_func_t topic_func,
198                         console_opt_func_t autocomplete);
199
200 API_EXPORT(unsigned char)
201   noit_edit_complete(EditLine *el, int invoking_key);
202
203 API_EXPORT(char *)
204   noit_console_opt_delegate(noit_console_closure_t ncct,
205                             noit_console_state_stack_t *stack,
206                             noit_console_state_t *state,
207                             int argc, char **argv,
208                             int idx);
209
210 #endif
Note: See TracBrowser for help on using the browser.