Client: add method GetPartition(), make partition private

This commit is contained in:
Max Kellermann 2017-02-25 09:58:58 +01:00
parent e3ee60e7af
commit c7396b0675
9 changed files with 72 additions and 58 deletions

View File

@ -50,9 +50,9 @@ class Storage;
class Client final
: FullyBufferedSocket, TimeoutMonitor,
public boost::intrusive::list_base_hook<boost::intrusive::link_mode<boost::intrusive::normal_link>> {
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();

View File

@ -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());
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;