[vlc-devel] [PATCHv2 04/18] variables: add var_GetAllNames

Thomas Guillem thomas at gllm.fr
Tue May 30 18:40:54 CEST 2017


---
 src/misc/variables.c | 32 ++++++++++++++++++++++++++++++++
 src/misc/variables.h | 11 +++++++++++
 2 files changed, 43 insertions(+)

diff --git a/src/misc/variables.c b/src/misc/variables.c
index b043d2018b..511449471a 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"
@@ -1380,3 +1381,34 @@ void DumpVariables(vlc_object_t *obj)
         twalk(vlc_internals(obj)->var_root, DumpVariable);
     vlc_mutex_unlock(&vlc_internals(obj)->var_lock);
 }
+
+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 = *var->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);
+    priv->var_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 76a7dd3360..a733018161 100644
--- a/src/misc/variables.h
+++ b/src/misc/variables.h
@@ -58,4 +58,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
-- 
2.11.0



More information about the vlc-devel mailing list