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