Commit 05e1b157 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

cli: return error code from commands

parent 66e13864
Pipeline #40561 passed with stages
in 27 minutes and 18 seconds
......@@ -146,7 +146,7 @@ void RegisterHandlers(intf_thread_t *intf, const struct cli_handler *handlers,
# include "../intromsg.h"
#endif
static void Help( intf_thread_t *p_intf, const char *const *args, size_t count)
static int Help( intf_thread_t *p_intf, const char *const *args, size_t count)
{
msg_rc("%s", _("+----[ Remote control commands ]"));
msg_rc( "| ");
......@@ -207,20 +207,22 @@ static void Help( intf_thread_t *p_intf, const char *const *args, size_t count)
msg_rc( "| ");
msg_rc("%s", _("+----[ end of help ]"));
(void) args; (void) count;
return 0;
}
static void Intf(intf_thread_t *intf, const char *const *args, size_t count)
static int Intf(intf_thread_t *intf, const char *const *args, size_t count)
{
intf_Create(vlc_object_instance(intf), count == 1 ? "" : args[1]);
return intf_Create(vlc_object_instance(intf), count == 1 ? "" : args[1]);
}
static void Quit(intf_thread_t *intf, const char *const *args, size_t count)
static int Quit(intf_thread_t *intf, const char *const *args, size_t count)
{
libvlc_Quit(vlc_object_instance(intf));
(void) args; (void) count;
return 0;
}
static void LogOut(intf_thread_t *intf, const char *const *args, size_t count)
static int LogOut(intf_thread_t *intf, const char *const *args, size_t count)
{
intf_sys_t *sys = intf->p_sys;
......@@ -255,14 +257,18 @@ static void LogOut(intf_thread_t *intf, const char *const *args, size_t count)
}
#endif
(void) args; (void) count;
return 0;
}
static void KeyAction(intf_thread_t *intf, const char *const *args, size_t n)
static int KeyAction(intf_thread_t *intf, const char *const *args, size_t n)
{
vlc_object_t *vlc = VLC_OBJECT(vlc_object_instance(intf));
if (n > 1)
var_SetInteger(vlc, "key-action", vlc_actions_get_id(args[1]));
if (n != 1)
return VLC_EGENERIC; /* EINVAL */
var_SetInteger(vlc, "key-action", vlc_actions_get_id(args[1]));
return 0;
}
static const struct cli_handler cmds[] =
......@@ -280,21 +286,23 @@ static const struct cli_handler cmds[] =
{ "hotkey", KeyAction },
};
static void UnknownCmd(intf_thread_t *intf, const char *const *args,
static int 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;
return VLC_EGENERIC;
}
static void Process(intf_thread_t *intf, const char *line)
static int Process(intf_thread_t *intf, const char *line)
{
intf_sys_t *sys = intf->p_sys;
/* Skip heading spaces */
const char *cmd = line + strspn(line, " ");
int ret;
if (*cmd == '\0')
return; /* Ignore empty line */
return 0; /* Ignore empty line */
#ifdef HAVE_WORDEXP
wordexp_t we;
......@@ -303,15 +311,24 @@ static void Process(intf_thread_t *intf, const char *line)
if (val != 0)
{
if (val == WRDE_NOSPACE)
{
ret = VLC_ENOMEM;
error: wordfree(&we);
}
else
ret = VLC_EGENERIC;
msg_print(intf, N_("parse error"));
return;
return ret;
}
size_t count = we.we_wordc;
const char **args = vlc_alloc(count, sizeof (*args));
if (unlikely(args == NULL))
{
ret = VLC_ENOMEM;
goto error;
}
for (size_t i = 0; i < we.we_wordc; i++)
args[i] = we.we_wordv[i];
......@@ -334,19 +351,20 @@ error: wordfree(&we);
if (count > 0)
{
void (*cb)(intf_thread_t *, const char *const *, size_t) = UnknownCmd;
int (*cb)(intf_thread_t *, const char *const *, size_t) = UnknownCmd;
const struct cli_handler **h = tfind(&args[0], &sys->commands, cmdcmp);
if (h != NULL)
cb = (*h)->callback;
cb(intf, args, count);
ret = cb(intf, args, count);
}
#ifdef HAVE_WORDEXP
free(args);
wordfree(&we);
#endif
return ret;
}
#ifndef _WIN32
......
......@@ -56,7 +56,7 @@ void msg_print(intf_thread_t *p_intf, const char *psz_fmt, ...);
struct cli_handler
{
const char *name;
void (*callback)(intf_thread_t *intf, const char *const *, size_t);
int (*callback)(intf_thread_t *intf, const char *const *, size_t);
};
void RegisterHandlers(intf_thread_t *intf, const struct cli_handler *handlers,
......
......@@ -158,7 +158,7 @@ static const struct vlc_player_aout_cbs player_aout_cbs =
.on_volume_changed = player_aout_on_volume_changed,
};
static void PlayerDoVoid(intf_thread_t *intf, void (*cb)(vlc_player_t *))
static int PlayerDoVoid(intf_thread_t *intf, void (*cb)(vlc_player_t *))
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
......@@ -166,33 +166,43 @@ static void PlayerDoVoid(intf_thread_t *intf, void (*cb)(vlc_player_t *))
vlc_player_Lock(player);
cb(player);
vlc_player_Unlock(player);
return 0;
}
static void PlayerDoFloat(intf_thread_t *intf, const char *const *args,
size_t count,
void (*setter)(vlc_player_t *, float),
float (*getter)(vlc_player_t *))
static int PlayerDoFloat(intf_thread_t *intf, const char *const *args,
size_t count,
void (*setter)(vlc_player_t *, float),
float (*getter)(vlc_player_t *))
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
vlc_player_t *player = vlc_playlist_GetPlayer(playlist);
int ret = 0;
vlc_player_Lock(player);
if (count < 2)
msg_print(intf, "%f", getter(player));
else
setter(player, atof(args[1]));
switch (count)
{
case 1:
msg_print(intf, "%f", getter(player));
break;
case 2:
setter(player, atof(args[1]));
break;
default:
ret = VLC_EGENERIC; /* EINVAL */
}
vlc_player_Unlock(player);
return ret;
}
static void PlayerPause(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerPause(intf_thread_t *intf, const char *const *args,
size_t count)
{
PlayerDoVoid(intf, vlc_player_TogglePause);
(void) args; (void) count;
return PlayerDoVoid(intf, vlc_player_TogglePause);
}
static void PlayerFastForward(intf_thread_t *intf, const char *const *args,
size_t count)
static int 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);
......@@ -213,9 +223,10 @@ static void PlayerFastForward(intf_thread_t *intf, const char *const *args,
}
vlc_player_Unlock(player);
(void) args; (void) count;
return 0;
}
static void PlayerRewind(intf_thread_t *intf, const char *const *args,
static int PlayerRewind(intf_thread_t *intf, const char *const *args,
size_t count)
{
vlc_playlist_t *playlist = intf->p_sys->playlist;
......@@ -236,20 +247,21 @@ static void PlayerRewind(intf_thread_t *intf, const char *const *args,
}
vlc_player_Unlock(player);
(void) args; (void) count;
return 0;
}
static void PlayerFaster(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerFaster(intf_thread_t *intf, const char *const *args,
size_t count)
{
PlayerDoVoid(intf, vlc_player_IncrementRate);
(void) args; (void) count;
return PlayerDoVoid(intf, vlc_player_IncrementRate);
}
static void PlayerSlower(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerSlower(intf_thread_t *intf, const char *const *args,
size_t count)
{
PlayerDoVoid(intf, vlc_player_DecrementRate);
(void) args; (void) count;
return PlayerDoVoid(intf, vlc_player_DecrementRate);
}
static void PlayerDoNormal(vlc_player_t *player)
......@@ -257,62 +269,63 @@ static void PlayerDoNormal(vlc_player_t *player)
vlc_player_ChangeRate(player, 1.f);
}
static void PlayerNormal(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerNormal(intf_thread_t *intf, const char *const *args,
size_t count)
{
PlayerDoVoid(intf, PlayerDoNormal);
(void) args; (void) count;
return PlayerDoVoid(intf, PlayerDoNormal);
}
static void PlayerRate(intf_thread_t *intf, const char *const *args, size_t n)
static int PlayerRate(intf_thread_t *intf, const char *const *args, size_t n)
{
PlayerDoFloat(intf, args, n, vlc_player_ChangeRate, vlc_player_GetRate);
return PlayerDoFloat(intf, args, n, vlc_player_ChangeRate,
vlc_player_GetRate);
}
static void PlayerFrame(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerFrame(intf_thread_t *intf, const char *const *args,
size_t count)
{
PlayerDoVoid(intf, vlc_player_NextVideoFrame);
(void) args; (void) count;
return PlayerDoVoid(intf, vlc_player_NextVideoFrame);
}
static void PlayerChapterPrev(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerChapterPrev(intf_thread_t *intf, const char *const *args,
size_t count)
{
PlayerDoVoid(intf, vlc_player_SelectPrevChapter);
(void) args; (void) count;
return PlayerDoVoid(intf, vlc_player_SelectPrevChapter);
}
static void PlayerChapterNext(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerChapterNext(intf_thread_t *intf, const char *const *args,
size_t count)
{
PlayerDoVoid(intf, vlc_player_SelectNextChapter);
(void) args; (void) count;
return PlayerDoVoid(intf, vlc_player_SelectNextChapter);
}
static void PlayerTitlePrev(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerTitlePrev(intf_thread_t *intf, const char *const *args,
size_t count)
{
PlayerDoVoid(intf, vlc_player_SelectPrevTitle);
(void) args; (void) count;
return PlayerDoVoid(intf, vlc_player_SelectPrevTitle);
}
static void PlayerTitleNext(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerTitleNext(intf_thread_t *intf, const char *const *args,
size_t count)
{
PlayerDoVoid(intf, vlc_player_SelectNextTitle);
(void) args; (void) count;
return PlayerDoVoid(intf, vlc_player_SelectNextTitle);
}
static void PlayerSeek(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerSeek(intf_thread_t *intf, const char *const *args,
size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
if (count != 2)
{
msg_print(intf, "%s expects one parameter", args[0]);
return;
return VLC_EGENERIC; /* EINVAL */
}
char *end;
......@@ -334,12 +347,14 @@ static void PlayerSeek(intf_thread_t *intf, const char *const *args,
else
vlc_player_SetTime(player, vlc_tick_from_sec(value));
vlc_player_Unlock(player);
return 0;
}
static void PlayerSetChapter(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerSetChapter(intf_thread_t *intf, const char *const *args,
size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
int ret = 0;
vlc_player_Lock(player);
......@@ -355,15 +370,20 @@ static void PlayerSetChapter(intf_thread_t *intf, const char *const *args,
msg_print(intf, "Currently playing chapter %zd/%zu.",
chapter, title->chapter_count);
else
{
msg_print(intf, "No chapter selected.");
ret = VLC_ENOITEM;
}
}
vlc_player_Unlock(player);
return ret;
}
static void PlayerSetTitle(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerSetTitle(intf_thread_t *intf, const char *const *args,
size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
int ret = 0;
vlc_player_Lock(player);
......@@ -385,18 +405,22 @@ static void PlayerSetTitle(intf_thread_t *intf, const char *const *args,
msg_print(intf, "Currently playing title %zd/%zu.", title,
title_count);
else
{
msg_print(intf, "No title selected.");
ret = VLC_ENOITEM;
}
}
vlc_player_Unlock(player);
return ret;
}
static void PlayerSetTrack(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerSetTrack(intf_thread_t *intf, const char *const *args,
size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
const char *psz_cmd = args[0];
enum es_format_category_e cat;
int ret = VLC_EGENERIC; /* EINVAL */
switch (psz_cmd[0])
{
......@@ -425,7 +449,10 @@ static void PlayerSetTrack(intf_thread_t *intf, const char *const *args,
struct vlc_player_track const *track =
vlc_player_GetTrackAt(player, cat, (size_t)idx);
if (track != NULL)
{
vlc_player_SelectTrack(player, track, VLC_PLAYER_SELECT_EXCLUSIVE);
ret = 0;
}
}
else
{
......@@ -443,13 +470,15 @@ static void PlayerSetTrack(intf_thread_t *intf, const char *const *args,
i, track->name, track == cur_track ? " *" : "");
}
msg_print(intf, "+----[ end of %s ]", name);
ret = 0;
}
out:
vlc_player_Unlock(player);
return ret;
}
static void PlayerRecord(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerRecord(intf_thread_t *intf, const char *const *args,
size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
......@@ -469,10 +498,11 @@ static void PlayerRecord(intf_thread_t *intf, const char *const *args,
if (cur_value != new_value)
vlc_player_SetRecordingEnabled(player, new_value);
vlc_player_Unlock(player);
return 0;
}
static void PlayerItemInfo(intf_thread_t *intf, const char *const *args,
size_t count)
static int 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;
......@@ -499,15 +529,14 @@ static void PlayerItemInfo(intf_thread_t *intf, const char *const *args,
vlc_mutex_unlock(&item->lock);
}
else
{
msg_print(intf, "no input");
}
vlc_player_Unlock(player);
(void) args; (void) count;
return (item != NULL) ? 0 : VLC_ENOITEM;
}
static void PlayerGetTime(intf_thread_t *intf, const char *const *args,
size_t count)
static int 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;
......@@ -515,14 +544,16 @@ static void PlayerGetTime(intf_thread_t *intf, const char *const *args,
vlc_player_Lock(player);
t = vlc_player_GetTime(player);
vlc_player_Unlock(player);
if (t != VLC_TICK_INVALID)
msg_print(intf, "%"PRIu64, SEC_FROM_VLC_TICK(t));
if (t == VLC_TICK_INVALID)
return VLC_ENOITEM;
msg_print(intf, "%"PRIu64, SEC_FROM_VLC_TICK(t));
(void) args; (void) count;
return 0;
}
static void PlayerGetLength(intf_thread_t *intf, const char *const *args,
size_t count)
static int 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;
......@@ -531,14 +562,16 @@ static void PlayerGetLength(intf_thread_t *intf, const char *const *args,
l = vlc_player_GetLength(player);
vlc_player_Unlock(player);
if (l != VLC_TICK_INVALID)
msg_print(intf, "%"PRIu64, SEC_FROM_VLC_TICK(l));
if (l == VLC_TICK_INVALID)
return VLC_ENOITEM;
msg_print(intf, "%"PRIu64, SEC_FROM_VLC_TICK(l));
(void) args; (void) count;
return 0;
}
static void PlayerGetTitle(intf_thread_t *intf, const char *const *args,
size_t count)
static int 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;
......@@ -548,17 +581,18 @@ static void PlayerGetTitle(intf_thread_t *intf, const char *const *args,
msg_print(intf, "%s", (title != NULL) ? title->name : "");
vlc_player_Unlock(player);
(void) args; (void) count;
return (title != NULL) ? 0 : VLC_ENOITEM;
}
static void PlayerVoutSnapshot(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerVoutSnapshot(intf_thread_t *intf, const char *const *args,
size_t count)
{
PlayerDoVoid(intf, vlc_player_vout_Snapshot);
(void) args; (void) count;
return PlayerDoVoid(intf, vlc_player_vout_Snapshot);
}
static void PlayerFullscreen(intf_thread_t *intf, const char *const *args,
size_t count)
static int PlayerFullscreen(intf_thread_t *intf, const char *const *args,
size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
bool fs = !vlc_player_vout_IsFullscreen(player);
......@@ -572,9 +606,10 @@ static void PlayerFullscreen(intf_thread_t *intf, const char *const *args,
}
vlc_player_vout_SetFullscreen(player, fs);
return 0;
}
static void Volume(intf_thread_t *intf, const char *const *args, size_t count)
static int Volume(intf_thread_t *intf, const char *const *args, size_t count)
{
const char *arg = count > 1 ? args[1] : "";
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
......@@ -593,10 +628,11 @@ static void Volume(intf_thread_t *intf, const char *const *args, size_t count)
msg_print(intf, STATUS_CHANGE "( audio volume: %ld )", volume);
}
vlc_player_Unlock(player);
return 0;
}
static void VolumeMove(intf_thread_t *intf, const char *const *args,
size_t count)
static int VolumeMove(intf_thread_t *intf, const char *const *args,
size_t count)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
const char *psz_cmd = args[0];
......@@ -611,10 +647,11 @@ static void VolumeMove(intf_thread_t *intf, const char *const *args,
vlc_player_Lock(player);
vlc_player_aout_IncrementVolume(player, i_nb_steps, &volume);
vlc_player_Unlock(player);
return 0;
}
static void VideoConfig(intf_thread_t *intf, const char *const *args,
size_t n_args)
static int VideoConfig(intf_thread_t *intf, const char *const *args,
size_t n_args)
{
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
vout_thread_t *p_vout = vlc_player_vout_Hold(player);
......@@ -661,7 +698,7 @@ static void VideoConfig(intf_thread_t *intf, const char *const *args,
if( psz_value == NULL )
{
vout_Release(p_vout);
return;
return VLC_ENOVAR;
}
}
......@@ -670,7 +707,7 @@ static void VideoConfig(intf_thread_t *intf, const char *const *args,
{
vout_Release(p_vout);
free( psz_value );
return;
return VLC_ENOMEM;
}
/* Get the descriptive name of the variable */
......@@ -713,22 +750,28 @@ static void VideoConfig(intf_thread_t *intf, const char *const *args,
free( name );
}
vout_Release(p_vout);
return 0;
}
static void AudioDevice(intf_thread_t *intf, const char *const *args,
size_t count)
static int AudioDevice(intf_thread_t *intf, const char *const *args,
size_t count)
{
const char *cmd = args[0];
const char *arg = count > 1 ? args[1] : "";
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
audio_output_t *aout = vlc_player_aout_Hold(player);
int ret = 0;
if (aout == NULL)
return;
return VLC_ENOOBJ;
char **ids, **names;
int n = aout_DevicesList(aout, &ids, &names);
if (n < 0)
{
ret = VLC_ENOMEM;
goto out;
}
bool setdev = count > 1;
if (setdev)
......@@ -771,17 +814,20 @@ static void AudioDevice(intf_thread_t *intf, const char *const *args,
free(names);
out:
aout_Release(aout);
return ret;
}
static void AudioChannel(intf_thread_t *intf, const char *const *args,
size_t n_args)
static int AudioChannel(intf_thread_t *intf, const char *const *args,
size_t n_args)
{
const char *cmd = args[0];
const char *arg = n_args > 1 ? args[1] : "";
vlc_player_t *player = vlc_playlist_GetPlayer(intf->p_sys->playlist);
audio_output_t *p_aout = vlc_player_aout_Hold(player);
int ret = 0;
if ( p_aout == NULL )
return;
return VLC_ENOOBJ;
if ( !*arg )
{
......@@ -792,7 +838,10 @@ static void AudioChannel(intf_thread_t *intf, const char *const *args,
if ( var_Change( p_aout, "stereo-mode", VLC_VAR_GETCHOICES,
&count, &val, &text ) < 0 )
{
ret = VLC_ENOVAR;
goto out;
}