module-dir.h revision bd63b5b860658b01b1f46f26d406e1e4a9dc019a
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek#ifndef MODULE_DIR_H
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek#define MODULE_DIR_H
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozekstruct module_dir_load_settings {
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek /* If abi_version is non-NULL and the module contains a version symbol,
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek fail the load if they're different. In both strings ignore anything
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek after the first '(' character, so the version can be e.g.:
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek 2.2.ABIv1(2.2.15) */
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek const char *abi_version;
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek /* Binary name used for checking if plugin is tried to be loaded for
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek wrong binary. */
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek const char *binary_name;
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek /* Setting name used in plugin dependency error message */
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek const char *setting_name;
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek /* If non-NULL, load only modules where filter_callback returns TRUE */
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek bool (*filter_callback)(const char *name, void *context);
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek void *filter_context;
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek /* Require all plugins to have <plugin_name>_init() function */
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek unsigned int require_init_funcs:1;
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek /* Enable debug logging */
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek unsigned int debug:1;
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek /* If dlopen() fails for some modules, silently skip it. */
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek unsigned int ignore_dlopen_errors:1;
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek /* Don't fail if some specified modules weren't found */
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek unsigned int ignore_missing:1;
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek};
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozekstruct module {
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek char *path, *name;
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek void *handle;
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek void (*init)(struct module *module);
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek void (*deinit)(void);
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek unsigned int initialized:1;
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek struct module *next;
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek};
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek/* Load modules in given directory. module_names is a space separated list of
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek module names to load. */
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozekstruct module *module_dir_load(const char *dir, const char *module_names,
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek const struct module_dir_load_settings *set)
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek ATTR_NULL(2);
/* Load modules that aren't already loaded. */
struct module *
module_dir_load_missing(struct module *old_modules,
const char *dir, const char *module_names,
const struct module_dir_load_settings *set)
ATTR_NULL(1, 3);
/* Call init() in all modules */
void module_dir_init(struct module *modules);
/* Call deinit() in all modules and mark them NULL so module_dir_unload()
won't do it again. */
void module_dir_deinit(struct module *modules);
/* Unload all modules */
void module_dir_unload(struct module **modules);
void *module_get_symbol(struct module *module, const char *symbol);
void *module_get_symbol_quiet(struct module *module, const char *symbol);
/* Returns module's base name from the filename. */
const char *module_file_get_name(const char *fname);
/* Returns module's name without "_plugin" suffix. */
const char *module_get_plugin_name(struct module *module);
#endif