From c2f9e3d2b3431ae750aa3b51a0a60d7bf73deb0f Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 22 May 2015 20:01:12 +0200 Subject: command: add a new property deprecation mechanism Looks like this will be needed a lot... --- player/command.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'player/command.c') diff --git a/player/command.c b/player/command.c index e044e3320a..e849275547 100644 --- a/player/command.c +++ b/player/command.c @@ -75,6 +75,9 @@ struct command_ctx { double prev_pts; + char **warned_deprecated; + int num_warned_deprecated; + struct cycle_counter *cycle_counters; int num_cycle_counters; @@ -3081,6 +3084,29 @@ static int mp_property_alias(void *ctx, struct m_property *prop, return mp_property_do(real_property, action, arg, ctx); } +static int mp_property_deprecated_alias(void *ctx, struct m_property *prop, + int action, void *arg) +{ + MPContext *mpctx = ctx; + struct command_ctx *cmd = mpctx->command_ctx; + const char *real_property = prop->priv; + if (action == M_PROPERTY_SET || action == M_PROPERTY_GET || + action == M_PROPERTY_PRINT) + { + for (int n = 0; n < cmd->num_warned_deprecated; n++) { + if (strcmp(cmd->warned_deprecated[n], prop->name) == 0) + goto done; + } + MP_WARN(mpctx, "Warning: property '%s' was replaced with '%s' and " + "might be removed in the future.\n", prop->name, real_property); + MP_TARRAY_APPEND(cmd, cmd->warned_deprecated, cmd->num_warned_deprecated, + (char *)prop->name); + + done:; + } + return mp_property_do(real_property, action, arg, ctx); +} + static int access_options(struct m_property_action_arg *ka, bool local, MPContext *mpctx) { @@ -3237,6 +3263,9 @@ static int mp_property_list(void *ctx, struct m_property *prop, #define M_PROPERTY_ALIAS(name, real_property) \ {(name), mp_property_alias, .priv = (real_property)} +#define M_PROPERTY_DEPRECATED_ALIAS(name, real_property) \ + {(name), mp_property_deprecated_alias, .priv = (real_property)} + /// All properties available in MPlayer. /** \ingroup Properties */ -- cgit v1.2.3