player/Control: use class Error as C++ exception, throw it

This commit is contained in:
Max Kellermann
2016-09-08 10:29:49 +02:00
parent 3da4648112
commit 6e52ab285a
9 changed files with 150 additions and 141 deletions

View File

@@ -62,10 +62,8 @@ handle_play(Client &client, Request args, gcc_unused Response &r)
{
int song = args.ParseOptional(0, -1);
Error error;
return client.partition.PlayPosition(song, error)
? CommandResult::OK
: print_error(r, error);
client.partition.PlayPosition(song);
return CommandResult::OK;
}
CommandResult
@@ -73,10 +71,8 @@ handle_playid(Client &client, Request args, gcc_unused Response &r)
{
int id = args.ParseOptional(0, -1);
Error error;
return client.partition.PlayId(id, error)
? CommandResult::OK
: print_error(r, error);
client.partition.PlayId(id);
return CommandResult::OK;
}
CommandResult
@@ -223,20 +219,16 @@ handle_next(Client &client, gcc_unused Request args, gcc_unused Response &r)
playlist.queue.single = single;
};
Error error;
return client.partition.PlayNext(error)
? CommandResult::OK
: print_error(r, error);
client.partition.PlayNext();
return CommandResult::OK;
}
CommandResult
handle_previous(Client &client, gcc_unused Request args,
gcc_unused Response &r)
{
Error error;
return client.partition.PlayPrevious(error)
? CommandResult::OK
: print_error(r, error);
client.partition.PlayPrevious();
return CommandResult::OK;
}
CommandResult
@@ -281,40 +273,34 @@ handle_clearerror(Client &client, gcc_unused Request args,
}
CommandResult
handle_seek(Client &client, Request args, Response &r)
handle_seek(Client &client, Request args, gcc_unused Response &r)
{
unsigned song = args.ParseUnsigned(0);
SongTime seek_time = args.ParseSongTime(1);
Error error;
return client.partition.SeekSongPosition(song, seek_time, error)
? CommandResult::OK
: print_error(r, error);
client.partition.SeekSongPosition(song, seek_time);
return CommandResult::OK;
}
CommandResult
handle_seekid(Client &client, Request args, Response &r)
handle_seekid(Client &client, Request args, gcc_unused Response &r)
{
unsigned id = args.ParseUnsigned(0);
SongTime seek_time = args.ParseSongTime(1);
Error error;
return client.partition.SeekSongId(id, seek_time, error)
? CommandResult::OK
: print_error(r, error);
client.partition.SeekSongId(id, seek_time);
return CommandResult::OK;
}
CommandResult
handle_seekcur(Client &client, Request args, Response &r)
handle_seekcur(Client &client, Request args, gcc_unused Response &r)
{
const char *p = args.front();
bool relative = *p == '+' || *p == '-';
SignedSongTime seek_time = ParseCommandArgSignedSongTime(p);
Error error;
return client.partition.SeekCurrent(seek_time, relative, error)
? CommandResult::OK
: print_error(r, error);
client.partition.SeekCurrent(seek_time, relative);
return CommandResult::OK;
}
CommandResult