root/src/noit_console.h

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

pull help and docs into the console, refs #21

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