GF_EXPORT GF_ModuleManager *gf_modules_new(const char *directory, GF_Config *config) { GF_ModuleManager *tmp; u32 loadedModules; const char *opt; if (!directory || !strlen(directory) || (strlen(directory) > GF_MAX_PATH)){ GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("Cannot load modules from directory %s, sanity check fails.\n", directory)); return NULL; } GF_SAFEALLOC(tmp, GF_ModuleManager); if (!tmp) return NULL; strcpy(tmp->dir, directory); /*remove the final delimiter*/ if (tmp->dir[strlen(tmp->dir)-1] == GF_PATH_SEPARATOR) tmp->dir[strlen(tmp->dir)-1] = 0; tmp->plug_list = gf_list_new(); if (!tmp->plug_list) { GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("OUT OF MEMORY, cannot create list of modules !!!\n", directory)); gf_free(tmp); return NULL; } tmp->cfg = config; opt = gf_cfg_get_key(config, "Systems", "ModuleUnload"); if (opt && !strcmp(opt, "no")) { tmp->no_unload = 1; } loadedModules = gf_modules_refresh(tmp); GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("Loaded %d modules from directory %s.\n", loadedModules, directory)); return tmp; }
GF_EXPORT GF_ModuleManager *gf_modules_new(const char *directory, GF_Config *config) { GF_ModuleManager *tmp; u32 loadedModules; const char *opt; u32 num_dirs = 0; if (!config) return NULL; /* Try to resolve directory from config file */ GF_SAFEALLOC(tmp, GF_ModuleManager); if (!tmp) return NULL; tmp->cfg = config; tmp->mutex = gf_mx_new("Module Manager"); gf_modules_get_module_directories(tmp, &num_dirs); /* Initialize module list */ tmp->plug_list = gf_list_new(); if (!tmp->plug_list) { GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("OUT OF MEMORY, cannot create list of modules !!!\n")); gf_free(tmp); return NULL; } tmp->plugin_registry = gf_list_new(); if (!tmp->plugin_registry) { GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("OUT OF MEMORY, cannot create list of static module registers !!!\n")); gf_list_del(tmp->plug_list); gf_free(tmp); return NULL; } opt = gf_cfg_get_key(config, "Systems", "ModuleUnload"); if (opt && !strcmp(opt, "no")) { tmp->no_unload = GF_TRUE; } #ifndef GPAC_MODULE_CUSTOM_LOAD load_all_modules(tmp); #endif loadedModules = gf_modules_refresh(tmp); GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("Loaded %d modules from directory %s.\n", loadedModules, directory)); return tmp; }