summaryrefslogtreecommitdiffstats
path: root/player/command.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-05-01 02:38:59 +0200
committerJan Ekström <jeebjp@gmail.com>2018-05-03 01:20:01 +0300
commitfb9bbf2a0d7f8dba0d0674595cc2dc0dab68ad94 (patch)
treeb386f221e961ad81e35a3bc23bb66320ba942b80 /player/command.h
parente8b073584d749bb864f495d9e1cd31b102c6283d (diff)
downloadmpv-fb9bbf2a0d7f8dba0d0674595cc2dc0dab68ad94.tar.bz2
mpv-fb9bbf2a0d7f8dba0d0674595cc2dc0dab68ad94.tar.xz
command: split big command handler switch into separate functions
This gets rid of run_command() and its big switch statement, which was an idiotically big function of almost 1000 lines. The switch is replaced with a callback per command, and each command is now implemented in its own function. Command IDs are not needed anymore, so the mp_command_type enum disappears. There should be no functional changes, but since this refactors 64 commands, regressions are possible. The handler() parameter is void*, because in theory the input code is supposed to be independent of the player core code. For example, you should be able to reuse the command parser code for some other part of mpv. In practice, the variable containing command list is defined in the player core anyway, so you could say this doesn't work. But I'm still trying to hold onto this idea, so I went with void*.
Diffstat (limited to 'player/command.h')
-rw-r--r--player/command.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/player/command.h b/player/command.h
index a8638d6666..b6ccffe80f 100644
--- a/player/command.h
+++ b/player/command.h
@@ -29,6 +29,25 @@ struct m_config_option;
void command_init(struct MPContext *mpctx);
void command_uninit(struct MPContext *mpctx);
+// Runtime context for a single command.
+struct mp_cmd_ctx {
+ struct MPContext *mpctx;
+ struct mp_cmd *cmd; // original command
+ // Fields from cmd (for convenience)
+ struct mp_cmd_arg *args;
+ int num_args;
+ const void *priv; // cmd->def->priv
+ // OSD control
+ int on_osd; // MP_ON_OSD_FLAGS;
+ bool msg_osd; // OSD message requested
+ bool bar_osd; // OSD bar requested
+ bool seek_msg_osd; // same as above, but for seek commands
+ bool seek_bar_osd;
+ // Return values
+ bool success; // true by default
+ struct mpv_node *result;
+};
+
int run_command(struct MPContext *mpctx, struct mp_cmd *cmd, struct mpv_node *res);
char *mp_property_expand_string(struct MPContext *mpctx, const char *str);
char *mp_property_expand_escaped_string(struct MPContext *mpctx, const char *str);