[vlc-commits] cli: use same callback prototype for all commands

Rémi Denis-Courmont git at videolan.org
Sat Oct 17 20:36:03 CEST 2020


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Oct 17 16:43:42 2020 +0300| [22360334643e7efc828ee0ffdc086f496d05d26e] | committer: Rémi Denis-Courmont

cli: use same callback prototype for all commands

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

 modules/control/cli/cli.c      | 53 +++++++++++++++++++-------------------
 modules/control/cli/cli.h      | 52 ++++++++++++++++++-------------------
 modules/control/cli/player.c   | 58 +++++++++++++++++++++++++++++-------------
 modules/control/cli/playlist.c | 24 +++++++++++------
 4 files changed, 108 insertions(+), 79 deletions(-)

diff --git a/modules/control/cli/cli.c b/modules/control/cli/cli.c
index e06c72bb16..da13009234 100644
--- a/modules/control/cli/cli.c
+++ b/modules/control/cli/cli.c
@@ -88,7 +88,7 @@ void msg_print(intf_thread_t *p_intf, const char *psz_fmt, ...)
 # include "../intromsg.h"
 #endif
 
-static void Help( intf_thread_t *p_intf)
+static void Help( intf_thread_t *p_intf, const char *const *args, size_t count)
 {
     msg_rc("%s", _("+----[ Remote control commands ]"));
     msg_rc(  "| ");
@@ -148,6 +148,7 @@ static void Help( intf_thread_t *p_intf)
     msg_rc("%s", _("| quit . . . . . . . . . . . . . . . . . . .  quit vlc"));
     msg_rc(  "| ");
     msg_rc("%s", _("+----[ end of help ]"));
+    (void) args; (void) count;
 }
 
 static void Intf(intf_thread_t *intf, const char *const *args, size_t count)
@@ -155,12 +156,13 @@ static void Intf(intf_thread_t *intf, const char *const *args, size_t count)
     intf_Create(vlc_object_instance(intf), count == 1 ? "" : args[1]);
 }
 
-static void Quit(intf_thread_t *intf)
+static void Quit(intf_thread_t *intf, const char *const *args, size_t count)
 {
     libvlc_Quit(vlc_object_instance(intf));
+    (void) args; (void) count;
 }
 
-static void LogOut(intf_thread_t *intf)
+static void LogOut(intf_thread_t *intf, const char *const *args, size_t count)
 {
     intf_sys_t *sys = intf->p_sys;
 
@@ -170,6 +172,7 @@ static void LogOut(intf_thread_t *intf)
         net_Close(sys->i_socket);
         sys->i_socket = -1;
     }
+    (void) args; (void) count;
 }
 
 static void KeyAction(intf_thread_t *intf, const char *const *args, size_t n)
@@ -183,8 +186,8 @@ static void KeyAction(intf_thread_t *intf, const char *const *args, size_t n)
 static const struct
 {
     const char *name;
-    void (*handler)(intf_thread_t *);
-} void_cmds[] =
+    void (*handler)(intf_thread_t *, const char *const *, size_t);
+} cmds[] =
 {
     { "playlist", PlaylistList },
     { "sort", PlaylistSort },
@@ -220,14 +223,7 @@ static const struct
     { "?", Help },
     { "logout", LogOut },
     { "quit", Quit },
-};
 
-static const struct
-{
-    const char *name;
-    void (*handler)(intf_thread_t *, const char *const *, size_t);
-} string_cmds[] =
-{
     { "intf", Intf },
     { "add", Playlist },
     { "repeat", Playlist },
@@ -265,6 +261,13 @@ static const struct
     { "hotkey", KeyAction },
 };
 
+static void UnknownCmd(intf_thread_t *intf, const char *const *args,
+                       size_t count)
+{
+    msg_print(intf, _("Unknown command `%s'. Type `help' for help."), args[0]);
+    (void) count;
+}
+
 static void Process(intf_thread_t *intf, const char *line)
 {
     /* Skip heading spaces */
@@ -275,33 +278,29 @@ static void Process(intf_thread_t *intf, const char *line)
 
     /* Split psz_cmd at the first space and make sure that
      * psz_arg is valid */
+    const char *args[] = { cmd, NULL };
+    size_t count = 1;
     char *arg = strchr(cmd, ' ');
 
     if (arg != NULL)
     {
         *(arg++) = '\0';
         arg += strspn(arg, " ");
+
+        if (*arg)
+            count++;
     }
-    else
-        arg = (char *)"";
 
-    for (size_t i = 0; i < ARRAY_SIZE(void_cmds); i++)
-        if (strcmp(cmd, void_cmds[i].name) == 0)
-        {
-            void_cmds[i].handler(intf);
-            return;
-        }
+    void (*cb)(intf_thread_t *, const char *const *, size_t) = UnknownCmd;
 
-    for (size_t i = 0; i < ARRAY_SIZE(string_cmds); i++)
-        if (strcmp(cmd, string_cmds[i].name) == 0)
+    for (size_t i = 0; i < ARRAY_SIZE(cmds); i++)
+        if (strcmp(args[0], cmds[i].name) == 0)
         {
-            const char *argv[3] = { cmd, arg, NULL };
-
-            string_cmds[i].handler(intf, argv, 1 + (argv[1][0] != '\0'));
-            return;
+            cb = cmds[i].handler;
+            break;
         }
 
-    msg_print(intf, _("Unknown command `%s'. Type `help' for help."), cmd);
+    cb(intf, args, count);
 }
 
 
diff --git a/modules/control/cli/cli.h b/modules/control/cli/cli.h
index ee8dd86f67..000348e113 100644
--- a/modules/control/cli/cli.h
+++ b/modules/control/cli/cli.h
@@ -48,41 +48,41 @@ void msg_print(intf_thread_t *p_intf, const char *psz_fmt, ...);
 #define msg_rc(...) msg_print(p_intf, __VA_ARGS__)
 #define STATUS_CHANGE "status change: "
 
-void PlayerPause(intf_thread_t *intf);
-void PlayerFastForward(intf_thread_t *intf);
-void PlayerRewind(intf_thread_t *intf);
-void PlayerFaster(intf_thread_t *intf);
-void PlayerSlower(intf_thread_t *intf);
-void PlayerNormal(intf_thread_t *intf);
-void PlayerFrame(intf_thread_t *intf);
-void PlayerChapterPrev(intf_thread_t *intf);
-void PlayerChapterNext(intf_thread_t *intf);
-void PlayerTitlePrev(intf_thread_t *intf);
-void PlayerTitleNext(intf_thread_t *intf);
+void PlayerPause(intf_thread_t *intf, const char *const *, size_t);
+void PlayerFastForward(intf_thread_t *intf, const char *const *, size_t);
+void PlayerRewind(intf_thread_t *intf, const char *const *, size_t);
+void PlayerFaster(intf_thread_t *intf, const char *const *, size_t);
+void PlayerSlower(intf_thread_t *intf, const char *const *, size_t);
+void PlayerNormal(intf_thread_t *intf, const char *const *, size_t);
+void PlayerFrame(intf_thread_t *intf, const char *const *, size_t);
+void PlayerChapterPrev(intf_thread_t *intf, const char *const *, size_t);
+void PlayerChapterNext(intf_thread_t *intf, const char *const *, size_t);
+void PlayerTitlePrev(intf_thread_t *intf, const char *const *, size_t);
+void PlayerTitleNext(intf_thread_t *intf, const char *const *, size_t);
 void Input(intf_thread_t *intf, const char *const *, size_t);
-void PlayerItemInfo(intf_thread_t *intf);
-void PlayerGetTime(intf_thread_t *intf);
-void PlayerGetLength(intf_thread_t *intf);
-void PlayerGetTitle(intf_thread_t *intf);
-void PlayerVoutSnapshot(intf_thread_t *intf);
+void PlayerItemInfo(intf_thread_t *intf, const char *const *, size_t);
+void PlayerGetTime(intf_thread_t *intf, const char *const *, size_t);
+void PlayerGetLength(intf_thread_t *intf, const char *const *, size_t);
+void PlayerGetTitle(intf_thread_t *intf, const char *const *, size_t);
+void PlayerVoutSnapshot(intf_thread_t *intf, const char *const *, size_t);
 void PlayerFullscreen(intf_thread_t *intf, const char *const *, size_t);
 void Volume(intf_thread_t *intf, const char *const *, size_t);
 void VolumeMove(intf_thread_t *intf, const char *const *, size_t);
 void VideoConfig(intf_thread_t *intf, const char *const *, size_t);
 void AudioDevice(intf_thread_t *intf, const char *const *, size_t);
 void AudioChannel(intf_thread_t *intf, const char *const *, size_t);
-void Statistics(intf_thread_t *intf);
-void IsPlaying(intf_thread_t *intf);
+void Statistics(intf_thread_t *intf, const char *const *, size_t);
+void IsPlaying(intf_thread_t *intf, const char *const *, size_t);
 
 void *RegisterPlayer(intf_thread_t *intf);
 void DeregisterPlayer(intf_thread_t *intf, void *);
 
-void PlaylistPrev(intf_thread_t *intf);
-void PlaylistNext(intf_thread_t *intf);
-void PlaylistPlay(intf_thread_t *intf);
-void PlaylistStop(intf_thread_t *intf);
-void PlaylistClear(intf_thread_t *intf);
-void PlaylistSort(intf_thread_t *intf);
-void PlaylistList(intf_thread_t *intf);
-void PlaylistStatus(intf_thread_t *intf);
+void PlaylistPrev(intf_thread_t *intf, const char *const *, size_t);
+void PlaylistNext(intf_thread_t *intf, const char *const *, size_t);
+void PlaylistPlay(intf_thread_t *intf, const char *const *, size_t);
+void PlaylistStop(intf_thread_t *intf, const char *const *, size_t);
+void PlaylistClear(intf_thread_t *intf, const char *const *, size_t);
+void PlaylistSort(intf_thread_t *intf, const char *const *, size_t);
+void PlaylistList(intf_thread_t *intf, const char *const *, size_t);
+void PlaylistStatus(intf_thread_t *intf, const char *const *, size_t);
 void Playlist(intf_thread_t *intf, const char *const *, size_t);
diff --git a/modules/control/cli/player.c b/modules/control/cli/player.c
index 14557589e5..cfe4560620 100644
--- a/modules/control/cli/player.c
+++ b/modules/control/cli/player.c
@@ -139,12 +139,14 @@ static void PlayerDoVoid(intf_thread_t *intf, void (*cb)(vlc_player_t *))
     vlc_player_Unlock(player);
 }
 
-void PlayerPause(intf_thread_t *intf)
+void PlayerPause(intf_thread_t *intf, const char *const *args, size_t count)
 {
     PlayerDoVoid(intf, vlc_player_TogglePause);
+    (void) args; (void) count;
 }
 
-void PlayerFastForward(intf_thread_t *intf)
+void PlayerFastForward(intf_thread_t *intf, const char *const *args,
+                       size_t count)
 {
     vlc_playlist_t *playlist = intf->p_sys->playlist;
     vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
@@ -160,9 +162,10 @@ void PlayerFastForward(intf_thread_t *intf)
         var_SetInteger(vlc_object_instance(intf), "key-action",
                        ACTIONID_JUMP_FORWARD_EXTRASHORT);
     vlc_player_Unlock(player);
+    (void) args; (void) count;
 }
 
-void PlayerRewind(intf_thread_t *intf)
+void PlayerRewind(intf_thread_t *intf, const char *const *args, size_t count)
 {
     vlc_playlist_t *playlist = intf->p_sys->playlist;
     vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
@@ -177,16 +180,19 @@ void PlayerRewind(intf_thread_t *intf)
         var_SetInteger(vlc_object_instance(intf), "key-action",
                        ACTIONID_JUMP_BACKWARD_EXTRASHORT);
     vlc_player_Unlock(player);
+    (void) args; (void) count;
 }
 
-void PlayerFaster(intf_thread_t *intf)
+void PlayerFaster(intf_thread_t *intf, const char *const *args, size_t count)
 {
     PlayerDoVoid(intf, vlc_player_IncrementRate);
+    (void) args; (void) count;
 }
 
-void PlayerSlower(intf_thread_t *intf)
+void PlayerSlower(intf_thread_t *intf, const char *const *args, size_t count)
 {
     PlayerDoVoid(intf, vlc_player_DecrementRate);
+    (void) args; (void) count;
 }
 
 static void PlayerDoNormal(vlc_player_t *player)
@@ -194,34 +200,40 @@ static void PlayerDoNormal(vlc_player_t *player)
     vlc_player_ChangeRate(player, 1.f);
 }
 
-void PlayerNormal(intf_thread_t *intf)
+void PlayerNormal(intf_thread_t *intf, const char *const *args, size_t count)
 {
     PlayerDoVoid(intf, PlayerDoNormal);
+    (void) args; (void) count;
 }
 
-void PlayerFrame(intf_thread_t *intf)
+void PlayerFrame(intf_thread_t *intf, const char *const *args, size_t count)
 {
     PlayerDoVoid(intf, vlc_player_NextVideoFrame);
+    (void) args; (void) count;
 }
 
-void PlayerChapterPrev(intf_thread_t *intf)
+void PlayerChapterPrev(intf_thread_t *intf, const char *const *args, size_t count)
 {
     PlayerDoVoid(intf, vlc_player_SelectPrevChapter);
+    (void) args; (void) count;
 }
 
-void PlayerChapterNext(intf_thread_t *intf)
+void PlayerChapterNext(intf_thread_t *intf, const char *const *args, size_t count)
 {
     PlayerDoVoid(intf, vlc_player_SelectNextChapter);
+    (void) args; (void) count;
 }
 
-void PlayerTitlePrev(intf_thread_t *intf)
+void PlayerTitlePrev(intf_thread_t *intf, const char *const *args, size_t count)
 {
     PlayerDoVoid(intf, vlc_player_SelectPrevTitle);
+    (void) args; (void) count;
 }
 
-void PlayerTitleNext(intf_thread_t *intf)
+void PlayerTitleNext(intf_thread_t *intf, const char *const *args, size_t count)
 {
     PlayerDoVoid(intf, vlc_player_SelectNextTitle);
+    (void) args; (void) count;
 }
 
 void Input(intf_thread_t *intf, const char *const *args, size_t n_args)
@@ -356,7 +368,7 @@ out:
     vlc_player_Unlock(player);
 }
 
-void PlayerItemInfo(intf_thread_t *intf)
+void PlayerItemInfo(intf_thread_t *intf, const char *const *args, size_t count)
 {
     vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
     input_item_t *item;
@@ -387,9 +399,10 @@ void PlayerItemInfo(intf_thread_t *intf)
         msg_print(intf, "no input");
     }
     vlc_player_Unlock(player);
+    (void) args; (void) count;
 }
 
-void PlayerGetTime(intf_thread_t *intf)
+void PlayerGetTime(intf_thread_t *intf, const char *const *args, size_t count)
 {
     vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
     vlc_tick_t t;
@@ -399,9 +412,11 @@ void PlayerGetTime(intf_thread_t *intf)
     vlc_player_Unlock(player);
     if (t != VLC_TICK_INVALID)
         msg_print(intf, "%"PRIu64, SEC_FROM_VLC_TICK(t));
+
+    (void) args; (void) count;
 }
 
-void PlayerGetLength(intf_thread_t *intf)
+void PlayerGetLength(intf_thread_t *intf, const char *const *args, size_t count)
 {
     vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
     vlc_tick_t l;
@@ -412,9 +427,11 @@ void PlayerGetLength(intf_thread_t *intf)
 
     if (l != VLC_TICK_INVALID)
         msg_print(intf, "%"PRIu64, SEC_FROM_VLC_TICK(l));
+
+    (void) args; (void) count;
 }
 
-void PlayerGetTitle(intf_thread_t *intf)
+void PlayerGetTitle(intf_thread_t *intf, const char *const *args, size_t count)
 {
     vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
     const struct vlc_player_title *title;
@@ -423,11 +440,14 @@ void PlayerGetTitle(intf_thread_t *intf)
     title = vlc_player_GetSelectedTitle(player);
     msg_print(intf, "%s", (title != NULL) ? title->name : "");
     vlc_player_Unlock(player);
+    (void) args; (void) count;
 }
 
-void PlayerVoutSnapshot(intf_thread_t *intf)
+void PlayerVoutSnapshot(intf_thread_t *intf, const char *const *args,
+                        size_t count)
 {
     PlayerDoVoid(intf, vlc_player_vout_Snapshot);
+    (void) args; (void) count;
 }
 
 void PlayerFullscreen(intf_thread_t *intf, const char *const *args,
@@ -686,7 +706,7 @@ out:
     aout_Release(p_aout);
 }
 
-void Statistics(intf_thread_t *intf)
+void Statistics(intf_thread_t *intf, const char *const *args, size_t count)
 {
     vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
     input_item_t *item;
@@ -741,9 +761,10 @@ void Statistics(intf_thread_t *intf)
         msg_print(intf,  "+----[ end of statistical info ]" );
     }
     vlc_player_Unlock(player);
+    (void) args; (void) count;
 }
 
-void IsPlaying(intf_thread_t *intf)
+void IsPlaying(intf_thread_t *intf, const char *const *args, size_t count)
 {
     intf_sys_t *sys = intf->p_sys;
     vlc_player_t *player = vlc_playlist_GetPlayer(sys->playlist);
@@ -754,6 +775,7 @@ void IsPlaying(intf_thread_t *intf)
     msg_print(intf, "%d", state == VLC_PLAYER_STATE_PLAYING
                        || state == VLC_PLAYER_STATE_PAUSED);
     vlc_player_Unlock(player);
+    (void) args; (void) count;
 }
 
 void *RegisterPlayer(intf_thread_t *intf)
diff --git a/modules/control/cli/playlist.c b/modules/control/cli/playlist.c
index 2deb05012b..8e15655344 100644
--- a/modules/control/cli/playlist.c
+++ b/modules/control/cli/playlist.c
@@ -166,19 +166,22 @@ static void PlaylistDoVoid(intf_thread_t *intf, int (*cb)(vlc_playlist_t *))
     vlc_playlist_Unlock(playlist);
 }
 
-void PlaylistPrev(intf_thread_t *intf)
+void PlaylistPrev(intf_thread_t *intf, const char *const *args, size_t count)
 {
     PlaylistDoVoid(intf, vlc_playlist_Prev);
+    (void) args; (void) count;
 }
 
-void PlaylistNext(intf_thread_t *intf)
+void PlaylistNext(intf_thread_t *intf, const char *const *args, size_t count)
 {
     PlaylistDoVoid(intf, vlc_playlist_Next);
+    (void) args; (void) count;
 }
 
-void PlaylistPlay(intf_thread_t *intf)
+void PlaylistPlay(intf_thread_t *intf, const char *const *args, size_t count)
 {
     PlaylistDoVoid(intf, vlc_playlist_Start);
+    (void) args; (void) count;
 }
 
 static int PlaylistDoStop(vlc_playlist_t *playlist)
@@ -187,9 +190,10 @@ static int PlaylistDoStop(vlc_playlist_t *playlist)
     return 0;
 }
 
-void PlaylistStop(intf_thread_t *intf)
+void PlaylistStop(intf_thread_t *intf, const char *const *args, size_t count)
 {
     PlaylistDoVoid(intf, PlaylistDoStop);
+    (void) args; (void) count;
 }
 
 static int PlaylistDoClear(vlc_playlist_t *playlist)
@@ -199,9 +203,10 @@ static int PlaylistDoClear(vlc_playlist_t *playlist)
     return 0;
 }
 
-void PlaylistClear(intf_thread_t *intf)
+void PlaylistClear(intf_thread_t *intf, const char *const *args, size_t count)
 {
     PlaylistDoVoid(intf, PlaylistDoClear);
+    (void) args; (void) count;
 }
 
 static int PlaylistDoSort(vlc_playlist_t *playlist)
@@ -215,12 +220,13 @@ static int PlaylistDoSort(vlc_playlist_t *playlist)
     return vlc_playlist_Sort(playlist, &criteria, 1);
 }
 
-void PlaylistSort(intf_thread_t *intf)
+void PlaylistSort(intf_thread_t *intf, const char *const *args, size_t count)
 {
     PlaylistDoVoid(intf, PlaylistDoSort);
+    (void) args; (void) count;
 }
 
-void PlaylistList(intf_thread_t *intf)
+void PlaylistList(intf_thread_t *intf, const char *const *args, size_t count)
 {
     vlc_playlist_t *playlist = intf->p_sys->playlist;
 
@@ -229,9 +235,10 @@ void PlaylistList(intf_thread_t *intf)
     print_playlist(intf, playlist);
     vlc_playlist_Unlock(playlist);
     msg_print(intf, "+----[ End of playlist ]");
+    (void) args; (void) count;
 }
 
-void PlaylistStatus(intf_thread_t *intf)
+void PlaylistStatus(intf_thread_t *intf, const char *const *args, size_t count)
 {
     vlc_playlist_t *playlist = intf->p_sys->playlist;
     vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
@@ -281,6 +288,7 @@ void PlaylistStatus(intf_thread_t *intf)
     }
 
     msg_print(intf, STATUS_CHANGE "( %s state: %u )", stname, stnum);
+    (void) args; (void) count;
 }
 
 void Playlist(intf_thread_t *intf, const char *const *args, size_t n_args)



More information about the vlc-commits mailing list