root/src/noit_console.h

Revision 71803743714376fc12fb54b3506df6a4c17a8828, 5.1 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 10 years ago)

oh my word... basic function, refs #49

  • 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   char feed_path[128];
69   eventer_t e;           /* The event it is attached to.  This
70                           * is needed so it can write itself out */
71   int   wants_shutdown;  /* Set this to 1 to have it die */
72
73   /* nice console support */
74   EditLine *el;
75   History *hist;
76   noit_hash_table userdata;
77
78   noit_console_state_stack_t *state_stack;
79
80   int   pty_master;
81   int   pty_slave;
82
83   /* Output buffer for non-blocking sends */
84   char *outbuf;
85   int   outbuf_allocd;
86   int   outbuf_len;
87   int   outbuf_cooked;
88   int   outbuf_completed;
89
90   /* This tracks telnet protocol state (if we're doing telnet) */
91   noit_console_telnet_closure_t telnet;
92   void (*output_cooker)(struct __noit_console_closure *);
93 } * noit_console_closure_t;
94
95 API_EXPORT(void) noit_console_init();
96
97 API_EXPORT(int)
98   noit_console_handler(eventer_t e, int mask, void *closure,
99                        struct timeval *now);
100
101
102 API_EXPORT(int)
103   nc_printf(noit_console_closure_t ncct, const char *fmt, ...);
104
105 API_EXPORT(int)
106   nc_vprintf(noit_console_closure_t ncct, const char *fmt, va_list arg);
107
108 API_EXPORT(int)
109   nc_write(noit_console_closure_t ncct, const void *buf, int len);
110
111 API_EXPORT(int)
112   noit_console_continue_sending(noit_console_closure_t ncct,
113                                 int *mask);
114
115 API_EXPORT(int)
116   noit_console_state_init(noit_console_closure_t ncct);
117
118 API_EXPORT(int)
119   noit_console_state_pop(noit_console_closure_t ncct, int argc, char **argv,
120                          noit_console_state_t *, void *);
121
122 API_EXPORT(int)
123   noit_console_shutdown(noit_console_closure_t ncct, int argc, char **argv,
124                         noit_console_state_t *, void *);
125
126 API_EXPORT(int)
127   noit_console_restart(noit_console_closure_t ncct, int argc, char **argv,
128                        noit_console_state_t *, void *);
129
130 API_EXPORT(int)
131   noit_console_state_add_cmd(noit_console_state_t *state,
132                              cmd_info_t *cmd);
133
134 API_EXPORT(cmd_info_t *)
135   noit_console_state_get_cmd(noit_console_state_t *state,
136                              const char *name);
137
138 API_EXPORT(noit_console_state_t *)
139   noit_console_state_build(console_prompt_func_t promptf, cmd_info_t **clist,
140                            state_free_func_t sfreef);
141
142 API_EXPORT(void)
143   noit_console_state_push_state(noit_console_closure_t ncct,
144                                 noit_console_state_t *);
145
146 API_EXPORT(noit_console_state_t *)
147   noit_console_state_initial();
148
149 API_EXPORT(noit_console_state_t *)
150   noit_console_state_alloc(void);
151
152 API_EXPORT(void)
153   noit_console_state_free(noit_console_state_t *st);
154
155 API_EXPORT(int)
156   noit_console_state_do(noit_console_closure_t ncct, int argc, char **argv);
157
158 API_EXPORT(int)
159   _noit_console_state_do(noit_console_closure_t ncct,
160                          noit_console_state_stack_t *stack,
161                          int argc, char **argv);
162
163 API_EXPORT(int)
164   noit_console_state_delegate(noit_console_closure_t ncct,
165                               int argc, char **argv,
166                               noit_console_state_t *dstate,
167                               void *closure);
168  
169 API_EXPORT(cmd_info_t *)
170   NCSCMD(const char *name, console_cmd_func_t func,
171          noit_console_state_t *dstate, void *closure);
172
173 #endif
Note: See TracBrowser for help on using the browser.