Added SILC Thread Queue API
[crypto.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_UNSET(rec) \
14         g_hash_table_remove((rec)->module_data, MODULE_NAME)
15
16 #define MODULE_DATA(rec) \
17         g_hash_table_lookup((rec)->module_data, MODULE_NAME)
18
19
20 #ifdef HAVE_GMODULE
21 #  define MODULE_IS_STATIC(rec) \
22         ((rec)->gmodule == NULL)
23 #else
24 #  define MODULE_IS_STATIC(rec) TRUE
25 #endif
26
27 enum {
28         MODULE_ERROR_ALREADY_LOADED,
29         MODULE_ERROR_LOAD,
30         MODULE_ERROR_INVALID
31 };
32
33 typedef struct _MODULE_REC MODULE_REC;
34
35 typedef struct {
36         MODULE_REC *root;
37         char *name;
38         char *defined_module_name;
39         void (*module_deinit) (void);
40
41 #ifdef HAVE_GMODULE
42         GModule *gmodule; /* static, if NULL */
43 #endif
44         unsigned int initialized:1;
45 } MODULE_FILE_REC;
46
47 struct _MODULE_REC {
48         char *name;
49         GSList *files; /* list of modules that belong to this root module */
50 };
51
52 extern GSList *modules;
53
54 /* Register a new module. The `name' is the root module name, `submodule'
55    specifies the current module to be registered (eg. "perl", "fe").
56    The module is registered as statically loaded by default. */
57 MODULE_FILE_REC *module_register_full(const char *name, const char *submodule,
58                                       const char *defined_module_name);
59 #define module_register(name, submodule) \
60         module_register_full(name, submodule, MODULE_NAME)
61
62 MODULE_REC *module_find(const char *name);
63 MODULE_FILE_REC *module_file_find(MODULE_REC *module, const char *name);
64
65 #define MODULE_CHECK_CAST(object, cast, type_field, id) \
66         ((cast *) module_check_cast(object, offsetof(cast, type_field), id))
67 #define MODULE_CHECK_CAST_MODULE(object, cast, type_field, module, id) \
68         ((cast *) module_check_cast_module(object, \
69                                 offsetof(cast, type_field), module, id))
70 void *module_check_cast(void *object, int type_pos, const char *id);
71 void *module_check_cast_module(void *object, int type_pos,
72                                const char *module, const char *id);
73
74 /* return unique number across all modules for `id' */
75 int module_get_uniq_id(const char *module, int id);
76 /* return unique number across all modules for `id'. */
77 int module_get_uniq_id_str(const char *module, const char *id);
78
79 /* returns the original module specific id, -1 = not found */
80 int module_find_id(const char *module, int uniqid);
81 /* returns the original module specific id, NULL = not found */
82 const char *module_find_id_str(const char *module, int uniqid);
83
84 /* Destroy unique IDs from `module'. This function is automatically called
85    when module is destroyed with module's name as the parameter. */
86 void module_uniq_destroy(const char *module);
87
88 void modules_init(void);
89 void modules_deinit(void);
90
91 #endif