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