libobs: Add post-load module callback

This allows the ability for certain types of modules (particularly
scripting-related modules) to initialize extra data when all other
modules have loaded.  Because front-ends may wish to have custom
handling for loading modules, the front-end must manually call
obs_post_load_modules after it has completed loading all plug-in
modules.

Closes jp9000/obs-studio#965
This commit is contained in:
SammyJames 2017-07-14 23:26:53 -04:00 committed by jp9000
parent c354551484
commit 4fd66d4d1e
5 changed files with 18 additions and 0 deletions

View File

@ -1317,6 +1317,8 @@ void OBSBasic::OBSInit()
obs_load_all_modules();
blog(LOG_INFO, "---------------------------------");
obs_log_loaded_modules();
blog(LOG_INFO, "---------------------------------");
obs_post_load_modules();
blog(LOG_INFO, STARTUP_SEPARATOR);

View File

@ -82,6 +82,7 @@ struct obs_module {
bool (*load)(void);
void (*unload)(void);
void (*post_load)(void);
void (*set_locale)(const char *locale);
void (*free_locale)(void);
uint32_t (*ver)(void);

View File

@ -48,6 +48,7 @@ static int load_module_exports(struct obs_module *mod, const char *path)
/* optional exports */
mod->unload = os_dlsym(mod->module, "obs_module_unload");
mod->post_load = os_dlsym(mod->module, "obs_module_post_load");
mod->set_locale = os_dlsym(mod->module, "obs_module_set_locale");
mod->free_locale = os_dlsym(mod->module, "obs_module_free_locale");
mod->name = os_dlsym(mod->module, "obs_module_name");
@ -254,6 +255,13 @@ void obs_load_all_modules(void)
profile_end(obs_load_all_modules_name);
}
void obs_post_load_modules(void)
{
for (obs_module_t *mod = obs->first_module; !!mod; mod = mod->next)
if (mod->post_load)
mod->post_load();
}
static inline void make_data_dir(struct dstr *parsed_data_dir,
const char *data_dir, const char *name)
{

View File

@ -97,6 +97,9 @@ MODULE_EXPORT bool obs_module_load(void);
/** Optional: Called when the module is unloaded. */
MODULE_EXPORT void obs_module_unload(void);
/** Optional: Called when all modules have finished loading */
MODULE_EXPORT void obs_module_post_load(void);
/** Called to set the current locale data for the module. */
MODULE_EXPORT void obs_module_set_locale(const char *locale);

View File

@ -374,6 +374,10 @@ EXPORT void obs_add_module_path(const char *bin, const char *data);
/** Automatically loads all modules from module paths (convenience function) */
EXPORT void obs_load_all_modules(void);
/** Notifies modules that all modules have been loaded. This function should
* be called after all modules have been loaded. */
EXPORT void obs_post_load_modules(void);
struct obs_module_info {
const char *bin_path;
const char *data_path;