vlc | branch: master | Thomas Guillem <[email protected]> | Tue May 30 11:02:41 2017 +0200| [e1597367c9d14428142be60a123822feb4cba6be] | committer: Thomas Guillem
variables: add var_GetAllNames > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e1597367c9d14428142be60a123822feb4cba6be --- src/misc/variables.c | 34 ++++++++++++++++++++++++++++++++++ src/misc/variables.h | 11 +++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/misc/variables.c b/src/misc/variables.c index 5e9ba678a8..f2e5478479 100644 --- a/src/misc/variables.c +++ b/src/misc/variables.c @@ -37,6 +37,7 @@ #include <limits.h> #include <vlc_common.h> +#include <vlc_arrays.h> #include <vlc_charset.h> #include "libvlc.h" #include "variables.h" @@ -1376,3 +1377,36 @@ void DumpVariables(vlc_object_t *obj) twalk(vlc_internals(obj)->var_root, DumpVariable); vlc_mutex_unlock(&vlc_internals(obj)->var_lock); } + +static _Thread_local void *twalk_ctx; + +static void TwalkGetNames(const void *data, const VISIT which, const int depth) +{ + if (which != postorder && which != leaf) + return; + (void) depth; + + const variable_t *var = *(const variable_t **)data; + DECL_ARRAY(char *) *names = twalk_ctx; + char *dup = strdup(var->psz_name); + if (dup != NULL) + ARRAY_APPEND(*names, dup); +} + +char **var_GetAllNames(vlc_object_t *obj) +{ + vlc_object_internals_t *priv = vlc_internals(obj); + + DECL_ARRAY(char *) names; + ARRAY_INIT(names); + + vlc_mutex_lock(&priv->var_lock); + twalk_ctx = &names; + twalk(priv->var_root, TwalkGetNames); + vlc_mutex_unlock(&priv->var_lock); + + if (names.i_size == 0) + return NULL; + ARRAY_APPEND(names, NULL); + return names.p_elems; +} diff --git a/src/misc/variables.h b/src/misc/variables.h index 97fb2ba18d..e5853e449c 100644 --- a/src/misc/variables.h +++ b/src/misc/variables.h @@ -57,4 +57,15 @@ void DumpVariables(vlc_object_t *obj); extern void var_DestroyAll( vlc_object_t * ); +/** + * Return a list of all variable names + * + * There is no warranty that the returned variables will be still alive after + * the return of this function. + * + * @return a NULL terminated list of char *, each elements and the return value + * must be freed by the caller + */ +char **var_GetAllNames(vlc_object_t *); + #endif _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
