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

Use callback and opaque pointer for plugin descriptors

This is more flexible and extensible.
parent cf52eed6
This diff is collapsed.
...@@ -56,8 +56,6 @@ static struct ...@@ -56,8 +56,6 @@ static struct
unsigned usage; unsigned usage;
} modules = { VLC_STATIC_MUTEX, NULL, 0 }; } modules = { VLC_STATIC_MUTEX, NULL, 0 };
module_t *vlc_entry__main (void);
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
...@@ -467,7 +465,7 @@ static module_t *module_InitDynamic (vlc_object_t *obj, ...@@ -467,7 +465,7 @@ static module_t *module_InitDynamic (vlc_object_t *obj,
} }
/* We can now try to call the symbol */ /* We can now try to call the symbol */
module_t *module = entry (); module_t *module = vlc_plugin_describe (entry);
if (unlikely(module == NULL)) if (unlikely(module == NULL))
{ {
/* With a well-written module we shouldn't have to print an /* With a well-written module we shouldn't have to print an
...@@ -497,8 +495,8 @@ error: ...@@ -497,8 +495,8 @@ error:
static module_t *module_InitStatic (vlc_plugin_cb entry) static module_t *module_InitStatic (vlc_plugin_cb entry)
{ {
/* Initializes the module */ /* Initializes the module */
module_t *module = entry (); module_t *module = vlc_plugin_describe (entry);
if (unlikely (module == NULL)) if (unlikely(module == NULL))
return NULL; return NULL;
module->b_loaded = true; module->b_loaded = true;
......
...@@ -145,8 +145,14 @@ static module_config_t *vlc_config_create (module_t *module, int type) ...@@ -145,8 +145,14 @@ static module_config_t *vlc_config_create (module_t *module, int type)
} }
int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...) /**
* Callback for the plugin descriptor functions.
*/
static int vlc_plugin_setter (void *plugin, void *tgt, int propid, ...)
{ {
module_t **pprimary = plugin;
module_t *module = tgt;
module_config_t *item = tgt;
va_list ap; va_list ap;
int ret = 0; int ret = 0;
...@@ -155,18 +161,20 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...) ...@@ -155,18 +161,20 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
{ {
case VLC_MODULE_CREATE: case VLC_MODULE_CREATE:
{ {
module_t **pp = va_arg (ap, module_t **); module = *pprimary;
module_t *submodule = vlc_module_create (module); module_t *submodule = vlc_module_create (module);
if (unlikely(submodule == NULL)) if (unlikely(submodule == NULL))
{ {
ret = -1; ret = -1;
break; break;
} }
*pp = submodule; *(va_arg (ap, module_t **)) = submodule;
if (module == NULL) if (*pprimary == NULL)
{
*pprimary = submodule;
break; break;
}
/* Inheritance. Ugly!! */ /* Inheritance. Ugly!! */
submodule->pp_shortcuts = xmalloc (sizeof (char **)); submodule->pp_shortcuts = xmalloc (sizeof (char **));
submodule->pp_shortcuts[0] = strdup_null (module->pp_shortcuts[0]); submodule->pp_shortcuts[0] = strdup_null (module->pp_shortcuts[0]);
...@@ -182,9 +190,14 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...) ...@@ -182,9 +190,14 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
{ {
int type = va_arg (ap, int); int type = va_arg (ap, int);
module_config_t **pp = va_arg (ap, module_config_t **); module_config_t **pp = va_arg (ap, module_config_t **);
*pp = vlc_config_create (module, type);
if (*pp == NULL) item = vlc_config_create (*pprimary, type);
if (unlikely(item == NULL))
{
ret = -1; ret = -1;
break;
}
*pp = item;
break; break;
} }
...@@ -465,3 +478,19 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...) ...@@ -465,3 +478,19 @@ int vlc_plugin_set (module_t *module, module_config_t *item, int propid, ...)
va_end (ap); va_end (ap);
return ret; return ret;
} }
/**
* Runs a plug-in descriptor. This loads the plug-in meta-data in memory.
*/
module_t *vlc_plugin_describe (vlc_plugin_cb entry)
{
module_t *module = NULL;
if (entry (vlc_plugin_setter, &module) != 0)
{
if (module != NULL) /* partially initialized plug-in... */
vlc_module_destroy (module);
module = NULL;
}
return module;
}
...@@ -46,7 +46,11 @@ struct module_cache_t ...@@ -46,7 +46,11 @@ struct module_cache_t
/** The module handle type */ /** The module handle type */
typedef void *module_handle_t; typedef void *module_handle_t;
typedef module_t *(*vlc_plugin_cb) (void); /** Plugin entry point prototype */
typedef int (*vlc_plugin_cb) (int (*)(void *, void *, int, ...), void *);
/** Main module */
int vlc_entry__main (int (*)(void *, void *, int, ...), void *);
/** /**
* Internal module descriptor * Internal module descriptor
...@@ -96,6 +100,7 @@ struct module_t ...@@ -96,6 +100,7 @@ struct module_t
char * domain; /* gettext domain */ char * domain; /* gettext domain */
}; };
module_t *vlc_plugin_describe (vlc_plugin_cb);
module_t *vlc_module_create (module_t *); module_t *vlc_module_create (module_t *);
void vlc_module_destroy (module_t *); void vlc_module_destroy (module_t *);
......
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