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

config: add integer list callbacks for config items

parent 75b3b2ed
......@@ -54,6 +54,8 @@ typedef union
typedef int (*vlc_string_list_cb)(vlc_object_t *, const char *,
char ***, char ***);
typedef int (*vlc_integer_list_cb)(vlc_object_t *, const char *,
int64_t **, char ***);
struct module_config_t
{
......@@ -88,6 +90,7 @@ struct module_config_t
char **psz; /* List of possible values for the option */
int *i;
vlc_string_list_cb psz_cb;
vlc_integer_list_cb i_cb;
} list;
char **list_text; /* Friendly names for list values */
};
......
......@@ -491,6 +491,9 @@ VLC_METADATA_EXPORTS
(const int *)(list), \
(const char *const *)(list_text));
#define change_integer_cb( cb ) \
vlc_config_set (VLC_CONFIG_LIST_CB, (cb));
#define change_integer_range( minv, maxv ) \
vlc_config_set (VLC_CONFIG_RANGE, (int64_t)(minv), (int64_t)(maxv));
......
......@@ -354,7 +354,11 @@ ssize_t config_GetIntChoices (vlc_object_t *obj, const char *name,
size_t count = cfg->list_count;
if (count == 0)
return 0;
{
if (cfg->list.i_cb == NULL)
return 0;
return cfg->list.i_cb(obj, name, values, texts);
}
int64_t *vals = xmalloc (sizeof (*vals) * count);
char **txts = xmalloc (sizeof (*txts) * count);
......@@ -532,6 +536,12 @@ void config_Free (module_config_t *config, size_t confsize)
free( p_item->psz_text );
free( p_item->psz_longtext );
if (IsConfigIntegerType (p_item->i_type))
{
if (p_item->list_count)
free (p_item->list.i);
}
else
if (IsConfigStringType (p_item->i_type))
{
free (p_item->value.psz);
......@@ -543,8 +553,6 @@ void config_Free (module_config_t *config, size_t confsize)
free (p_item->list.psz);
}
}
else
free (p_item->list.i);
for (size_t i = 0; i < p_item->list_count; i++)
free (p_item->list_text[i]);
......
......@@ -490,7 +490,7 @@ static int AllocatePluginFile (module_bank_t *bank, const char *abspath,
* Could be optimized by adding an API call.*/
for (size_t n = module->confsize, i = 0; i < n; i++)
if (module->p_config[i].list_count == 0
&& module->p_config[i].list.psz_cb != NULL)
&& (module->p_config[i].list.psz_cb != NULL || module->p_config[i].list.i_cb != NULL))
{
/* !unloadable not allowed for plugins with callbacks */
vlc_module_destroy (module);
......
......@@ -144,7 +144,10 @@ static int CacheLoadConfig (module_config_t *cfg, FILE *file)
LOAD_IMMEDIATE (cfg->max);
cfg->value = cfg->orig;
cfg->list.i = xmalloc (cfg->list_count * sizeof (int));
if (cfg->list_count)
cfg->list.i = xmalloc (cfg->list_count * sizeof (int));
else
cfg->list.i_cb = NULL;
for (unsigned i = 0; i < cfg->list_count; i++)
LOAD_IMMEDIATE (cfg->list.i[i]);
}
......
......@@ -414,7 +414,13 @@ static int vlc_plugin_setter (void *plugin, void *tgt, int propid, ...)
}
case VLC_CONFIG_LIST_CB:
item->list.psz_cb = va_arg (ap, vlc_string_list_cb);
if (IsConfigIntegerType (item->i_type))
item->list.i_cb = va_arg (ap, vlc_integer_list_cb);
else
if (IsConfigStringType (item->i_type))
item->list.psz_cb = va_arg (ap, vlc_string_list_cb);
else
break;
break;
default:
......
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