fsp: Fixed a serious bug.
[elinks.git] / src / main / module.h
blob3b56e40bdde1fdb74c1b1a02302a168012a2f375
1 #ifndef EL__MAIN_MODULE_H
2 #define EL__MAIN_MODULE_H
4 #include "config/options.h"
5 #include "main/event.h"
7 /* The module record */
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;
14 /* The options that should be registered for this module.
15 * The table should end with NULL_OPTION_INFO. */
16 struct option_info *options;
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;
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;
28 /* User data for the module. Undefined purpose. */
29 void *data;
31 /* Lifecycle functions */
33 /* This function should initialize the module. */
34 void (*init)(struct module *module);
36 /* This function should shutdown the module. */
37 void (*done)(struct module *module);
40 #define struct_module(name, options, hooks, submods, data, init, done) \
41 { name, options, hooks, submods, data, init, done }
43 #define foreach_module(module, modules, i) \
44 for (i = 0, module = modules ? modules[i] : NULL; \
45 module; \
46 i++, module = modules[i])
48 /* The module table has to be NULL terminates */
49 static inline int
50 sizeof_modules(struct module **modules)
52 struct module *module;
53 int i;
55 foreach_module (module, modules, i) {
56 ; /* m33p */
59 return i - 1;
62 #define foreachback_module(module, modules, i) \
63 for (i = sizeof_modules(modules); \
64 i >= 0 && (module = modules[i]); \
65 i--)
67 /* Interface for handling single modules */
69 void register_module_options(struct module *module);
70 void unregister_module_options(struct module *module);
72 void init_module(struct module *module);
73 void done_module(struct module *module);
75 /* Interface for handling builtin modules */
77 /* Builtin modules are initialised only when not connecting to a master
78 * terminal. */
79 extern struct module *builtin_modules[];
81 /* Main modules are initialised earlier and are not listed in Help -> About. */
82 extern struct module *main_modules[];
84 void register_modules_options(struct module *modules[]);
85 void unregister_modules_options(struct module *modules[]);
87 void init_modules(struct module *modules[]);
88 void done_modules(struct module *modules[]);
90 #endif