From c7396b06754ebba45421712413301ffa8466448f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 25 Feb 2017 09:58:58 +0100 Subject: [PATCH] Client: add method GetPartition(), make partition private --- src/client/Client.hxx | 6 ++++- src/command/AllCommands.cxx | 2 +- src/command/DatabaseCommands.cxx | 19 ++++++++-------- src/command/OtherCommands.cxx | 10 ++++---- src/command/OutputCommands.cxx | 8 +++---- src/command/PlayerCommands.cxx | 36 +++++++++++++++-------------- src/command/PlaylistCommands.cxx | 8 +++---- src/command/QueueCommands.cxx | 39 ++++++++++++++++++-------------- src/command/StickerCommands.cxx | 2 +- 9 files changed, 72 insertions(+), 58 deletions(-) diff --git a/src/client/Client.hxx b/src/client/Client.hxx index 92e2958ff..e2d81d3ac 100644 --- a/src/client/Client.hxx +++ b/src/client/Client.hxx @@ -50,9 +50,9 @@ class Storage; class Client final : FullyBufferedSocket, TimeoutMonitor, public boost::intrusive::list_base_hook> { -public: Partition &partition; +public: unsigned permission; /** the uid of the client process, or -1 if unknown */ @@ -188,6 +188,10 @@ public: */ void AllowFile(Path path_fs) const; + Partition &GetPartition() { + return partition; + } + gcc_pure Instance &GetInstance(); diff --git a/src/command/AllCommands.cxx b/src/command/AllCommands.cxx index 75e15d94d..43dbaa691 100644 --- a/src/command/AllCommands.cxx +++ b/src/command/AllCommands.cxx @@ -262,7 +262,7 @@ PrintUnavailableCommands(Response &r, unsigned permission) static CommandResult handle_commands(Client &client, gcc_unused Request request, Response &r) { - return PrintAvailableCommands(r, client.partition, + return PrintAvailableCommands(r, client.GetPartition(), client.GetPermission()); } diff --git a/src/command/DatabaseCommands.cxx b/src/command/DatabaseCommands.cxx index 729de699e..c06b5a225 100644 --- a/src/command/DatabaseCommands.cxx +++ b/src/command/DatabaseCommands.cxx @@ -41,7 +41,7 @@ CommandResult handle_listfiles_db(Client &client, Response &r, const char *uri) { const DatabaseSelection selection(uri, false); - db_selection_print(r, client.partition, + db_selection_print(r, client.GetPartition(), selection, false, true); return CommandResult::OK; } @@ -50,7 +50,7 @@ CommandResult handle_lsinfo2(Client &client, const char *uri, Response &r) { const DatabaseSelection selection(uri, false); - db_selection_print(r, client.partition, + db_selection_print(r, client.GetPartition(), selection, true, false); return CommandResult::OK; } @@ -85,7 +85,7 @@ handle_match(Client &client, Request args, Response &r, bool fold_case) const DatabaseSelection selection("", true, &filter); - db_selection_print(r, client.partition, + db_selection_print(r, client.GetPartition(), selection, true, false, sort, window.start, window.end); @@ -113,10 +113,11 @@ handle_match_add(Client &client, Request args, Response &r, bool fold_case) return CommandResult::ERROR; } - const ScopeBulkEdit bulk_edit(client.partition); + auto &partition = client.GetPartition(); + const ScopeBulkEdit bulk_edit(partition); const DatabaseSelection selection("", true, &filter); - AddFromDatabase(client.partition, selection); + AddFromDatabase(partition, selection); return CommandResult::OK; } @@ -173,7 +174,7 @@ handle_count(Client &client, Request args, Response &r) return CommandResult::ERROR; } - PrintSongCount(r, client.partition, "", &filter, group); + PrintSongCount(r, client.GetPartition(), "", &filter, group); return CommandResult::OK; } @@ -183,7 +184,7 @@ handle_listall(Client &client, Request args, Response &r) /* default is root directory */ const auto uri = args.GetOptional(0, ""); - db_selection_print(r, client.partition, + db_selection_print(r, client.GetPartition(), DatabaseSelection(uri, true), false, false); return CommandResult::OK; @@ -248,7 +249,7 @@ handle_list(Client &client, Request args, Response &r) return CommandResult::ERROR; } - PrintUniqueTags(r, client.partition, + PrintUniqueTags(r, client.GetPartition(), tagType, group_mask, filter.get()); return CommandResult::OK; } @@ -259,7 +260,7 @@ handle_listallinfo(Client &client, Request args, Response &r) /* default is root directory */ const auto uri = args.GetOptional(0, ""); - db_selection_print(r, client.partition, + db_selection_print(r, client.GetPartition(), DatabaseSelection(uri, true), true, false); return CommandResult::OK; diff --git a/src/command/OtherCommands.cxx b/src/command/OtherCommands.cxx index 266a8172c..9d209ce00 100644 --- a/src/command/OtherCommands.cxx +++ b/src/command/OtherCommands.cxx @@ -329,7 +329,7 @@ handle_setvol(Client &client, Request args, Response &r) { unsigned level = args.ParseUnsigned(0, 100); - if (!volume_level_change(client.partition.outputs, level)) { + if (!volume_level_change(client.GetPartition().outputs, level)) { r.Error(ACK_ERROR_SYSTEM, "problems setting volume"); return CommandResult::ERROR; } @@ -342,7 +342,9 @@ handle_volume(Client &client, Request args, Response &r) { int relative = args.ParseInt(0, -100, 100); - const int old_volume = volume_level_get(client.partition.outputs); + auto &outputs = client.GetPartition().outputs; + + const int old_volume = volume_level_get(outputs); if (old_volume < 0) { r.Error(ACK_ERROR_SYSTEM, "No mixer"); return CommandResult::ERROR; @@ -355,7 +357,7 @@ handle_volume(Client &client, Request args, Response &r) new_volume = 100; if (new_volume != old_volume && - !volume_level_change(client.partition.outputs, new_volume)) { + !volume_level_change(outputs, new_volume)) { r.Error(ACK_ERROR_SYSTEM, "problems setting volume"); return CommandResult::ERROR; } @@ -366,7 +368,7 @@ handle_volume(Client &client, Request args, Response &r) CommandResult handle_stats(Client &client, gcc_unused Request args, Response &r) { - stats_print(r, client.partition); + stats_print(r, client.GetPartition()); return CommandResult::OK; } diff --git a/src/command/OutputCommands.cxx b/src/command/OutputCommands.cxx index 0e6980113..1aa7c0e31 100644 --- a/src/command/OutputCommands.cxx +++ b/src/command/OutputCommands.cxx @@ -32,7 +32,7 @@ handle_enableoutput(Client &client, Request args, Response &r) assert(args.size == 1); unsigned device = args.ParseUnsigned(0); - if (!audio_output_enable_index(client.partition.outputs, device)) { + if (!audio_output_enable_index(client.GetPartition().outputs, device)) { r.Error(ACK_ERROR_NO_EXIST, "No such audio output"); return CommandResult::ERROR; } @@ -46,7 +46,7 @@ handle_disableoutput(Client &client, Request args, Response &r) assert(args.size == 1); unsigned device = args.ParseUnsigned(0); - if (!audio_output_disable_index(client.partition.outputs, device)) { + if (!audio_output_disable_index(client.GetPartition().outputs, device)) { r.Error(ACK_ERROR_NO_EXIST, "No such audio output"); return CommandResult::ERROR; } @@ -60,7 +60,7 @@ handle_toggleoutput(Client &client, Request args, Response &r) assert(args.size == 1); unsigned device = args.ParseUnsigned(0); - if (!audio_output_toggle_index(client.partition.outputs, device)) { + if (!audio_output_toggle_index(client.GetPartition().outputs, device)) { r.Error(ACK_ERROR_NO_EXIST, "No such audio output"); return CommandResult::ERROR; } @@ -73,6 +73,6 @@ handle_devices(Client &client, gcc_unused Request args, Response &r) { assert(args.IsEmpty()); - printAudioDevices(r, client.partition.outputs); + printAudioDevices(r, client.GetPartition().outputs); return CommandResult::OK; } diff --git a/src/command/PlayerCommands.cxx b/src/command/PlayerCommands.cxx index d81a78ba1..e73157ce4 100644 --- a/src/command/PlayerCommands.cxx +++ b/src/command/PlayerCommands.cxx @@ -63,7 +63,7 @@ handle_play(Client &client, Request args, gcc_unused Response &r) { int song = args.ParseOptional(0, -1); - client.partition.PlayPosition(song); + client.GetPartition().PlayPosition(song); return CommandResult::OK; } @@ -72,14 +72,14 @@ handle_playid(Client &client, Request args, gcc_unused Response &r) { int id = args.ParseOptional(0, -1); - client.partition.PlayId(id); + client.GetPartition().PlayId(id); return CommandResult::OK; } CommandResult handle_stop(Client &client, gcc_unused Request args, gcc_unused Response &r) { - client.partition.Stop(); + client.GetPartition().Stop(); return CommandResult::OK; } @@ -136,7 +136,7 @@ handle_status(Client &client, gcc_unused Request args, Response &r) COMMAND_STATUS_PLAYLIST_LENGTH ": %i\n" COMMAND_STATUS_MIXRAMPDB ": %f\n" COMMAND_STATUS_STATE ": %s\n", - volume_level_get(client.partition.outputs), + volume_level_get(client.GetPartition().outputs), playlist.GetRepeat(), playlist.GetRandom(), playlist.GetSingle(), @@ -222,7 +222,7 @@ handle_next(Client &client, gcc_unused Request args, gcc_unused Response &r) playlist.queue.single = single; }; - client.partition.PlayNext(); + client.GetPartition().PlayNext(); return CommandResult::OK; } @@ -230,7 +230,7 @@ CommandResult handle_previous(Client &client, gcc_unused Request args, gcc_unused Response &r) { - client.partition.PlayPrevious(); + client.GetPartition().PlayPrevious(); return CommandResult::OK; } @@ -238,7 +238,7 @@ CommandResult handle_repeat(Client &client, Request args, gcc_unused Response &r) { bool status = args.ParseBool(0); - client.partition.SetRepeat(status); + client.GetPartition().SetRepeat(status); return CommandResult::OK; } @@ -246,7 +246,7 @@ CommandResult handle_single(Client &client, Request args, gcc_unused Response &r) { bool status = args.ParseBool(0); - client.partition.SetSingle(status); + client.GetPartition().SetSingle(status); return CommandResult::OK; } @@ -254,7 +254,7 @@ CommandResult handle_consume(Client &client, Request args, gcc_unused Response &r) { bool status = args.ParseBool(0); - client.partition.SetConsume(status); + client.GetPartition().SetConsume(status); return CommandResult::OK; } @@ -262,8 +262,9 @@ CommandResult handle_random(Client &client, Request args, gcc_unused Response &r) { bool status = args.ParseBool(0); - client.partition.SetRandom(status); - client.partition.UpdateEffectiveReplayGainMode(); + auto &partition = client.GetPartition(); + partition.SetRandom(status); + partition.UpdateEffectiveReplayGainMode(); return CommandResult::OK; } @@ -281,7 +282,7 @@ handle_seek(Client &client, Request args, gcc_unused Response &r) unsigned song = args.ParseUnsigned(0); SongTime seek_time = args.ParseSongTime(1); - client.partition.SeekSongPosition(song, seek_time); + client.GetPartition().SeekSongPosition(song, seek_time); return CommandResult::OK; } @@ -291,7 +292,7 @@ handle_seekid(Client &client, Request args, gcc_unused Response &r) unsigned id = args.ParseUnsigned(0); SongTime seek_time = args.ParseSongTime(1); - client.partition.SeekSongId(id, seek_time); + client.GetPartition().SeekSongId(id, seek_time); return CommandResult::OK; } @@ -302,7 +303,7 @@ handle_seekcur(Client &client, Request args, gcc_unused Response &r) bool relative = *p == '+' || *p == '-'; SignedSongTime seek_time = ParseCommandArgSignedSongTime(p); - client.partition.SeekCurrent(seek_time, relative); + client.GetPartition().SeekCurrent(seek_time, relative); return CommandResult::OK; } @@ -334,8 +335,9 @@ CommandResult handle_replay_gain_mode(Client &client, Request args, Response &) { auto new_mode = FromString(args.front()); - client.partition.SetReplayGainMode(new_mode); - client.partition.EmitIdle(IDLE_OPTIONS); + auto &partition = client.GetPartition(); + partition.SetReplayGainMode(new_mode); + partition.EmitIdle(IDLE_OPTIONS); return CommandResult::OK; } @@ -344,6 +346,6 @@ handle_replay_gain_status(Client &client, gcc_unused Request args, Response &r) { r.Format("replay_gain_mode: %s\n", - ToString(client.partition.replay_gain_mode)); + ToString(client.GetPartition().replay_gain_mode)); return CommandResult::OK; } diff --git a/src/command/PlaylistCommands.cxx b/src/command/PlaylistCommands.cxx index 0d7458d66..9aaa053c3 100644 --- a/src/command/PlaylistCommands.cxx +++ b/src/command/PlaylistCommands.cxx @@ -67,7 +67,7 @@ handle_load(Client &client, Request args, gcc_unused Response &r) { RangeArg range = args.ParseOptional(1, RangeArg::All()); - const ScopeBulkEdit bulk_edit(client.partition); + const ScopeBulkEdit bulk_edit(client.GetPartition()); const SongLoader loader(client); playlist_open_into_queue(args.front(), @@ -82,8 +82,8 @@ handle_listplaylist(Client &client, Request args, Response &r) { const char *const name = args.front(); - if (playlist_file_print(r, client.partition, SongLoader(client), - name, false)) + if (playlist_file_print(r, client.GetPartition(), SongLoader(client), + name, false)) return CommandResult::OK; throw PlaylistError::NoSuchList(); @@ -94,7 +94,7 @@ handle_listplaylistinfo(Client &client, Request args, Response &r) { const char *const name = args.front(); - if (playlist_file_print(r, client.partition, SongLoader(client), + if (playlist_file_print(r, client.GetPartition(), SongLoader(client), name, true)) return CommandResult::OK; diff --git a/src/command/QueueCommands.cxx b/src/command/QueueCommands.cxx index d1beafbdf..079890130 100644 --- a/src/command/QueueCommands.cxx +++ b/src/command/QueueCommands.cxx @@ -43,7 +43,7 @@ static void AddUri(Client &client, const LocatedUri &uri) { - auto &partition = client.partition; + auto &partition = client.GetPartition(); partition.playlist.AppendSong(partition.pc, SongLoader(client).LoadSong(uri)); } @@ -53,10 +53,11 @@ AddDatabaseSelection(Client &client, const char *uri, gcc_unused Response &r) { #ifdef ENABLE_DATABASE - const ScopeBulkEdit bulk_edit(client.partition); + auto &partition = client.GetPartition(); + const ScopeBulkEdit bulk_edit(partition); const DatabaseSelection selection(uri, true); - AddFromDatabase(client.partition, selection); + AddFromDatabase(partition, selection); return CommandResult::OK; #else (void)client; @@ -103,17 +104,18 @@ handle_addid(Client &client, Request args, Response &r) { const char *const uri = args.front(); + auto &partition = client.GetPartition(); const SongLoader loader(client); - unsigned added_id = client.partition.AppendURI(loader, uri); + unsigned added_id = partition.AppendURI(loader, uri); if (args.size == 2) { unsigned to = args.ParseUnsigned(1); try { - client.partition.MoveId(added_id, to); + partition.MoveId(added_id, to); } catch (...) { /* rollback */ - client.partition.DeleteId(added_id); + partition.DeleteId(added_id); throw; } } @@ -173,7 +175,7 @@ CommandResult handle_delete(Client &client, Request args, gcc_unused Response &r) { RangeArg range = args.ParseRange(0); - client.partition.DeleteRange(range.start, range.end); + client.GetPartition().DeleteRange(range.start, range.end); return CommandResult::OK; } @@ -181,7 +183,7 @@ CommandResult handle_deleteid(Client &client, Request args, gcc_unused Response &r) { unsigned id = args.ParseUnsigned(0); - client.partition.DeleteId(id); + client.GetPartition().DeleteId(id); return CommandResult::OK; } @@ -196,14 +198,14 @@ CommandResult handle_shuffle(gcc_unused Client &client, Request args, gcc_unused Response &r) { RangeArg range = args.ParseOptional(0, RangeArg::All()); - client.partition.Shuffle(range.start, range.end); + client.GetPartition().Shuffle(range.start, range.end); return CommandResult::OK; } CommandResult handle_clear(Client &client, gcc_unused Request args, gcc_unused Response &r) { - client.partition.ClearQueue(); + client.GetPartition().ClearQueue(); return CommandResult::OK; } @@ -283,10 +285,11 @@ handle_prio(Client &client, Request args, gcc_unused Response &r) unsigned priority = args.ParseUnsigned(0, 0xff); args.shift(); + auto &partition = client.GetPartition(); + for (const char *i : args) { RangeArg range = ParseCommandArgRange(i); - client.partition.SetPriorityRange(range.start, range.end, - priority); + partition.SetPriorityRange(range.start, range.end, priority); } return CommandResult::OK; @@ -298,9 +301,11 @@ handle_prioid(Client &client, Request args, gcc_unused Response &r) unsigned priority = args.ParseUnsigned(0, 0xff); args.shift(); + auto &partition = client.GetPartition(); + for (const char *i : args) { unsigned song_id = ParseCommandArgUnsigned(i); - client.partition.SetPriorityId(song_id, priority); + partition.SetPriorityId(song_id, priority); } return CommandResult::OK; @@ -311,7 +316,7 @@ handle_move(Client &client, Request args, gcc_unused Response &r) { RangeArg range = args.ParseRange(0); int to = args.ParseInt(1); - client.partition.MoveRange(range.start, range.end, to); + client.GetPartition().MoveRange(range.start, range.end, to); return CommandResult::OK; } @@ -320,7 +325,7 @@ handle_moveid(Client &client, Request args, gcc_unused Response &r) { unsigned id = args.ParseUnsigned(0); int to = args.ParseInt(1); - client.partition.MoveId(id, to); + client.GetPartition().MoveId(id, to); return CommandResult::OK; } @@ -329,7 +334,7 @@ handle_swap(Client &client, Request args, gcc_unused Response &r) { unsigned song1 = args.ParseUnsigned(0); unsigned song2 = args.ParseUnsigned(1); - client.partition.SwapPositions(song1, song2); + client.GetPartition().SwapPositions(song1, song2); return CommandResult::OK; } @@ -338,6 +343,6 @@ handle_swapid(Client &client, Request args, gcc_unused Response &r) { unsigned id1 = args.ParseUnsigned(0); unsigned id2 = args.ParseUnsigned(1); - client.partition.SwapIds(id1, id2); + client.GetPartition().SwapIds(id1, id2); return CommandResult::OK; } diff --git a/src/command/StickerCommands.cxx b/src/command/StickerCommands.cxx index a6c6d6b48..5ce689a14 100644 --- a/src/command/StickerCommands.cxx +++ b/src/command/StickerCommands.cxx @@ -161,7 +161,7 @@ handle_sticker(Client &client, Request args, Response &r) } if (StringIsEqual(args[1], "song")) - return handle_sticker_song(r, client.partition, args); + return handle_sticker_song(r, client.GetPartition(), args); else { r.Error(ACK_ERROR_ARG, "unknown sticker domain"); return CommandResult::ERROR;