ekg2
GIT master
Strona główna
Dodatkowe strony
Moduły
Struktury Danych
Pliki
Lista plików
Globalne
All
Struktury Danych
Pliki
Funkcje
Zmienne
Definicje typów
Wyliczenia
Wartości wyliczeń
Definicje
Grupay
Strony
ekg
scripts.h
Idź do dokumentacji tego pliku.
1
#ifndef EKG_SCRIPTS_H
2
#define EKG_SCRIPTS_H
3
#include <sys/types.h>
4
5
#include "
commands.h
"
6
#include "
plugins.h
"
7
#include "
protocol.h
"
8
#include "
stuff.h
"
9
#include "
vars.h
"
10
#include "
queries.h
"
11
12
#ifdef __cplusplus
13
extern
"C"
{
14
#endif
15
16
#define SCRIPT_HANDLE_UNBIND -666
17
#define MAX_ARGS QUERY_ARGS_MAX+1
18
19
typedef
enum
{
20
SCRIPT_UNKNOWNTYPE
,
21
SCRIPT_VARTYPE
,
22
SCRIPT_COMMANDTYPE
,
23
SCRIPT_QUERYTYPE
,
24
SCRIPT_TIMERTYPE
,
25
SCRIPT_WATCHTYPE
,
26
SCRIPT_PLUGINTYPE
,
27
}
script_type_t
;
28
29
typedef
struct
script
{
30
struct
script
*
next
;
31
32
void
*
lang
;
33
char
*
name
;
34
char
*
path
;
35
void
*
priv_data
;
36
int
inited
;
37
}
script_t
;
38
extern
script_t
*
scripts
;
39
40
typedef
struct
{
41
script_t
*
scr
;
42
ekg_timer_t
self
;
43
int
removed
;
44
void
*
priv_data
;
45
}
script_timer_t
;
46
47
typedef
struct
{
48
script_t
*
scr
;
49
plugin_t
*
self
;
50
void
*
priv_data
;
51
}
script_plugin_t
;
52
53
typedef
struct
{
54
script_t
*
scr
;
55
variable_t
*
self
;
56
57
char
*
name
;
58
char
*
value
;
59
void
*
priv_data
;
60
}
script_var_t
;
61
62
typedef
struct
{
63
script_t
*
scr
;
64
query_t
*
self
;
65
int
argc
;
66
int
argv_type[
MAX_ARGS
];
67
68
int
real_argc
;
69
void
*
priv_data
;
70
int
hack
;
71
}
script_query_t
;
72
73
typedef
struct
{
74
script_t
*
scr
;
75
command_t
*
self
;
76
void
*
priv_data
;
77
}
script_command_t
;
78
79
typedef
struct
{
80
script_t
*
scr
;
81
watch_t
*
self
;
82
int
removed
;
83
void
*
data
;
84
void
*
priv_data
;
85
}
script_watch_t
;
86
87
typedef
int (
scriptlang_initialize_t
)();
88
typedef
int (
scriptlang_finalize_t
)();
89
typedef
int (
script_load_t
)(
script_t
*);
90
typedef
int (
script_unload_t
)(
script_t
*);
91
typedef
int (
script_handler_command_t
)(
script_t
*,
script_command_t
*,
char
**);
92
typedef
int (
script_handler_timer_t
) (script_t *,
script_timer_t
*, int);
93
typedef
int (
script_handler_var_t
) (script_t *,
script_var_t
*,
char
*);
94
typedef
int (
script_handler_query_t
) (script_t *,
script_query_t
*,
void
**);
95
typedef
int (
script_handler_watch_t
) (script_t *,
script_watch_t
*, int, int, int);
96
97
typedef
int (
script_free_bind_t
) (script_t *,
void
*, int,
void
*, ...);
98
99
typedef
struct
scriptlang
{
100
struct
scriptlang
*
next
;
101
102
char
*
name
;
/* perl, python, php *g* and so on. */
103
char
*
ext
;
/* .pl, .py, .php ... */
104
plugin_t
*
plugin
;
105
106
scriptlang_initialize_t
*
init
;
107
scriptlang_finalize_t
*
deinit
;
108
109
script_load_t
*
script_load
;
110
script_unload_t
*
script_unload
;
111
script_free_bind_t
*
script_free_bind
;
112
113
script_handler_query_t
*
script_handler_query
;
114
script_handler_command_t
*
script_handler_command
;
115
script_handler_timer_t
*
script_handler_timer
;
116
script_handler_var_t
*
script_handler_var
;
117
script_handler_watch_t
*
script_handler_watch
;
118
119
void
*
priv_data
;
120
}
scriptlang_t
;
121
extern
scriptlang_t
*
scriptlang
;
122
123
#define SCRIPT_FINDER(bool)\
124
script_t *scr = NULL;\
125
scriptlang_t *slang = NULL;\
126
\
127
for (scr = scripts; scr; scr = scr->next) {\
128
slang = scr->lang;\
129
if (bool)\
130
return scr;\
131
}\
132
return NULL;
133
134
/* XXX: Split *_watches() into normal and line-ones.
135
*
136
* Until then we abort the build if sizeof(void*) > sizeof(long int), as
137
* in that case the pointer would get corrupted when being passed around
138
* as a long using type-punning.
139
*
140
* This trick was stolen from the Linux kernel. See
141
* http://scaryreasoner.wordpress.com/2009/02/28/checking-sizeof-at-compile-time/
142
* for an explanation.
143
*/
144
#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
145
146
#define SCRIPT_DEFINE(x, y)\
147
extern int x##_load(script_t *);\
148
extern int x##_unload(script_t *);\
149
\
150
extern int x##_commands(script_t *, script_command_t *, char **);\
151
extern int x##_timers(script_t *, script_timer_t *, int );\
152
extern int x##_variable_changed(script_t *, script_var_t *, char *);\
153
extern int x##_query(script_t *, script_query_t *, void **);\
154
extern int x##_watches(script_t *, script_watch_t *, int, int, long int);\
155
void x##_dummy_sanity_check() { BUILD_BUG_ON(sizeof(void *) > sizeof(long)); };\
156
\
157
extern int x##_bind_free(script_t *, void *, int type, void *, ...);\
158
\
159
scriptlang_t x##_lang = { \
160
name: #x, \
161
plugin: &x##_plugin, \
162
ext: y, \
163
\
164
init: x##_initialize,\
165
deinit: x##_finalize, \
166
\
167
script_load: x##_load, \
168
script_unload: x##_unload, \
169
script_free_bind: x##_bind_free,\
170
\
171
script_handler_query : x##_query,\
172
script_handler_command: x##_commands,\
173
script_handler_timer : x##_timers,\
174
script_handler_var : x##_variable_changed,\
175
script_handler_watch : x##_watches,\
176
}
177
178
#define script_private_get(s) (s->priv_data)
179
#define script_private_set(s, p) (s->priv_data = p)
180
181
#ifndef EKG2_WIN32_NOFUNCTION
182
int
script_unload_lang
(
scriptlang_t
*s);
183
184
int
script_list
(
scriptlang_t
*s);
185
int
script_unload_name
(
scriptlang_t
*s,
char
*
name
);
186
int
script_load
(
scriptlang_t
*s,
char
*
name
);
187
188
int
scriptlang_register
(
scriptlang_t
*s);
189
int
scriptlang_unregister
(
scriptlang_t
*s);
190
191
int
scripts_init
();
192
193
script_t *
script_find
(
scriptlang_t
*s,
char
*
name
);
194
195
int
script_query_unbind
(script_query_t *squery,
int
from);
196
int
script_command_unbind
(script_command_t *scr_comm,
int
free);
197
int
script_timer_unbind
(script_timer_t *stimer,
int
free);
198
int
script_var_unbind
(script_var_t *data,
int
free);
199
int
script_watch_unbind
(script_watch_t *temp,
int
free);
200
201
script_command_t *
script_command_bind
(
scriptlang_t
*s, script_t *scr,
char
*
command
,
char
*
params
,
char
*possibilities,
void
*
handler
);
202
script_timer_t *
script_timer_bind
(
scriptlang_t
*s, script_t *scr,
int
freq,
void
*
handler
);
203
script_query_t *
script_query_bind
(
scriptlang_t
*s, script_t *scr,
char
*qname,
void
*
handler
);
204
script_var_t *
script_var_add_full
(
scriptlang_t
*s, script_t *scr,
char
*
name
,
int
type,
char
*value,
void
*
handler
);
205
script_var_t *
script_var_add
(
scriptlang_t
*s, script_t *scr,
char
*
name
,
char
*value,
void
*
handler
);
206
script_watch_t *
script_watch_add
(
scriptlang_t
*s, script_t *scr,
int
fd,
int
type,
void
*
handler
,
void
*data);
207
script_plugin_t
*
script_plugin_init
(
scriptlang_t
*s, script_t *scr,
char
*
name
,
plugin_class_t
pclass,
void
*
handler
);
208
209
void
script_variables_free
();
210
void
script_variables_write
();
211
#endif
212
213
#define SCRIPT_UNBIND_HANDLER(type, args...) \
214
{\
215
SCRIPT_HANDLER_HEADER(script_free_bind_t);\
216
SCRIPT_HANDLER_FOOTER(script_free_bind, type, temp->priv_data, args);\
217
}
218
219
/* BINDING && UNBINDING */
220
221
#define SCRIPT_BIND_HEADER(x) \
222
x *temp; \
223
if (scr && scr->inited != 1) {\
224
debug_error("[script_bind_error] script not inited!\n"); \
225
return NULL; \
226
} \
227
temp = xmalloc(sizeof(x)); \
228
temp->scr = scr;\
229
temp->priv_data = handler;
230
231
#define SCRIPT_BIND_FOOTER(y) \
232
if (!temp->self) {\
233
debug("[script_bind_error] (before adding to %s) ERROR! retcode = 0x%x\n", #y, temp->self);\
234
xfree(temp);\
235
return NULL;\
236
}\
237
list_add(&y, temp);\
238
return temp;
239
240
/* HANDLERS */
241
#define SCRIPT_HANDLER_HEADER(x) \
242
script_t *_scr;\
243
scriptlang_t *_slang;\
244
x *_handler;\
245
int ret = SCRIPT_HANDLE_UNBIND;
246
247
/* TODO: quietmode */
248
#define SCRIPT_HANDLER_FOOTER(y, _args...) \
249
if ((_scr = temp->scr) && ((_slang = _scr->lang))) _handler = _slang->y;\
250
else _handler = temp->priv_data;\
251
if (_handler)\
252
ret = _handler(_scr, temp, _args); \
253
else {\
254
debug("[%s] (_handler == NULL)\n", #y);\
255
ret = SCRIPT_HANDLE_UNBIND;\
256
}\
257
\
258
if (ret == SCRIPT_HANDLE_UNBIND) { debug("[%s] script or scriptlang want to delete this handler\n", #y); }\
259
if (ret == SCRIPT_HANDLE_UNBIND)
260
261
#define SCRIPT_HANDLER_MULTI_FOOTER(y, _args...)\
262
/* foreach y->list->next do SCRIPT_HANDLER_FOOTER(y->list->data, _args); */
\
263
SCRIPT_HANDLER_FOOTER(y, _args)
264
265
#ifdef __cplusplus
266
}
267
#endif
268
269
#endif
Wygenerowano Wt, 29 paź 2013 20:17:04 dla ekg2 programem
1.8.4