root/src/noit_console.h

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

userdata for states, track a path and prompt

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