root/src/noit_console.h

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

delegate hooking into the configuration system to other modules

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