imported.
[silc.git] / apps / irssi / src / core / modules.h
1 #ifndef __MODULES_H
2 #define __MODULES_H
3
4 #define MODULE_DATA_INIT(rec) \
5         (rec)->module_data = g_hash_table_new(g_str_hash, g_str_equal)
6
7 #define MODULE_DATA_DEINIT(rec) \
8         g_hash_table_destroy((rec)->module_data)
9
10 #define MODULE_DATA_SET(rec, data) \
11         g_hash_table_insert((rec)->module_data, MODULE_NAME, data)
12
13 #define MODULE_DATA(rec) \
14         g_hash_table_lookup((rec)->module_data, MODULE_NAME)
15
16 enum {
17         MODULE_ERROR_ALREADY_LOADED,
18         MODULE_ERROR_LOAD,
19         MODULE_ERROR_INVALID
20 };
21
22 typedef struct {
23         char *name;
24 #ifdef HAVE_GMODULE
25         GModule *gmodule;
26 #endif
27 } MODULE_REC;
28
29 extern GSList *modules;
30
31 MODULE_REC *module_find(const char *name);
32
33 /* Load module - automatically tries to load also the related non-core
34    modules given in `prefixes' (like irc, fe, fe_text, ..) */
35 int module_load(const char *path, char **prefixes);
36 void module_unload(MODULE_REC *module);
37
38 #define MODULE_CHECK_CAST(object, cast, type_field, id) \
39         ((cast *) module_check_cast(object, offsetof(cast, type_field), id))
40 #define MODULE_CHECK_CAST_MODULE(object, cast, type_field, module, id) \
41         ((cast *) module_check_cast_module(object, \
42                                 offsetof(cast, type_field), module, id))
43 void *module_check_cast(void *object, int type_pos, const char *id);
44 void *module_check_cast_module(void *object, int type_pos,
45                                const char *module, const char *id);
46
47 /* return unique number across all modules for `id' */
48 int module_get_uniq_id(const char *module, int id);
49 /* return unique number across all modules for `id'. */
50 int module_get_uniq_id_str(const char *module, const char *id);
51
52 /* returns the original module specific id, -1 = not found */
53 int module_find_id(const char *module, int uniqid);
54 /* returns the original module specific id, NULL = not found */
55 const char *module_find_id_str(const char *module, int uniqid);
56
57 /* Destroy unique IDs from `module'. This function is automatically called
58    when module is destroyed with module's name as the parameter. */
59 void module_uniq_destroy(const char *module);
60
61 void modules_init(void);
62 void modules_deinit(void);
63
64 #endif