root/src/noit_console.h

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

closes #48

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