Client: replace playlist and player_control with getter methods

Prepare to convert "partition" to a mutable pointer.
This commit is contained in:
Max Kellermann 2017-02-20 12:44:09 +01:00
parent 71ce1a25dd
commit 668724de4e
7 changed files with 54 additions and 33 deletions

View File

@ -25,6 +25,18 @@
const Domain client_domain("client"); const Domain client_domain("client");
playlist &
Client::GetPlaylist()
{
return partition.playlist;
}
PlayerControl &
Client::GetPlayerControl()
{
return partition.pc;
}
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
const Database * const Database *

View File

@ -41,6 +41,8 @@ class SocketAddress;
class EventLoop; class EventLoop;
class Path; class Path;
struct Partition; struct Partition;
struct PlayerControl;
struct playlist;
class Database; class Database;
class Storage; class Storage;
@ -49,8 +51,6 @@ class Client final
public boost::intrusive::list_base_hook<boost::intrusive::link_mode<boost::intrusive::normal_link>> { public boost::intrusive::list_base_hook<boost::intrusive::link_mode<boost::intrusive::normal_link>> {
public: public:
Partition &partition; Partition &partition;
struct playlist &playlist;
struct PlayerControl &player_control;
unsigned permission; unsigned permission;
@ -187,6 +187,12 @@ public:
*/ */
void AllowFile(Path path_fs) const; void AllowFile(Path path_fs) const;
gcc_pure
playlist &GetPlaylist();
gcc_pure
PlayerControl &GetPlayerControl();
/** /**
* Wrapper for Instance::GetDatabase(). * Wrapper for Instance::GetDatabase().
*/ */

View File

@ -46,7 +46,6 @@ Client::Client(EventLoop &_loop, Partition &_partition,
:FullyBufferedSocket(_fd, _loop, 16384, client_max_output_buffer_size), :FullyBufferedSocket(_fd, _loop, 16384, client_max_output_buffer_size),
TimeoutMonitor(_loop), TimeoutMonitor(_loop),
partition(_partition), partition(_partition),
playlist(partition.playlist), player_control(partition.pc),
permission(getDefaultPermissions()), permission(getDefaultPermissions()),
uid(_uid), uid(_uid),
num(_num), num(_num),

View File

@ -86,18 +86,20 @@ handle_stop(Client &client, gcc_unused Request args, gcc_unused Response &r)
CommandResult CommandResult
handle_currentsong(Client &client, gcc_unused Request args, Response &r) handle_currentsong(Client &client, gcc_unused Request args, Response &r)
{ {
playlist_print_current(r, client.playlist); playlist_print_current(r, client.GetPlaylist());
return CommandResult::OK; return CommandResult::OK;
} }
CommandResult CommandResult
handle_pause(Client &client, Request args, gcc_unused Response &r) handle_pause(Client &client, Request args, gcc_unused Response &r)
{ {
auto &pc = client.GetPlayerControl();
if (!args.IsEmpty()) { if (!args.IsEmpty()) {
bool pause_flag = args.ParseBool(0); bool pause_flag = args.ParseBool(0);
client.player_control.LockSetPause(pause_flag); pc.LockSetPause(pause_flag);
} else } else
client.player_control.LockPause(); pc.LockPause();
return CommandResult::OK; return CommandResult::OK;
} }
@ -105,10 +107,12 @@ handle_pause(Client &client, Request args, gcc_unused Response &r)
CommandResult CommandResult
handle_status(Client &client, gcc_unused Request args, Response &r) handle_status(Client &client, gcc_unused Request args, Response &r)
{ {
auto &pc = client.GetPlayerControl();
const char *state = nullptr; const char *state = nullptr;
int song; int song;
const auto player_status = client.player_control.LockGetStatus(); const auto player_status = pc.LockGetStatus();
switch (player_status.state) { switch (player_status.state) {
case PlayerState::STOP: case PlayerState::STOP:
@ -122,7 +126,7 @@ handle_status(Client &client, gcc_unused Request args, Response &r)
break; break;
} }
const playlist &playlist = client.playlist; const playlist &playlist = client.GetPlaylist();
r.Format("volume: %i\n" r.Format("volume: %i\n"
COMMAND_STATUS_REPEAT ": %i\n" COMMAND_STATUS_REPEAT ": %i\n"
COMMAND_STATUS_RANDOM ": %i\n" COMMAND_STATUS_RANDOM ": %i\n"
@ -139,16 +143,16 @@ handle_status(Client &client, gcc_unused Request args, Response &r)
playlist.GetConsume(), playlist.GetConsume(),
(unsigned long)playlist.GetVersion(), (unsigned long)playlist.GetVersion(),
playlist.GetLength(), playlist.GetLength(),
client.player_control.GetMixRampDb(), pc.GetMixRampDb(),
state); state);
if (client.player_control.GetCrossFade() > 0) if (pc.GetCrossFade() > 0)
r.Format(COMMAND_STATUS_CROSSFADE ": %i\n", r.Format(COMMAND_STATUS_CROSSFADE ": %i\n",
int(client.player_control.GetCrossFade() + 0.5)); int(pc.GetCrossFade() + 0.5));
if (client.player_control.GetMixRampDelay() > 0) if (pc.GetMixRampDelay() > 0)
r.Format(COMMAND_STATUS_MIXRAMPDELAY ": %f\n", r.Format(COMMAND_STATUS_MIXRAMPDELAY ": %f\n",
client.player_control.GetMixRampDelay()); pc.GetMixRampDelay());
song = playlist.GetCurrentPosition(); song = playlist.GetCurrentPosition();
if (song >= 0) { if (song >= 0) {
@ -189,7 +193,7 @@ handle_status(Client &client, gcc_unused Request args, Response &r)
#endif #endif
try { try {
client.player_control.LockCheckRethrowError(); pc.LockCheckRethrowError();
} catch (...) { } catch (...) {
r.Format(COMMAND_STATUS_ERROR ": %s\n", r.Format(COMMAND_STATUS_ERROR ": %s\n",
FullMessage(std::current_exception()).c_str()); FullMessage(std::current_exception()).c_str());
@ -207,7 +211,7 @@ handle_status(Client &client, gcc_unused Request args, Response &r)
CommandResult CommandResult
handle_next(Client &client, gcc_unused Request args, gcc_unused Response &r) handle_next(Client &client, gcc_unused Request args, gcc_unused Response &r)
{ {
playlist &playlist = client.playlist; playlist &playlist = client.GetPlaylist();
/* single mode is not considered when this is user who /* single mode is not considered when this is user who
* wants to change song. */ * wants to change song. */
@ -267,7 +271,7 @@ CommandResult
handle_clearerror(Client &client, gcc_unused Request args, handle_clearerror(Client &client, gcc_unused Request args,
gcc_unused Response &r) gcc_unused Response &r)
{ {
client.player_control.LockClearError(); client.GetPlayerControl().LockClearError();
return CommandResult::OK; return CommandResult::OK;
} }
@ -306,7 +310,7 @@ CommandResult
handle_crossfade(Client &client, Request args, gcc_unused Response &r) handle_crossfade(Client &client, Request args, gcc_unused Response &r)
{ {
unsigned xfade_time = args.ParseUnsigned(0); unsigned xfade_time = args.ParseUnsigned(0);
client.player_control.SetCrossFade(xfade_time); client.GetPlayerControl().SetCrossFade(xfade_time);
return CommandResult::OK; return CommandResult::OK;
} }
@ -314,7 +318,7 @@ CommandResult
handle_mixrampdb(Client &client, Request args, gcc_unused Response &r) handle_mixrampdb(Client &client, Request args, gcc_unused Response &r)
{ {
float db = args.ParseFloat(0); float db = args.ParseFloat(0);
client.player_control.SetMixRampDb(db); client.GetPlayerControl().SetMixRampDb(db);
return CommandResult::OK; return CommandResult::OK;
} }
@ -322,7 +326,7 @@ CommandResult
handle_mixrampdelay(Client &client, Request args, gcc_unused Response &r) handle_mixrampdelay(Client &client, Request args, gcc_unused Response &r)
{ {
float delay_secs = args.ParseFloat(0); float delay_secs = args.ParseFloat(0);
client.player_control.SetMixRampDelay(delay_secs); client.GetPlayerControl().SetMixRampDelay(delay_secs);
return CommandResult::OK; return CommandResult::OK;
} }

View File

@ -58,7 +58,7 @@ print_spl_list(Response &r, const PlaylistVector &list)
CommandResult CommandResult
handle_save(Client &client, Request args, gcc_unused Response &r) handle_save(Client &client, Request args, gcc_unused Response &r)
{ {
spl_save_playlist(args.front(), client.playlist); spl_save_playlist(args.front(), client.GetPlaylist());
return CommandResult::OK; return CommandResult::OK;
} }
@ -72,8 +72,8 @@ handle_load(Client &client, Request args, gcc_unused Response &r)
const SongLoader loader(client); const SongLoader loader(client);
playlist_open_into_queue(args.front(), playlist_open_into_queue(args.front(),
range.start, range.end, range.start, range.end,
client.playlist, client.GetPlaylist(),
client.player_control, loader); client.GetPlayerControl(), loader);
return CommandResult::OK; return CommandResult::OK;
} }

View File

@ -164,8 +164,8 @@ handle_rangeid(Client &client, Request args, Response &r)
return CommandResult::ERROR; return CommandResult::ERROR;
} }
client.partition.playlist.SetSongIdRange(client.partition.pc, client.GetPlaylist().SetSongIdRange(client.GetPlayerControl(),
id, start, end); id, start, end);
return CommandResult::OK; return CommandResult::OK;
} }
@ -188,7 +188,7 @@ handle_deleteid(Client &client, Request args, gcc_unused Response &r)
CommandResult CommandResult
handle_playlist(Client &client, gcc_unused Request args, Response &r) handle_playlist(Client &client, gcc_unused Request args, Response &r)
{ {
playlist_print_uris(r, client.playlist); playlist_print_uris(r, client.GetPlaylist());
return CommandResult::OK; return CommandResult::OK;
} }
@ -212,7 +212,7 @@ handle_plchanges(Client &client, Request args, Response &r)
{ {
uint32_t version = ParseCommandArgU32(args.front()); uint32_t version = ParseCommandArgU32(args.front());
RangeArg range = args.ParseOptional(1, RangeArg::All()); RangeArg range = args.ParseOptional(1, RangeArg::All());
playlist_print_changes_info(r, client.playlist, version, playlist_print_changes_info(r, client.GetPlaylist(), version,
range.start, range.end); range.start, range.end);
return CommandResult::OK; return CommandResult::OK;
} }
@ -222,7 +222,7 @@ handle_plchangesposid(Client &client, Request args, Response &r)
{ {
uint32_t version = ParseCommandArgU32(args.front()); uint32_t version = ParseCommandArgU32(args.front());
RangeArg range = args.ParseOptional(1, RangeArg::All()); RangeArg range = args.ParseOptional(1, RangeArg::All());
playlist_print_changes_position(r, client.playlist, version, playlist_print_changes_position(r, client.GetPlaylist(), version,
range.start, range.end); range.start, range.end);
return CommandResult::OK; return CommandResult::OK;
} }
@ -232,7 +232,7 @@ handle_playlistinfo(Client &client, Request args, Response &r)
{ {
RangeArg range = args.ParseOptional(0, RangeArg::All()); RangeArg range = args.ParseOptional(0, RangeArg::All());
playlist_print_info(r, client.playlist, playlist_print_info(r, client.GetPlaylist(),
range.start, range.end); range.start, range.end);
return CommandResult::OK; return CommandResult::OK;
} }
@ -242,9 +242,9 @@ handle_playlistid(Client &client, Request args, Response &r)
{ {
if (!args.IsEmpty()) { if (!args.IsEmpty()) {
unsigned id = args.ParseUnsigned(0); unsigned id = args.ParseUnsigned(0);
playlist_print_id(r, client.playlist, id); playlist_print_id(r, client.GetPlaylist(), id);
} else { } else {
playlist_print_info(r, client.playlist, playlist_print_info(r, client.GetPlaylist(),
0, std::numeric_limits<unsigned>::max()); 0, std::numeric_limits<unsigned>::max());
} }
@ -261,7 +261,7 @@ handle_playlist_match(Client &client, Request args, Response &r,
return CommandResult::ERROR; return CommandResult::ERROR;
} }
playlist_print_find(r, client.playlist, filter); playlist_print_find(r, client.GetPlaylist(), filter);
return CommandResult::OK; return CommandResult::OK;
} }

View File

@ -40,7 +40,7 @@ handle_addtagid(Client &client, Request args, Response &r)
const char *const value = args[2]; const char *const value = args[2];
client.partition.playlist.AddSongIdTag(song_id, tag_type, value); client.GetPlaylist().AddSongIdTag(song_id, tag_type, value);
return CommandResult::OK; return CommandResult::OK;
} }
@ -60,6 +60,6 @@ handle_cleartagid(Client &client, Request args, Response &r)
} }
} }
client.partition.playlist.ClearSongIdTag(song_id, tag_type); client.GetPlaylist().ClearSongIdTag(song_id, tag_type);
return CommandResult::OK; return CommandResult::OK;
} }