1 #ifndef EL__MAIN_MODULE_H
2 #define EL__MAIN_MODULE_H
3
4 #include "config/options.h"
5 #include "main/event.h"
6
7 /* The module record */
8
9 struct module {
10 /* The name of the module. It needs to be unique in its class (ie. in
11 * the scope of root modules or submodules of one parent module). */
12 unsigned char *name;
13
14 /* The options that should be registered for this module.
15 * The table should end with NULL_OPTION_INFO. */
16 struct option_info *options;
17
18 /* The event hooks that should be registered for this module.
19 * The table should end with NULL_EVENT_HOOK_INFO. */
20 struct event_hook_info *hooks;
21
22 /* Any submodules that this module contains. Order matters
23 * since it is garanteed that initialization will happen in
24 * the specified order and teardown in the reverse order.
25 * The table should end with NULL. */
26 struct module **submodules;
27
28 /* User data for the module. Undefined purpose. */
29 void *data;
30
31 /* Lifecycle functions */
32
33 /* This function should initialize the module. */
34 void (*init)(struct module *module);
35
36 /* This function should shutdown the module. */
37 void (*done)(struct module *module);
38 };
39
40 #define struct_module(name, options, hooks, submods, data, init, done) \
41 { name, options, hooks, submods, data, init, done }
42
43 #define foreach_module(module, modules, i) \
44 for (i = 0, module = modules ? modules[i] : NULL; \
45 module; \
46 i++, module = modules[i])
47
48 /* The module table has to be NULL terminates */
49 static inline int
sizeof_modules(struct module ** modules)50 sizeof_modules(struct module **modules)
51 {
52 struct module *module;
53 int i;
54
55 foreach_module (module, modules, i) {
56 ; /* m33p */
57 }
58
59 return i - 1;
60 }
61
62 #define foreachback_module(module, modules, i) \
63 for (i = sizeof_modules(modules); \
64 i >= 0 && (module = modules[i]); \
65 i--)
66
67 /* Interface for handling single modules */
68
69 void register_module_options(struct module *module);
70 void unregister_module_options(struct module *module);
71
72 void init_module(struct module *module);
73 void done_module(struct module *module);
74
75 /* Interface for handling builtin modules */
76
77 extern struct module *builtin_modules[];
78 extern struct module *main_modules[];
79
80 void register_modules_options(struct module *modules[]);
81 void unregister_modules_options(struct module *modules[]);
82
83 void init_modules(struct module *modules[]);
84 void done_modules(struct module *modules[]);
85
86 #endif
87