Commit b7de6c24 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

modules: move module handle and path to plugin structure

parent da6d40de
......@@ -73,8 +73,8 @@ static vlc_plugin_t *module_InitStatic(vlc_plugin_cb entry)
return NULL;
assert(lib->module != NULL);
lib->module->b_loaded = true;
lib->module->b_unloadable = false;
lib->loaded = true;
lib->unloadable = false;
return lib;
}
......@@ -148,14 +148,14 @@ static vlc_plugin_t *module_InitDynamic(vlc_object_t *obj, const char *path,
assert(plugin->module != NULL);
plugin->module->psz_filename = strdup (path);
if (unlikely(plugin->module->psz_filename == NULL))
plugin->abspath = strdup(path);
if (unlikely(plugin->abspath == NULL))
{
vlc_plugin_destroy(plugin);
goto error;
}
plugin->module->handle = handle;
plugin->module->b_loaded = true;
plugin->handle = handle;
plugin->loaded = true;
return plugin;
error:
module_Unload( handle );
......@@ -189,9 +189,8 @@ static int AllocatePluginFile (module_bank_t *bank, const char *abspath,
vlc_plugin_t *cache = vlc_cache_lookup(&bank->cache, relpath, st);
if (cache != NULL)
{
assert(cache->module != NULL);
cache->module->psz_filename = strdup(abspath);
if (likely(cache->module->psz_filename != NULL))
cache->abspath = strdup(abspath);
if (likely(cache->abspath != NULL))
plugin = cache;
else
vlc_plugin_destroy(cache);
......@@ -213,7 +212,7 @@ static int AllocatePluginFile (module_bank_t *bank, const char *abspath,
/* For now we force loading if the module's config contains callbacks.
* Could be optimized by adding an API call.*/
for (size_t i = 0; i < plugin->conf.size; i++)
if (!module->b_loaded
if (!plugin->loaded
&& plugin->conf.items[i].list_count == 0
&& (plugin->conf.items[i].list.psz_cb != NULL
|| plugin->conf.items[i].list.i_cb != NULL))
......@@ -475,10 +474,10 @@ void module_EndBank (bool b_plugins)
libs = lib->next;
#ifdef HAVE_DYNAMIC_PLUGINS
assert(lib->module != NULL);
if (lib->module->b_loaded && lib->module->b_unloadable)
if (lib->loaded && lib->unloadable)
{
module_Unload(lib->module->handle);
lib->module->b_loaded = false;
module_Unload(lib->handle);
lib->loaded = false;
}
#endif
vlc_plugin_destroy(lib);
......@@ -632,27 +631,25 @@ int module_Map (vlc_object_t *obj, module_t *module)
vlc_plugin_t *plugin = module->plugin;
assert(plugin != NULL);
module = plugin->module;
assert(module != NULL);
vlc_mutex_lock(&lock);
if (!module->b_loaded)
if (!plugin->loaded)
{
vlc_plugin_t *uncache;
assert (module->psz_filename != NULL);
assert(plugin->abspath != NULL);
#ifdef HAVE_DYNAMIC_PLUGINS
uncache = module_InitDynamic (obj, module->psz_filename, false);
uncache = module_InitDynamic(obj, plugin->abspath, false);
if (uncache != NULL)
{
assert(uncache->module != NULL);
CacheMerge(obj, module, uncache->module);
CacheMerge(obj, plugin->module, uncache->module);
vlc_plugin_destroy(uncache);
}
else
#endif
{
msg_Err (obj, "corrupt module: %s", module->psz_filename);
msg_Err(obj, "corrupt module: %s", plugin->abspath);
module = NULL;
}
}
......
......@@ -57,7 +57,7 @@
#ifdef HAVE_DYNAMIC_PLUGINS
/* Sub-version number
* (only used to avoid breakage in dev version when cache structure changes) */
#define CACHE_SUBVERSION_NUM 28
#define CACHE_SUBVERSION_NUM 29
/* Cache filename */
#define CACHE_NAME "plugins.dat"
......@@ -312,7 +312,6 @@ static module_t *vlc_cache_load_module(vlc_plugin_t *plugin, block_t *file)
LOAD_STRING(module->psz_capability);
LOAD_IMMEDIATE(module->i_score);
LOAD_IMMEDIATE(module->b_unloadable);
uint32_t submodules;
LOAD_IMMEDIATE(submodules);
......@@ -369,6 +368,7 @@ static vlc_plugin_t *vlc_cache_load_plugin(block_t *file)
if (unlikely(plugin->path == NULL))
goto error;
LOAD_FLAG(plugin->unloadable);
LOAD_IMMEDIATE(plugin->mtime);
LOAD_IMMEDIATE(plugin->size);
......@@ -650,7 +650,6 @@ static int CacheSaveBank(FILE *file, vlc_plugin_t *const *cache, size_t n)
SAVE_STRING(module->psz_capability);
SAVE_IMMEDIATE(module->i_score);
SAVE_IMMEDIATE(module->b_unloadable);
i_submodule = module->submodule_count;
SAVE_IMMEDIATE( i_submodule );
......@@ -664,6 +663,7 @@ static int CacheSaveBank(FILE *file, vlc_plugin_t *const *cache, size_t n)
/* Save common info */
SAVE_STRING(plugin->textdomain);
SAVE_STRING(plugin->path);
SAVE_FLAG(plugin->unloadable);
SAVE_IMMEDIATE(plugin->mtime);
SAVE_IMMEDIATE(plugin->size);
}
......@@ -732,7 +732,6 @@ void CacheMerge( vlc_object_t *p_this, module_t *p_cache, module_t *p_module )
p_cache->pf_activate = p_module->pf_activate;
p_cache->pf_deactivate = p_module->pf_deactivate;
p_cache->handle = p_module->handle;
/* FIXME: This looks too simplistic an algorithm to me. What if the module
* file was altered such that the number of order of submodules was
......@@ -747,8 +746,11 @@ void CacheMerge( vlc_object_t *p_this, module_t *p_cache, module_t *p_module )
p_cchild = p_cchild->next;
}
p_cache->b_loaded = true;
p_module->b_loaded = false;
p_cache->plugin->handle = p_module->plugin->handle;
assert(!p_cache->plugin->loaded);
p_cache->plugin->loaded = true;
assert(p_module->plugin->loaded);
p_module->plugin->loaded = false;
}
/**
......
......@@ -63,12 +63,8 @@ module_t *vlc_module_create(vlc_plugin_t *plugin)
module->i_shortcuts = 0;
module->psz_capability = NULL;
module->i_score = (parent != NULL) ? parent->i_score : 1;
module->b_loaded = false;
module->b_unloadable = parent == NULL;
module->pf_activate = NULL;
module->pf_deactivate = NULL;
/*module->handle = garbage */
module->psz_filename = NULL;
return module;
}
......@@ -77,15 +73,12 @@ module_t *vlc_module_create(vlc_plugin_t *plugin)
*/
void vlc_module_destroy (module_t *module)
{
assert (!module->b_loaded || !module->b_unloadable);
for (module_t *m = module->submodule, *next; m != NULL; m = next)
{
next = m->next;
vlc_module_destroy (m);
}
free (module->psz_filename);
free (module->pp_shortcuts);
free (module);
}
......@@ -96,13 +89,18 @@ vlc_plugin_t *vlc_plugin_create(void)
if (unlikely(plugin == NULL))
return NULL;
plugin->path = NULL;
plugin->module = NULL;
plugin->textdomain = NULL;
plugin->conf.items = NULL;
plugin->conf.size = 0;
plugin->conf.count = 0;
plugin->conf.booleans = 0;
plugin->abspath = NULL;
plugin->loaded = false;
plugin->unloadable = true;
plugin->handle = NULL;
plugin->abspath = NULL;
plugin->path = NULL;
plugin->module = NULL;
return plugin;
}
......@@ -115,11 +113,13 @@ vlc_plugin_t *vlc_plugin_create(void)
void vlc_plugin_destroy(vlc_plugin_t *plugin)
{
assert(plugin != NULL);
assert(!plugin->loaded || !plugin->unloadable);
if (plugin->module != NULL)
vlc_module_destroy(plugin->module);
config_Free(plugin->conf.items, plugin->conf.size);
free(plugin->abspath);
free(plugin->path);
free(plugin);
}
......@@ -260,8 +260,7 @@ static int vlc_plugin_setter(void *ctx, void *tgt, int propid, ...)
break;
case VLC_MODULE_NO_UNLOAD:
assert(module->plugin->module == module);
module->b_unloadable = false;
plugin->unloadable = false;
break;
case VLC_MODULE_NAME:
......
/*****************************************************************************
* modules.h : Module management functions.
*****************************************************************************
* Copyright (C) 2001 VLC authors and VideoLAN
* Copyright (C) 2001-2016 VLC authors and VideoLAN
* $Id$
*
* Authors: Samuel Hocevar <sam@zoy.org>
......@@ -24,15 +24,14 @@
#ifndef LIBVLC_MODULES_H
# define LIBVLC_MODULES_H 1
/** The plugin handle type */
typedef void *module_handle_t;
/** VLC plugin */
typedef struct vlc_plugin_t
{
struct vlc_plugin_t *next;
char *path; /**< Relative path */
time_t mtime; /**< Last modification time */
off_t size; /**< File size */
module_t *module;
const char *textdomain; /**< gettext domain (or NULL) */
......@@ -47,6 +46,15 @@ typedef struct vlc_plugin_t
size_t count; /**< Number of configuration items */
size_t booleans; /**< Number of booleal config items */
} conf;
bool loaded; /**< Whether the plug-in is mapped in memory */
bool unloadable; /**< Whether the plug-in can be unloaded safely */
module_handle_t handle; /**< Run-time linker handle (if loaded) */
char *abspath; /**< Absolute path */
char *path; /**< Relative path (within plug-in directory) */
time_t mtime; /**< Last modification time */
off_t size; /**< File size */
} vlc_plugin_t;
/**
......@@ -56,9 +64,6 @@ extern struct vlc_plugin_t *vlc_plugins;
#define MODULE_SHORTCUT_MAX 20
/** The module handle type */
typedef void *module_handle_t;
/** Plugin entry point prototype */
typedef int (*vlc_plugin_cb) (int (*)(void *, void *, int, ...), void *);
......@@ -89,19 +94,9 @@ struct module_t
const char *psz_capability; /**< Capability */
int i_score; /**< Score for the capability */
bool b_loaded; /* Set to true if the dll is loaded */
bool b_unloadable; /**< Can we be dlclosed? */
/* Callbacks */
void *pf_activate;
void *pf_deactivate;
/*
* Variables used internally by the module manager
*/
/* Plugin-specific stuff */
module_handle_t handle; /* Unique handle */
char * psz_filename; /* Module filename */
};
vlc_plugin_t *vlc_plugin_create(void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment