diff options
author | Max Kellermann <max@duempel.org> | 2016-02-28 10:51:07 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2016-02-28 11:02:36 +0100 |
commit | b6cb9b853a3385650d40cc121a6b4230e5cf81bc (patch) | |
tree | f3b9eb4c27f3c907350652184aa309915ffbe6dd | |
parent | 50b930f283c33f01ce43c54216896e7d3736a1c9 (diff) |
queue/PlaylistEdit: throw PlaylistError on error
-rw-r--r-- | src/command/PlaylistCommands.cxx | 12 | ||||
-rw-r--r-- | src/command/QueueCommands.cxx | 14 | ||||
-rw-r--r-- | src/db/DatabaseQueue.cxx | 14 | ||||
-rw-r--r-- | src/playlist/PlaylistQueue.cxx | 29 | ||||
-rw-r--r-- | src/playlist/PlaylistQueue.hxx | 9 | ||||
-rw-r--r-- | src/queue/Playlist.hxx | 13 | ||||
-rw-r--r-- | src/queue/PlaylistEdit.cxx | 42 |
7 files changed, 49 insertions, 84 deletions
diff --git a/src/command/PlaylistCommands.cxx b/src/command/PlaylistCommands.cxx index 08e944182..f1a40aa61 100644 --- a/src/command/PlaylistCommands.cxx +++ b/src/command/PlaylistCommands.cxx @@ -66,7 +66,7 @@ handle_save(Client &client, Request args, gcc_unused Response &r) } CommandResult -handle_load(Client &client, Request args, Response &r) +handle_load(Client &client, Request args, gcc_unused Response &r) { RangeArg range = args.ParseOptional(1, RangeArg::All()); @@ -74,12 +74,10 @@ handle_load(Client &client, Request args, Response &r) Error error; const SongLoader loader(client); - if (!playlist_open_into_queue(args.front(), - range.start, range.end, - client.playlist, - client.player_control, loader, error)) - return print_error(r, error); - + playlist_open_into_queue(args.front(), + range.start, range.end, + client.playlist, + client.player_control, loader); return CommandResult::OK; } diff --git a/src/command/QueueCommands.cxx b/src/command/QueueCommands.cxx index b6a7c16dc..bae8cdea4 100644 --- a/src/command/QueueCommands.cxx +++ b/src/command/QueueCommands.cxx @@ -54,11 +54,7 @@ AddUri(Client &client, const LocatedUri &uri, Response &r) return print_error(r, error); auto &partition = client.partition; - unsigned id = partition.playlist.AppendSong(partition.pc, - std::move(*song), error); - if (id == 0) - return print_error(r, error); - + partition.playlist.AppendSong(partition.pc, std::move(*song)); return CommandResult::OK; } @@ -186,12 +182,8 @@ handle_rangeid(Client &client, Request args, Response &r) return CommandResult::ERROR; } - Error error; - if (!client.partition.playlist.SetSongIdRange(client.partition.pc, - id, start, end, - error)) - return print_error(r, error); - + client.partition.playlist.SetSongIdRange(client.partition.pc, + id, start, end); return CommandResult::OK; } diff --git a/src/db/DatabaseQueue.cxx b/src/db/DatabaseQueue.cxx index 23b342f44..2dac3d5cd 100644 --- a/src/db/DatabaseQueue.cxx +++ b/src/db/DatabaseQueue.cxx @@ -28,15 +28,13 @@ #include <functional> static bool -AddToQueue(Partition &partition, const LightSong &song, Error &error) +AddToQueue(Partition &partition, const LightSong &song) { const Storage &storage = *partition.instance.storage; - unsigned id = - partition.playlist.AppendSong(partition.pc, - DatabaseDetachSong(storage, - song), - error); - return id != 0; + partition.playlist.AppendSong(partition.pc, + DatabaseDetachSong(storage, + song)); + return true; } bool @@ -48,6 +46,6 @@ AddFromDatabase(Partition &partition, const DatabaseSelection &selection, return false; using namespace std::placeholders; - const auto f = std::bind(AddToQueue, std::ref(partition), _1, _2); + const auto f = std::bind(AddToQueue, std::ref(partition), _1); return db->Visit(selection, f, error); } diff --git a/src/playlist/PlaylistQueue.cxx b/src/playlist/PlaylistQueue.cxx index 0bd2133ef..f42b191ad 100644 --- a/src/playlist/PlaylistQueue.cxx +++ b/src/playlist/PlaylistQueue.cxx @@ -35,12 +35,11 @@ #include <memory> -bool +void playlist_load_into_queue(const char *uri, SongEnumerator &e, unsigned start_index, unsigned end_index, playlist &dest, PlayerControl &pc, - const SongLoader &loader, - Error &error) + const SongLoader &loader) { const std::string base_uri = uri != nullptr ? PathTraitsUTF8::GetParent(uri) @@ -60,20 +59,15 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e, continue; } - unsigned id = dest.AppendSong(pc, std::move(*song), error); - if (id == 0) - return false; + dest.AppendSong(pc, std::move(*song)); } - - return true; } -bool +void playlist_open_into_queue(const char *uri, unsigned start_index, unsigned end_index, playlist &dest, PlayerControl &pc, - const SongLoader &loader, - Error &error) + const SongLoader &loader) { Mutex mutex; Cond cond; @@ -83,13 +77,10 @@ playlist_open_into_queue(const char *uri, loader.GetStorage(), #endif mutex, cond)); - if (playlist == nullptr) { - error.Set(playlist_domain, int(PlaylistResult::NO_SUCH_LIST), - "No such playlist"); - return false; - } + if (playlist == nullptr) + throw PlaylistError::NoSuchList(); - return playlist_load_into_queue(uri, *playlist, - start_index, end_index, - dest, pc, loader, error); + playlist_load_into_queue(uri, *playlist, + start_index, end_index, + dest, pc, loader); } diff --git a/src/playlist/PlaylistQueue.hxx b/src/playlist/PlaylistQueue.hxx index 16898c856..1507b70b7 100644 --- a/src/playlist/PlaylistQueue.hxx +++ b/src/playlist/PlaylistQueue.hxx @@ -41,22 +41,21 @@ struct PlayerControl; * @param start_index the index of the first song * @param end_index the index of the last song (excluding) */ -bool +void playlist_load_into_queue(const char *uri, SongEnumerator &e, unsigned start_index, unsigned end_index, playlist &dest, PlayerControl &pc, - const SongLoader &loader, - Error &error); + const SongLoader &loader); /** * Opens a playlist with a playlist plugin and append to the specified * play queue. */ -bool +void playlist_open_into_queue(const char *uri, unsigned start_index, unsigned end_index, playlist &dest, PlayerControl &pc, - const SongLoader &loader, Error &error); + const SongLoader &loader); #endif diff --git a/src/queue/Playlist.hxx b/src/queue/Playlist.hxx index 1abfb56a2..868dccceb 100644 --- a/src/queue/Playlist.hxx +++ b/src/queue/Playlist.hxx @@ -195,11 +195,11 @@ public: #endif /** - * @return the new song id or 0 on error + * Throws PlaylistError if the queue would be too large. + * + * @return the new song id */ - unsigned AppendSong(PlayerControl &pc, - DetachedSong &&song, - Error &error); + unsigned AppendSong(PlayerControl &pc, DetachedSong &&song); /** * @return the new song id or 0 on error @@ -254,9 +254,8 @@ public: * Sets the start_time and end_time attributes on the song * with the specified id. */ - bool SetSongIdRange(PlayerControl &pc, unsigned id, - SongTime start, SongTime end, - Error &error); + void SetSongIdRange(PlayerControl &pc, unsigned id, + SongTime start, SongTime end); void AddSongIdTag(unsigned id, TagType tag_type, const char *value); void ClearSongIdTag(unsigned id, TagType tag_type); diff --git a/src/queue/PlaylistEdit.cxx b/src/queue/PlaylistEdit.cxx index becaf1622..63699394f 100644 --- a/src/queue/PlaylistEdit.cxx +++ b/src/queue/PlaylistEdit.cxx @@ -92,15 +92,13 @@ playlist::CommitBulk(PlayerControl &pc) } unsigned -playlist::AppendSong(PlayerControl &pc, DetachedSong &&song, Error &error) +playlist::AppendSong(PlayerControl &pc, DetachedSong &&song) { unsigned id; - if (queue.IsFull()) { - error.Set(playlist_domain, int(PlaylistResult::TOO_LARGE), - "Playlist is too large"); - return 0; - } + if (queue.IsFull()) + throw PlaylistError(PlaylistResult::TOO_LARGE, + "Playlist is too large"); const DetachedSong *const queued_song = GetQueuedSong(); @@ -134,7 +132,7 @@ playlist::AppendURI(PlayerControl &pc, const SongLoader &loader, if (song == nullptr) return 0; - return AppendSong(pc, std::move(*song), error); + return AppendSong(pc, std::move(*song)); } void @@ -419,26 +417,20 @@ playlist::Shuffle(PlayerControl &pc, unsigned start, unsigned end) OnModified(); } -bool +void playlist::SetSongIdRange(PlayerControl &pc, unsigned id, - SongTime start, SongTime end, - Error &error) + SongTime start, SongTime end) { assert(end.IsZero() || start < end); int position = queue.IdToPosition(id); - if (position < 0) { - error.Set(playlist_domain, int(PlaylistResult::NO_SUCH_SONG), - "No such song"); - return false; - } + if (position < 0) + throw PlaylistError::NoSuchSong(); if (playing) { - if (position == current) { - error.Set(playlist_domain, int(PlaylistResult::DENIED), - "Cannot edit the current song"); - return false; - } + if (position == current) + throw PlaylistError(PlaylistResult::DENIED, + "Cannot edit the current song"); if (position == queued) { /* if we're manipulating the "queued" song, @@ -455,12 +447,9 @@ playlist::SetSongIdRange(PlayerControl &pc, unsigned id, if (!duration.IsNegative()) { /* validate the offsets */ - if (start > duration) { - error.Set(playlist_domain, - int(PlaylistResult::BAD_RANGE), - "Invalid start offset"); - return false; - } + if (start > duration) + throw PlaylistError(PlaylistResult::BAD_RANGE, + "Invalid start offset"); if (end >= duration) end = SongTime::zero(); @@ -474,5 +463,4 @@ playlist::SetSongIdRange(PlayerControl &pc, unsigned id, UpdateQueuedSong(pc, nullptr); queue.ModifyAtPosition(position); OnModified(); - return true; } |