[vlc-commits] config: add integer list callbacks for config items

Rémi Denis-Courmont git at videolan.org
Sat Sep 15 09:30:54 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Sep 14 21:42:45 2012 +0300| [8629a3fed7b55c457679fff270303e4373b4c1f0] | committer: Rémi Denis-Courmont

config: add integer list callbacks for config items

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8629a3fed7b55c457679fff270303e4373b4c1f0
---

 include/vlc_configuration.h |    3 +++
 include/vlc_plugin.h        |    3 +++
 src/config/core.c           |   14 +++++++++++---
 src/modules/bank.c          |    2 +-
 src/modules/cache.c         |    5 ++++-
 src/modules/entry.c         |    8 +++++++-
 6 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/include/vlc_configuration.h b/include/vlc_configuration.h
index 02a8486..c3df097 100644
--- a/include/vlc_configuration.h
+++ b/include/vlc_configuration.h
@@ -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 */
 };
diff --git a/include/vlc_plugin.h b/include/vlc_plugin.h
index 3b59dc5..48af8ef 100644
--- a/include/vlc_plugin.h
+++ b/include/vlc_plugin.h
@@ -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));
 
diff --git a/src/config/core.c b/src/config/core.c
index f7d59be..5c485f0 100644
--- a/src/config/core.c
+++ b/src/config/core.c
@@ -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]);
diff --git a/src/modules/bank.c b/src/modules/bank.c
index 05392e9..8a2c5a7 100644
--- a/src/modules/bank.c
+++ b/src/modules/bank.c
@@ -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);
diff --git a/src/modules/cache.c b/src/modules/cache.c
index ae125bc..bd9b32d 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -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]);
     }
diff --git a/src/modules/entry.c b/src/modules/entry.c
index 33dc46d..2f63868 100644
--- a/src/modules/entry.c
+++ b/src/modules/entry.c
@@ -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:



More information about the vlc-commits mailing list