BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
2 | * @file NCDInterpreter.h |
||
3 | * @author Ambroz Bizjak <ambrop7@gmail.com> |
||
4 | * |
||
5 | * @section LICENSE |
||
6 | * |
||
7 | * Redistribution and use in source and binary forms, with or without |
||
8 | * modification, are permitted provided that the following conditions are met: |
||
9 | * 1. Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * 2. Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * 3. Neither the name of the author nor the |
||
15 | * names of its contributors may be used to endorse or promote products |
||
16 | * derived from this software without specific prior written permission. |
||
17 | * |
||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||
19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | */ |
||
29 | |||
30 | #ifndef BADVPN_NCD_INTERPRETER_H |
||
31 | #define BADVPN_NCD_INTERPRETER_H |
||
32 | |||
33 | #include <stddef.h> |
||
34 | |||
35 | #include <misc/debug.h> |
||
36 | #include <base/DebugObject.h> |
||
37 | #include <system/BTime.h> |
||
38 | #include <system/BReactor.h> |
||
39 | #include <ncd/NCDStringIndex.h> |
||
40 | #include <ncd/NCDModuleIndex.h> |
||
41 | #include <ncd/NCDAst.h> |
||
42 | #include <ncd/NCDEvaluator.h> |
||
43 | #include <ncd/NCDInterpProg.h> |
||
44 | #include <ncd/NCDModule.h> |
||
45 | #include <structure/LinkedList1.h> |
||
46 | |||
47 | #ifndef BADVPN_NO_PROCESS |
||
48 | #include <system/BProcess.h> |
||
49 | #endif |
||
50 | #ifndef BADVPN_NO_UDEV |
||
51 | #include <udevmonitor/NCDUdevManager.h> |
||
52 | #endif |
||
53 | #ifndef BADVPN_NO_RANDOM |
||
54 | #include <random/BRandom2.h> |
||
55 | #endif |
||
56 | |||
57 | /** |
||
58 | * Handler called when the interpreter has terminated, and {@link NCDInterpreter_Free} |
||
59 | * can be called. |
||
60 | * |
||
61 | * @param user the user member of struct {@link NCDInterpreter_params} |
||
62 | * @param exit_code the exit code specified in the last interpreter termination request |
||
63 | */ |
||
64 | typedef void (*NCDInterpreter_handler_finished) (void *user, int exit_code); |
||
65 | |||
66 | struct NCDInterpreter_params { |
||
67 | // callbacks |
||
68 | NCDInterpreter_handler_finished handler_finished; |
||
69 | void *user; |
||
70 | |||
71 | // options |
||
72 | btime_t retry_time; |
||
73 | char **extra_args; |
||
74 | int num_extra_args; |
||
75 | |||
76 | // possibly shared resources |
||
77 | BReactor *reactor; |
||
78 | #ifndef BADVPN_NO_PROCESS |
||
79 | BProcessManager *manager; |
||
80 | #endif |
||
81 | #ifndef BADVPN_NO_UDEV |
||
82 | NCDUdevManager *umanager; |
||
83 | #endif |
||
84 | #ifndef BADVPN_NO_RANDOM |
||
85 | BRandom2 *random2; |
||
86 | #endif |
||
87 | }; |
||
88 | |||
89 | typedef struct { |
||
90 | // parameters |
||
91 | struct NCDInterpreter_params params; |
||
92 | |||
93 | // are we terminating |
||
94 | int terminating; |
||
95 | int main_exit_code; |
||
96 | |||
97 | // string index |
||
98 | NCDStringIndex string_index; |
||
99 | |||
100 | // module index |
||
101 | NCDModuleIndex mindex; |
||
102 | |||
103 | // program AST |
||
104 | NCDProgram program; |
||
105 | |||
106 | // expression evaluator |
||
107 | NCDEvaluator evaluator; |
||
108 | |||
109 | // structure for efficient interpretation |
||
110 | NCDInterpProg iprogram; |
||
111 | |||
112 | // common module parameters |
||
113 | struct NCDModuleInst_params module_params; |
||
114 | struct NCDModuleInst_iparams module_iparams; |
||
115 | struct NCDCall_interp_shared module_call_shared; |
||
116 | |||
117 | // processes |
||
118 | LinkedList1 processes; |
||
119 | |||
120 | DebugObject d_obj; |
||
121 | } NCDInterpreter; |
||
122 | |||
123 | /** |
||
124 | * Initializes and starts the interpreter. |
||
125 | * |
||
126 | * @param o the interpreter |
||
127 | * @param program the program to execute in AST format. The program must |
||
128 | * not contain any 'include' or 'include_guard' directives. |
||
129 | * The interpreter takes ownership of the program, regardless |
||
130 | * of the success of this function. |
||
131 | * @param params other parameters |
||
132 | * @return 1 on success, 0 on failure |
||
133 | */ |
||
134 | int NCDInterpreter_Init (NCDInterpreter *o, NCDProgram program, struct NCDInterpreter_params params) WARN_UNUSED; |
||
135 | |||
136 | /** |
||
137 | * Frees the interpreter. |
||
138 | * This may only be called after the interpreter has terminated, i.e. |
||
139 | * the {@link NCDInterpreter_handler_finished} handler has been called. |
||
140 | * Additionally, it can be called right after {@link NCDInterpreter_Init} |
||
141 | * before any of the interpreter's {@link BPendingGroup} jobs have executed. |
||
142 | */ |
||
143 | void NCDInterpreter_Free (NCDInterpreter *o); |
||
144 | |||
145 | /** |
||
146 | * Requests termination of the interpreter. |
||
147 | * NOTE: the program can request its own termination, possibly overriding the exit |
||
148 | * code specified here. Expect the program to terminate even if this function was |
||
149 | * not called. |
||
150 | * |
||
151 | * @param o the interpreter |
||
152 | * @param exit_code the exit code to be passed to {@link NCDInterpreter_handler_finished}. |
||
153 | * This overrides any exit code set previously. |
||
154 | */ |
||
155 | void NCDInterpreter_RequestShutdown (NCDInterpreter *o, int exit_code); |
||
156 | |||
157 | #endif |