Commit ff626ac7 authored by Max Kellermann's avatar Max Kellermann

*: use references instead of pointers

parent 59f8144c
......@@ -56,15 +56,15 @@ struct command {
unsigned permission;
int min;
int max;
enum command_return (*handler)(Client *client, int argc, char **argv);
enum command_return (*handler)(Client &client, int argc, char **argv);
};
/* don't be fooled, this is the command handler for "commands" command */
static enum command_return
handle_commands(Client *client, int argc, char *argv[]);
handle_commands(Client &client, int argc, char *argv[]);
static enum command_return
handle_not_commands(Client *client, int argc, char *argv[]);
handle_not_commands(Client &client, int argc, char *argv[]);
/**
* The command registry.
......@@ -179,7 +179,7 @@ command_available(gcc_unused const struct command *cmd)
/* don't be fooled, this is the command handler for "commands" command */
static enum command_return
handle_commands(Client *client,
handle_commands(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
const unsigned permission = client_get_permission(client);
......@@ -197,7 +197,7 @@ handle_commands(Client *client,
}
static enum command_return
handle_not_commands(Client *client,
handle_not_commands(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
const unsigned permission = client_get_permission(client);
......@@ -249,17 +249,16 @@ command_lookup(const char *name)
}
static bool
command_check_request(const struct command *cmd, Client *client,
command_check_request(const struct command *cmd, Client &client,
unsigned permission, int argc, char *argv[])
{
int min = cmd->min + 1;
int max = cmd->max + 1;
if (cmd->permission != (permission & cmd->permission)) {
if (client != nullptr)
command_error(client, ACK_ERROR_PERMISSION,
"you don't have permission for \"%s\"",
cmd->cmd);
command_error(client, ACK_ERROR_PERMISSION,
"you don't have permission for \"%s\"",
cmd->cmd);
return false;
}
......@@ -267,27 +266,24 @@ command_check_request(const struct command *cmd, Client *client,
return true;
if (min == max && max != argc) {
if (client != nullptr)
command_error(client, ACK_ERROR_ARG,
"wrong number of arguments for \"%s\"",
argv[0]);
command_error(client, ACK_ERROR_ARG,
"wrong number of arguments for \"%s\"",
argv[0]);
return false;
} else if (argc < min) {
if (client != nullptr)
command_error(client, ACK_ERROR_ARG,
"too few arguments for \"%s\"", argv[0]);
command_error(client, ACK_ERROR_ARG,
"too few arguments for \"%s\"", argv[0]);
return false;
} else if (argc > max && max /* != 0 */ ) {
if (client != nullptr)
command_error(client, ACK_ERROR_ARG,
"too many arguments for \"%s\"", argv[0]);
command_error(client, ACK_ERROR_ARG,
"too many arguments for \"%s\"", argv[0]);
return false;
} else
return true;
}
static const struct command *
command_checked_lookup(Client *client, unsigned permission,
command_checked_lookup(Client &client, unsigned permission,
int argc, char *argv[])
{
const struct command *cmd;
......@@ -299,9 +295,8 @@ command_checked_lookup(Client *client, unsigned permission,
cmd = command_lookup(argv[0]);
if (cmd == nullptr) {
if (client != nullptr)
command_error(client, ACK_ERROR_UNKNOWN,
"unknown command \"%s\"", argv[0]);
command_error(client, ACK_ERROR_UNKNOWN,
"unknown command \"%s\"", argv[0]);
return nullptr;
}
......@@ -314,7 +309,7 @@ command_checked_lookup(Client *client, unsigned permission,
}
enum command_return
command_process(Client *client, unsigned num, char *line)
command_process(Client &client, unsigned num, char *line)
{
Error error;
char *argv[COMMAND_ARGV_MAX] = { nullptr };
......
......@@ -29,6 +29,6 @@ void command_init(void);
void command_finish(void);
enum command_return
command_process(Client *client, unsigned num, char *line);
command_process(Client &client, unsigned num, char *line);
#endif
......@@ -23,17 +23,20 @@
const Domain client_domain("client");
int client_get_uid(const Client *client)
int
client_get_uid(const Client &client)
{
return client->uid;
return client.uid;
}
unsigned client_get_permission(const Client *client)
unsigned
client_get_permission(const Client &client)
{
return client->permission;
return client.permission;
}
void client_set_permission(Client *client, unsigned permission)
void
client_set_permission(Client &client, unsigned permission)
{
client->permission = permission;
client.permission = permission;
}
......@@ -41,7 +41,8 @@ client_new(EventLoop &loop, Partition &partition,
* uid is unknown
*/
gcc_pure
int client_get_uid(const Client *client);
int
client_get_uid(const Client &client);
/**
* Is this client running on the same machine, connected with a local
......@@ -49,31 +50,32 @@ int client_get_uid(const Client *client);
*/
gcc_pure
static inline bool
client_is_local(const Client *client)
client_is_local(const Client &client)
{
return client_get_uid(client) > 0;
}
gcc_pure
unsigned client_get_permission(const Client *client);
unsigned
client_get_permission(const Client &client);
void client_set_permission(Client *client, unsigned permission);
void client_set_permission(Client &client, unsigned permission);
/**
* Write a C string to the client.
*/
void client_puts(Client *client, const char *s);
void client_puts(Client &client, const char *s);
/**
* Write a printf-like formatted string to the client.
*/
void client_vprintf(Client *client, const char *fmt, va_list args);
void client_vprintf(Client &client, const char *fmt, va_list args);
/**
* Write a printf-like formatted string to the client.
*/
gcc_printf(2,3)
void
client_printf(Client *client, const char *fmt, ...);
client_printf(Client &client, const char *fmt, ...);
#endif
......@@ -32,7 +32,7 @@
#include <unistd.h>
bool
client_allow_file(const Client *client, Path path_fs, Error &error)
client_allow_file(const Client &client, Path path_fs, Error &error)
{
#ifdef WIN32
(void)client;
......
......@@ -35,6 +35,6 @@ class Error;
* @return true if access is allowed
*/
bool
client_allow_file(const Client *client, Path path_fs, Error &error);
client_allow_file(const Client &client, Path path_fs, Error &error);
#endif
......@@ -36,11 +36,11 @@ Client::IdleNotify()
const char *const*idle_names = idle_get_names();
for (unsigned i = 0; idle_names[i]; ++i) {
if (flags & (1 << i) & idle_subscriptions)
client_printf(this, "changed: %s\n",
client_printf(*this, "changed: %s\n",
idle_names[i]);
}
client_puts(this, "OK\n");
client_puts(*this, "OK\n");
TimeoutMonitor::ScheduleSeconds(client_timeout);
}
......
......@@ -43,7 +43,7 @@ class Client final : private FullyBufferedSocket, TimeoutMonitor {
public:
Partition &partition;
struct playlist &playlist;
struct player_control *player_control;
struct player_control &player_control;
unsigned permission;
......@@ -126,6 +126,6 @@ extern size_t client_max_command_list_size;
extern size_t client_max_output_buffer_size;
enum command_return
client_process_line(Client *client, char *line);
client_process_line(Client &client, char *line);
#endif
......@@ -50,7 +50,7 @@ Client::Client(EventLoop &_loop, Partition &_partition,
:FullyBufferedSocket(_fd, _loop, 16384, client_max_output_buffer_size),
TimeoutMonitor(_loop),
partition(_partition),
playlist(partition.playlist), player_control(&partition.pc),
playlist(partition.playlist), player_control(partition.pc),
permission(getDefaultPermissions()),
uid(_uid),
num(_num),
......
......@@ -30,7 +30,7 @@
#define CLIENT_LIST_MODE_END "command_list_end"
static enum command_return
client_process_command_list(Client *client, bool list_ok,
client_process_command_list(Client &client, bool list_ok,
std::list<std::string> &&list)
{
enum command_return ret = COMMAND_RETURN_OK;
......@@ -42,7 +42,7 @@ client_process_command_list(Client *client, bool list_ok,
FormatDebug(client_domain, "process command \"%s\"", cmd);
ret = command_process(client, num++, cmd);
FormatDebug(client_domain, "command returned %i", ret);
if (ret != COMMAND_RETURN_OK || client->IsExpired())
if (ret != COMMAND_RETURN_OK || client.IsExpired())
break;
else if (list_ok)
client_puts(client, "list_OK\n");
......@@ -52,14 +52,14 @@ client_process_command_list(Client *client, bool list_ok,
}
enum command_return
client_process_line(Client *client, char *line)
client_process_line(Client &client, char *line)
{
enum command_return ret;
if (strcmp(line, "noidle") == 0) {
if (client->idle_waiting) {
if (client.idle_waiting) {
/* send empty idle response and leave idle mode */
client->idle_waiting = false;
client.idle_waiting = false;
command_success(client);
}
......@@ -68,44 +68,44 @@ client_process_line(Client *client, char *line)
client_idle_notify(), which he can now evaluate */
return COMMAND_RETURN_OK;
} else if (client->idle_waiting) {
} else if (client.idle_waiting) {
/* during idle mode, clients must not send anything
except "noidle" */
FormatWarning(client_domain,
"[%u] command \"%s\" during idle",
client->num, line);
client.num, line);
return COMMAND_RETURN_CLOSE;
}
if (client->cmd_list.IsActive()) {
if (client.cmd_list.IsActive()) {
if (strcmp(line, CLIENT_LIST_MODE_END) == 0) {
FormatDebug(client_domain,
"[%u] process command list",
client->num);
client.num);
auto &&cmd_list = client->cmd_list.Commit();
auto &&cmd_list = client.cmd_list.Commit();
ret = client_process_command_list(client,
client->cmd_list.IsOKMode(),
client.cmd_list.IsOKMode(),
std::move(cmd_list));
FormatDebug(client_domain,
"[%u] process command "
"list returned %i", client->num, ret);
"list returned %i", client.num, ret);
if (ret == COMMAND_RETURN_CLOSE ||
client->IsExpired())
client.IsExpired())
return COMMAND_RETURN_CLOSE;
if (ret == COMMAND_RETURN_OK)
command_success(client);
client->cmd_list.Reset();
client.cmd_list.Reset();
} else {
if (!client->cmd_list.Add(line)) {
if (!client.cmd_list.Add(line)) {
FormatWarning(client_domain,
"[%u] command list size "
"is larger than the max (%lu)",
client->num,
client.num,
(unsigned long)client_max_command_list_size);
return COMMAND_RETURN_CLOSE;
}
......@@ -114,22 +114,22 @@ client_process_line(Client *client, char *line)
}
} else {
if (strcmp(line, CLIENT_LIST_MODE_BEGIN) == 0) {
client->cmd_list.Begin(false);
client.cmd_list.Begin(false);
ret = COMMAND_RETURN_OK;
} else if (strcmp(line, CLIENT_LIST_OK_MODE_BEGIN) == 0) {
client->cmd_list.Begin(true);
client.cmd_list.Begin(true);
ret = COMMAND_RETURN_OK;
} else {
FormatDebug(client_domain,
"[%u] process command \"%s\"",
client->num, line);
client.num, line);
ret = command_process(client, 0, line);
FormatDebug(client_domain,
"[%u] command returned %i",
client->num, ret);
client.num, ret);
if (ret == COMMAND_RETURN_CLOSE ||
client->IsExpired())
client.IsExpired())
return COMMAND_RETURN_CLOSE;
if (ret == COMMAND_RETURN_OK)
......
......@@ -40,7 +40,7 @@ Client::OnSocketInput(void *data, size_t length)
BufferedSocket::ConsumeInput(newline + 1 - p);
enum command_return result = client_process_line(this, p);
enum command_return result = client_process_line(*this, p);
switch (result) {
case COMMAND_RETURN_OK:
case COMMAND_RETURN_IDLE:
......
......@@ -26,22 +26,21 @@
#include <string.h>
enum client_subscribe_result
client_subscribe(Client *client, const char *channel)
client_subscribe(Client &client, const char *channel)
{
assert(client != nullptr);
assert(channel != nullptr);
if (!client_message_valid_channel_name(channel))
return CLIENT_SUBSCRIBE_INVALID;
if (client->num_subscriptions >= CLIENT_MAX_SUBSCRIPTIONS)
if (client.num_subscriptions >= CLIENT_MAX_SUBSCRIPTIONS)
return CLIENT_SUBSCRIBE_FULL;
auto r = client->subscriptions.insert(channel);
auto r = client.subscriptions.insert(channel);
if (!r.second)
return CLIENT_SUBSCRIBE_ALREADY;
++client->num_subscriptions;
++client.num_subscriptions;
idle_add(IDLE_SUBSCRIPTION);
......@@ -49,44 +48,42 @@ client_subscribe(Client *client, const char *channel)
}
bool
client_unsubscribe(Client *client, const char *channel)
client_unsubscribe(Client &client, const char *channel)
{
const auto i = client->subscriptions.find(channel);
if (i == client->subscriptions.end())
const auto i = client.subscriptions.find(channel);
if (i == client.subscriptions.end())
return false;
assert(client->num_subscriptions > 0);
assert(client.num_subscriptions > 0);
client->subscriptions.erase(i);
--client->num_subscriptions;
client.subscriptions.erase(i);
--client.num_subscriptions;
idle_add(IDLE_SUBSCRIPTION);
assert((client->num_subscriptions == 0) ==
client->subscriptions.empty());
assert((client.num_subscriptions == 0) ==
client.subscriptions.empty());
return true;
}
void
client_unsubscribe_all(Client *client)
client_unsubscribe_all(Client &client)
{
client->subscriptions.clear();
client->num_subscriptions = 0;
client.subscriptions.clear();
client.num_subscriptions = 0;
}
bool
client_push_message(Client *client, const ClientMessage &msg)
client_push_message(Client &client, const ClientMessage &msg)
{
assert(client != nullptr);
if (client->messages.size() >= CLIENT_MAX_MESSAGES ||
!client->IsSubscribed(msg.GetChannel()))
if (client.messages.size() >= CLIENT_MAX_MESSAGES ||
!client.IsSubscribed(msg.GetChannel()))
return false;
if (client->messages.empty())
client->IdleAdd(IDLE_MESSAGE);
if (client.messages.empty())
client.IdleAdd(IDLE_MESSAGE);
client->messages.push_back(msg);
client.messages.push_back(msg);
return true;
}
......@@ -40,15 +40,15 @@ enum client_subscribe_result {
};
enum client_subscribe_result
client_subscribe(Client *client, const char *channel);
client_subscribe(Client &client, const char *channel);
bool
client_unsubscribe(Client *client, const char *channel);
client_unsubscribe(Client &client, const char *channel);
void
client_unsubscribe_all(Client *client);
client_unsubscribe_all(Client &client);
bool
client_push_message(Client *client, const ClientMessage &msg);
client_push_message(Client &client, const ClientMessage &msg);
#endif
......@@ -27,23 +27,23 @@
* Write a block of data to the client.
*/
static void
client_write(Client *client, const char *data, size_t length)
client_write(Client &client, const char *data, size_t length)
{
/* if the client is going to be closed, do nothing */
if (client->IsExpired() || length == 0)
if (client.IsExpired() || length == 0)
return;
client->Write(data, length);
client.Write(data, length);
}
void
client_puts(Client *client, const char *s)
client_puts(Client &client, const char *s)
{
client_write(client, s, strlen(s));
}
void
client_vprintf(Client *client, const char *fmt, va_list args)
client_vprintf(Client &client, const char *fmt, va_list args)
{
char *p = FormatNewV(fmt, args);
client_write(client, p, strlen(p));
......@@ -51,7 +51,7 @@ client_vprintf(Client *client, const char *fmt, va_list args)
}
void
client_printf(Client *client, const char *fmt, ...)
client_printf(Client &client, const char *fmt, ...)
{
va_list args;
......
......@@ -30,7 +30,7 @@
#include <errno.h>
enum command_return
print_playlist_result(Client *client, enum playlist_result result)
print_playlist_result(Client &client, enum playlist_result result)
{
switch (result) {
case PLAYLIST_RESULT_SUCCESS:
......@@ -89,9 +89,8 @@ print_playlist_result(Client *client, enum playlist_result result)
}
enum command_return
print_error(Client *client, const Error &error)
print_error(Client &client, const Error &error)
{
assert(client != NULL);
assert(error.IsDefined());
LogError(error);
......
......@@ -27,12 +27,12 @@ class Client;
class Error;
enum command_return
print_playlist_result(Client *client, enum playlist_result result);
print_playlist_result(Client &client, enum playlist_result result);
/**
* Send the #Error to the client.
*/
enum command_return
print_error(Client *client, const Error &error);
print_error(Client &client, const Error &error);
#endif
......@@ -35,7 +35,7 @@
#include <string.h>
enum command_return
handle_lsinfo2(Client *client, int argc, char *argv[])
handle_lsinfo2(Client &client, int argc, char *argv[])
{
const char *uri;
......@@ -55,7 +55,7 @@ handle_lsinfo2(Client *client, int argc, char *argv[])
}
static enum command_return
handle_match(Client *client, int argc, char *argv[], bool fold_case)
handle_match(Client &client, int argc, char *argv[], bool fold_case)
{
SongFilter filter;
if (!filter.Parse(argc - 1, argv + 1, fold_case)) {
......@@ -72,19 +72,19 @@ handle_match(Client *client, int argc, char *argv[], bool fold_case)
}
enum command_return
handle_find(Client *client, int argc, char *argv[])
handle_find(Client &client, int argc, char *argv[])
{
return handle_match(client, argc, argv, false);
}
enum command_return
handle_search(Client *client, int argc, char *argv[])
handle_search(Client &client, int argc, char *argv[])
{
return handle_match(client, argc, argv, true);
}
static enum command_return
handle_match_add(Client *client, int argc, char *argv[], bool fold_case)
handle_match_add(Client &client, int argc, char *argv[], bool fold_case)
{
SongFilter filter;
if (!filter.Parse(argc - 1, argv + 1, fold_case)) {
......@@ -94,25 +94,25 @@ handle_match_add(Client *client, int argc, char *argv[], bool fold_case)
const DatabaseSelection selection("", true, &filter);
Error error;
return AddFromDatabase(client->partition, selection, error)
return AddFromDatabase(client.partition, selection, error)
? COMMAND_RETURN_OK
: print_error(client, error);
}
enum command_return
handle_findadd(Client *client, int argc, char *argv[])
handle_findadd(Client &client, int argc, char *argv[])
{
return handle_match_add(client, argc, argv, false);
}
enum command_return
handle_searchadd(Client *client, int argc, char *argv[])
handle_searchadd(Client &client, int argc, char *argv[])
{
return handle_match_add(client, argc, argv, true);
}
enum command_return
handle_searchaddpl(Client *client, int argc, char *argv[])
handle_searchaddpl(Client &client, int argc, char *argv[])
{
const char *playlist = argv[1];
......@@ -129,7 +129,7 @@ handle_searchaddpl(Client *client, int argc, char *argv[])
}
enum command_return
handle_count(Client *client, int argc, char *argv[])
handle_count(Client &client, int argc, char *argv[])
{
SongFilter filter;
if (!filter.Parse(argc - 1, argv + 1, false)) {
......@@ -144,7 +144,7 @@ handle_count(Client *client, int argc, char *argv[])
}
enum command_return
handle_listall(Client *client, gcc_unused int argc, char *argv[])
handle_listall(Client &client, gcc_unused int argc, char *argv[])
{
const char *directory = "";
......@@ -158,7 +158,7 @@ handle_listall(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_list(Client *client, int argc, char *argv[])
handle_list(Client &client, int argc, char *argv[])
{
unsigned tagType = locate_parse_type(argv[1]);
......@@ -207,7 +207,7 @@ handle_list(Client *client, int argc, char *argv[])
}
enum command_return
handle_listallinfo(Client *client, gcc_unused int argc, char *argv[])
handle_listallinfo(Client &client, gcc_unused int argc, char *argv[])
{
const char *directory = "";
......
......@@ -25,33 +25,33 @@
class Client;
enum command_return
handle_lsinfo2(Client *client, int argc, char *argv[]);
handle_lsinfo2(Client &client, int argc, char *argv[]);
enum command_return
handle_find(Client *client, int argc, char *argv[]);
handle_find(Client &client, int argc, char *argv[]);
enum command_return
handle_findadd(Client *client, int argc, char *argv[]);
handle_findadd(Client &client, int argc, char *argv[]);
enum command_return
handle_search(Client *client, int argc, char *argv[]);
handle_search(Client &client, int argc, char *argv[]);
enum command_return
handle_searchadd(Client *client, int argc, char *argv[]);
handle_searchadd(Client &client, int argc, char *argv[]);
enum command_return
handle_searchaddpl(Client *client, int argc, char *argv[]);
handle_searchaddpl(Client &client, int argc, char *argv[]);
enum command_return
handle_count(Client *client, int argc, char *argv[]);
handle_count(Client &client, int argc, char *argv[]);
enum command_return
handle_listall(Client *client, int argc, char *argv[]);
handle_listall(Client &client, int argc, char *argv[]);
enum command_return
handle_list(Client *client, int argc, char *argv[]);
handle_list(Client &client, int argc, char *argv[]);
enum command_return
handle_listallinfo(Client *client, int argc, char *argv[]);
handle_listallinfo(Client &client, int argc, char *argv[]);
#endif
......@@ -30,7 +30,7 @@ static bool
AddSong(const char *playlist_path_utf8,
Song &song, Error &error)
{
return spl_append_song(playlist_path_utf8, &song, error);
return spl_append_song(playlist_path_utf8, song, error);
}
bool
......
......@@ -34,7 +34,7 @@
#include <functional>
static bool
PrintDirectoryBrief(Client *client, const Directory &directory)
PrintDirectoryBrief(Client &client, const Directory &directory)
{
if (!directory.IsRoot())
client_printf(client, "directory: %s\n", directory.GetPath());
......@@ -43,7 +43,7 @@ PrintDirectoryBrief(Client *client, const Directory &directory)
}
static bool
PrintDirectoryFull(Client *client, const Directory &directory)
PrintDirectoryFull(Client &client, const Directory &directory)
{
if (!directory.IsRoot()) {
client_printf(client, "directory: %s\n", directory.GetPath());
......@@ -55,7 +55,7 @@ PrintDirectoryFull(Client *client, const Directory &directory)
static void
print_playlist_in_directory(Client *client,
print_playlist_in_directory(Client &client,
const Directory &directory,
const char *name_utf8)
{
......@@ -67,11 +67,11 @@ print_playlist_in_directory(Client *client,
}
static bool
PrintSongBrief(Client *client, Song &song)
PrintSongBrief(Client &client, const Song &song)
{
assert(song.parent != nullptr);
song_print_uri(client, &song);
song_print_uri(client, song);
if (song.tag != nullptr && song.tag->has_playlist)
/* this song file has an embedded CUE sheet */
......@@ -81,11 +81,11 @@ PrintSongBrief(Client *client, Song &song)
}
static bool
PrintSongFull(Client *client, Song &song)
PrintSongFull(Client &client, const Song &song)
{
assert(song.parent != nullptr);
song_print_info(client, &song);
song_print_info(client, song);
if (song.tag != nullptr && song.tag->has_playlist)
/* this song file has an embedded CUE sheet */
......@@ -95,7 +95,7 @@ PrintSongFull(Client *client, Song &song)
}
static bool
PrintPlaylistBrief(Client *client,
PrintPlaylistBrief(Client &client,
const PlaylistInfo &playlist,
const Directory &directory)
{
......@@ -104,7 +104,7 @@ PrintPlaylistBrief(Client *client,
}
static bool
PrintPlaylistFull(Client *client,
PrintPlaylistFull(Client &client,
const PlaylistInfo &playlist,
const Directory &directory)
{
......@@ -117,7 +117,7 @@ PrintPlaylistFull(Client *client,
}
bool
db_selection_print(Client *client, const DatabaseSelection &selection,
db_selection_print(Client &client, const DatabaseSelection &selection,
bool full, Error &error)
{
const Database *db = GetDatabase(error);
......@@ -127,13 +127,13 @@ db_selection_print(Client *client, const DatabaseSelection &selection,
using namespace std::placeholders;
const auto d = selection.filter == nullptr
? std::bind(full ? PrintDirectoryFull : PrintDirectoryBrief,
client, _1)
std::ref(client), _1)
: VisitDirectory();
const auto s = std::bind(full ? PrintSongFull : PrintSongBrief,
client, _1);
std::ref(client), _1);
const auto p = selection.filter == nullptr
? std::bind(full ? PrintPlaylistFull : PrintPlaylistBrief,
client, _1, _2)
std::ref(client), _1, _2)
: VisitPlaylist();
return db->Visit(selection, d, s, p, error);
......@@ -144,7 +144,7 @@ struct SearchStats {
unsigned long playTime;
};
static void printSearchStats(Client *client, SearchStats *stats)
static void printSearchStats(Client &client, SearchStats *stats)
{
client_printf(client, "songs: %i\n", stats->numberOfSongs);
client_printf(client, "playtime: %li\n", stats->playTime);
......@@ -160,7 +160,7 @@ stats_visitor_song(SearchStats &stats, Song &song)
}
bool
searchStatsForSongsIn(Client *client, const char *name,
searchStatsForSongsIn(Client &client, const char *name,
const SongFilter *filter,
Error &error)
{
......@@ -185,14 +185,14 @@ searchStatsForSongsIn(Client *client, const char *name,
}
bool
printAllIn(Client *client, const char *uri_utf8, Error &error)
printAllIn(Client &client, const char *uri_utf8, Error &error)
{
const DatabaseSelection selection(uri_utf8, true);
return db_selection_print(client, selection, false, error);
}
bool
printInfoForAllIn(Client *client, const char *uri_utf8,
printInfoForAllIn(Client &client, const char *uri_utf8,
Error &error)
{
const DatabaseSelection selection(uri_utf8, true);
......@@ -200,15 +200,15 @@ printInfoForAllIn(Client *client, const char *uri_utf8,
}
static bool
PrintSongURIVisitor(Client *client, Song &song)
PrintSongURIVisitor(Client &client, Song &song)
{
song_print_uri(client, &song);
song_print_uri(client, song);
return true;
}
static bool
PrintUniqueTag(Client *client, enum tag_type tag_type,
PrintUniqueTag(Client &client, enum tag_type tag_type,
const char *value)
{
client_printf(client, "%s: %s\n", tag_item_names[tag_type], value);
......@@ -216,7 +216,7 @@ PrintUniqueTag(Client *client, enum tag_type tag_type,
}
bool
listAllUniqueTags(Client *client, int type,
listAllUniqueTags(Client &client, int type,
const SongFilter *filter,
Error &error)
{
......@@ -228,11 +228,12 @@ listAllUniqueTags(Client *client, int type,
if (type == LOCATE_TAG_FILE_TYPE) {
using namespace std::placeholders;
const auto f = std::bind(PrintSongURIVisitor, client, _1);
const auto f = std::bind(PrintSongURIVisitor,
std::ref(client), _1);
return db->Visit(selection, f, error);
} else {
using namespace std::placeholders;
const auto f = std::bind(PrintUniqueTag, client,
const auto f = std::bind(PrintUniqueTag, std::ref(client),
(enum tag_type)type, _1);
return db->VisitUniqueTags(selection, (enum tag_type)type,
f, error);
......
......@@ -28,29 +28,27 @@ struct db_visitor;
class Client;
class Error;
gcc_nonnull(1)
bool
db_selection_print(Client *client, const DatabaseSelection &selection,
db_selection_print(Client &client, const DatabaseSelection &selection,
bool full, Error &error);
gcc_nonnull(1,2)
gcc_nonnull(2)
bool
printAllIn(Client *client, const char *uri_utf8, Error &error);
printAllIn(Client &client, const char *uri_utf8, Error &error);
gcc_nonnull(1,2)
gcc_nonnull(2)
bool
printInfoForAllIn(Client *client, const char *uri_utf8,
printInfoForAllIn(Client &client, const char *uri_utf8,
Error &error);
gcc_nonnull(1,2)
gcc_nonnull(2)
bool
searchStatsForSongsIn(Client *client, const char *name,
searchStatsForSongsIn(Client &client, const char *name,
const SongFilter *filter,
Error &error);
gcc_nonnull(1)
bool
listAllUniqueTags(Client *client, int type,
listAllUniqueTags(Client &client, int type,
const SongFilter *filter,
Error &error);
......
......@@ -49,10 +49,8 @@ enum {
};
void
db_save_internal(FILE *fp, const Directory *music_root)
db_save_internal(FILE *fp, const Directory &music_root)
{
assert(music_root != nullptr);
fprintf(fp, "%s\n", DIRECTORY_INFO_BEGIN);
fprintf(fp, DB_FORMAT_PREFIX "%u\n", DB_FORMAT);
fprintf(fp, "%s%s\n", DIRECTORY_MPD_VERSION, VERSION);
......@@ -68,7 +66,7 @@ db_save_internal(FILE *fp, const Directory *music_root)
}
bool
db_load_internal(TextFile &file, Directory *music_root, Error &error)
db_load_internal(TextFile &file, Directory &music_root, Error &error)
{
char *line;
int format = 0;
......@@ -76,8 +74,6 @@ db_load_internal(TextFile &file, Directory *music_root, Error &error)
bool success;
bool tags[TAG_NUM_OF_ITEM_TYPES];
assert(music_root != nullptr);
/* get initial info */
line = file.ReadLine();
if (line == nullptr || strcmp(DIRECTORY_INFO_BEGIN, line) != 0) {
......
......@@ -27,9 +27,9 @@ class TextFile;
class Error;
void
db_save_internal(FILE *file, const Directory *root);
db_save_internal(FILE *file, const Directory &root);
bool
db_load_internal(TextFile &file, Directory *root, Error &error);
db_load_internal(TextFile &file, Directory &root, Error &error);
#endif
......@@ -42,17 +42,17 @@ decoder::~decoder()
* one.
*/
static DecoderCommand
need_chunks(struct decoder_control *dc, bool do_wait)
need_chunks(decoder_control &dc, bool do_wait)
{
if (dc->command == DecoderCommand::STOP ||
dc->command == DecoderCommand::SEEK)
return dc->command;
if (dc.command == DecoderCommand::STOP ||
dc.command == DecoderCommand::SEEK)
return dc.command;
if (do_wait) {
dc->Wait();
dc->client_cond.signal();
dc.Wait();
dc.client_cond.signal();
return dc->command;
return dc.command;
}
return DecoderCommand::NONE;
......@@ -61,7 +61,7 @@ need_chunks(struct decoder_control *dc, bool do_wait)
struct music_chunk *
decoder_get_chunk(struct decoder *decoder)
{
struct decoder_control *dc = decoder->dc;
decoder_control &dc = decoder->dc;
DecoderCommand cmd;
assert(decoder != nullptr);
......@@ -70,7 +70,7 @@ decoder_get_chunk(struct decoder *decoder)
return decoder->chunk;
do {
decoder->chunk = dc->buffer->Allocate();
decoder->chunk = dc.buffer->Allocate();
if (decoder->chunk != nullptr) {
decoder->chunk->replay_gain_serial =
decoder->replay_gain_serial;
......@@ -81,9 +81,9 @@ decoder_get_chunk(struct decoder *decoder)
return decoder->chunk;
}
dc->Lock();
dc.Lock();
cmd = need_chunks(dc, true);
dc->Unlock();
dc.Unlock();
} while (cmd == DecoderCommand::NONE);
return nullptr;
......@@ -92,15 +92,15 @@ decoder_get_chunk(struct decoder *decoder)
void
decoder_flush_chunk(struct decoder *decoder)
{
struct decoder_control *dc = decoder->dc;
decoder_control &dc = decoder->dc;
assert(decoder != nullptr);
assert(decoder->chunk != nullptr);
if (decoder->chunk->IsEmpty())
dc->buffer->Return(decoder->chunk);
dc.buffer->Return(decoder->chunk);
else
dc->pipe->Push(decoder->chunk);
dc.pipe->Push(decoder->chunk);
decoder->chunk = nullptr;
}
......@@ -24,11 +24,12 @@
#include "pcm/PcmConvert.hxx"
#include "ReplayGainInfo.hxx"
struct decoder_control;
struct input_stream;
struct Tag;
struct decoder {
struct decoder_control *dc;
decoder_control &dc;
PcmConvert conv_state;
......@@ -82,7 +83,7 @@ struct decoder {
*/
unsigned replay_gain_serial;
decoder(decoder_control *_dc, bool _initial_seek_pending, Tag *_tag)
decoder(decoder_control &_dc, bool _initial_seek_pending, Tag *_tag)
:dc(_dc),
timestamp(0),
initial_seek_pending(_initial_seek_pending),
......
......@@ -149,7 +149,7 @@ decoder_plugin_from_suffix(const char *suffix,
decoder_plugins[i] != nullptr; ++i) {
plugin = decoder_plugins[i];
if (decoder_plugins_enabled[i] &&
decoder_plugin_supports_suffix(plugin, suffix))
decoder_plugin_supports_suffix(*plugin, suffix))
return plugin;
}
......@@ -169,7 +169,7 @@ decoder_plugin_from_mime_type(const char *mimeType, unsigned int next)
for (; decoder_plugins[i] != nullptr; ++i) {
const struct decoder_plugin *plugin = decoder_plugins[i];
if (decoder_plugins_enabled[i] &&
decoder_plugin_supports_mime_type(plugin, mimeType)) {
decoder_plugin_supports_mime_type(*plugin, mimeType)) {
++i;
return plugin;
}
......@@ -217,9 +217,9 @@ void decoder_plugin_init_all(void)
struct config_param empty;
for (unsigned i = 0; decoder_plugins[i] != nullptr; ++i) {
const struct decoder_plugin *plugin = decoder_plugins[i];
const decoder_plugin &plugin = *decoder_plugins[i];
const struct config_param *param =
decoder_plugin_config(plugin->name);
decoder_plugin_config(plugin.name);
if (param == nullptr)
param = &empty;
......@@ -235,5 +235,5 @@ void decoder_plugin_init_all(void)
void decoder_plugin_deinit_all(void)
{
decoder_plugins_for_each_enabled(plugin)
decoder_plugin_finish(plugin);
decoder_plugin_finish(*plugin);
}
......@@ -24,24 +24,22 @@
#include <assert.h>
bool
decoder_plugin_supports_suffix(const struct decoder_plugin *plugin,
decoder_plugin_supports_suffix(const decoder_plugin &plugin,
const char *suffix)
{
assert(plugin != nullptr);
assert(suffix != nullptr);
return plugin->suffixes != nullptr &&
string_array_contains(plugin->suffixes, suffix);
return plugin.suffixes != nullptr &&
string_array_contains(plugin.suffixes, suffix);
}
bool
decoder_plugin_supports_mime_type(const struct decoder_plugin *plugin,
decoder_plugin_supports_mime_type(const decoder_plugin &plugin,
const char *mime_type)
{
assert(plugin != nullptr);
assert(mime_type != nullptr);
return plugin->mime_types != nullptr &&
string_array_contains(plugin->mime_types, mime_type);
return plugin.mime_types != nullptr &&
string_array_contains(plugin.mime_types, mime_type);
}
......@@ -111,11 +111,11 @@ struct decoder_plugin {
* the plugin is not available
*/
static inline bool
decoder_plugin_init(const struct decoder_plugin *plugin,
decoder_plugin_init(const decoder_plugin &plugin,
const config_param &param)
{
return plugin->init != nullptr
? plugin->init(param)
return plugin.init != nullptr
? plugin.init(param)
: true;
}
......@@ -123,42 +123,42 @@ decoder_plugin_init(const struct decoder_plugin *plugin,
* Deinitialize a decoder plugin which was initialized successfully.
*/
static inline void
decoder_plugin_finish(const struct decoder_plugin *plugin)
decoder_plugin_finish(const decoder_plugin &plugin)
{
if (plugin->finish != nullptr)
plugin->finish();
if (plugin.finish != nullptr)
plugin.finish();
}
/**
* Decode a stream.
*/
static inline void
decoder_plugin_stream_decode(const struct decoder_plugin *plugin,
decoder_plugin_stream_decode(const decoder_plugin &plugin,
struct decoder *decoder, struct input_stream *is)
{
plugin->stream_decode(decoder, is);
plugin.stream_decode(decoder, is);
}
/**
* Decode a file.
*/
static inline void
decoder_plugin_file_decode(const struct decoder_plugin *plugin,
decoder_plugin_file_decode(const decoder_plugin &plugin,
struct decoder *decoder, const char *path_fs)
{
plugin->file_decode(decoder, path_fs);
plugin.file_decode(decoder, path_fs);
}
/**
* Read the tag of a file.
*/
static inline bool
decoder_plugin_scan_file(const struct decoder_plugin *plugin,
decoder_plugin_scan_file(const decoder_plugin &plugin,
const char *path_fs,
const struct tag_handler *handler, void *handler_ctx)
{
return plugin->scan_file != nullptr
? plugin->scan_file(path_fs, handler, handler_ctx)
return plugin.scan_file != nullptr
? plugin.scan_file(path_fs, handler, handler_ctx)
: false;
}
......@@ -166,13 +166,13 @@ decoder_plugin_scan_file(const struct decoder_plugin *plugin,
* Read the tag of a stream.
*/
static inline bool
decoder_plugin_scan_stream(const struct decoder_plugin *plugin,
decoder_plugin_scan_stream(const decoder_plugin &plugin,
struct input_stream *is,
const struct tag_handler *handler,
void *handler_ctx)
{
return plugin->scan_stream != nullptr
? plugin->scan_stream(is, handler, handler_ctx)
return plugin.scan_stream != nullptr
? plugin.scan_stream(is, handler, handler_ctx)
: false;
}
......@@ -180,25 +180,25 @@ decoder_plugin_scan_stream(const struct decoder_plugin *plugin,
* return "virtual" tracks in a container
*/
static inline char *
decoder_plugin_container_scan( const struct decoder_plugin *plugin,
decoder_plugin_container_scan( const decoder_plugin &plugin,
const char* pathname,
const unsigned int tnum)
{
return plugin->container_scan(pathname, tnum);
return plugin.container_scan(pathname, tnum);
}
/**
* Does the plugin announce the specified file name suffix?
*/
bool
decoder_plugin_supports_suffix(const struct decoder_plugin *plugin,
decoder_plugin_supports_suffix(const decoder_plugin &plugin,
const char *suffix);
/**
* Does the plugin announce the specified MIME type?
*/
bool
decoder_plugin_supports_mime_type(const struct decoder_plugin *plugin,
decoder_plugin_supports_mime_type(const decoder_plugin &plugin,
const char *mime_type);
#endif
......@@ -26,7 +26,7 @@
#include <assert.h>
static void
decoder_plugin_print(Client *client,
decoder_plugin_print(Client &client,
const struct decoder_plugin *plugin)
{
const char *const*p;
......@@ -46,7 +46,7 @@ decoder_plugin_print(Client *client,
}
void
decoder_list_print(Client *client)
decoder_list_print(Client &client)
{
decoder_plugins_for_each_enabled(plugin)
decoder_plugin_print(client, plugin);
......
......@@ -23,6 +23,6 @@
class Client;
void
decoder_list_print(Client *client);
decoder_list_print(Client &client);
#endif
......@@ -23,6 +23,6 @@
struct decoder_control;
void
decoder_thread_start(struct decoder_control *dc);
decoder_thread_start(decoder_control &dc);
#endif
......@@ -70,11 +70,11 @@ Directory::Directory(const char *_path)
Directory::~Directory()
{
Song *song, *ns;
directory_for_each_song_safe(song, ns, this)
directory_for_each_song_safe(song, ns, *this)
song->Free();
Directory *child, *n;
directory_for_each_child_safe(child, n, this)
directory_for_each_child_safe(child, n, *this)
child->Free();
}
......@@ -153,7 +153,7 @@ Directory::FindChild(const char *name) const
assert(holding_db_lock());
const Directory *child;
directory_for_each_child(child, this)
directory_for_each_child(child, *this)
if (strcmp(child->GetName(), name) == 0)
return child;
......@@ -166,7 +166,7 @@ Directory::PruneEmpty()
assert(holding_db_lock());
Directory *child, *n;
directory_for_each_child_safe(child, n, this) {
directory_for_each_child_safe(child, n, *this) {
child->PruneEmpty();
if (child->IsEmpty())
......@@ -235,7 +235,7 @@ Directory::FindSong(const char *name_utf8) const
assert(name_utf8 != nullptr);
Song *song;
directory_for_each_song(song, this) {
directory_for_each_song(song, *this) {
assert(song->parent == this);
if (strcmp(song->uri, name_utf8) == 0)
......@@ -293,7 +293,7 @@ Directory::Sort()
song_list_sort(&songs);
Directory *child;
directory_for_each_child(child, this)
directory_for_each_child(child, *this)
child->Sort();
}
......@@ -307,7 +307,7 @@ Directory::Walk(bool recursive, const SongFilter *filter,
if (visit_song) {
Song *song;
directory_for_each_song(song, this)
directory_for_each_song(song, *this)
if ((filter == nullptr || filter->Match(*song)) &&
!visit_song(*song, error))
return false;
......@@ -320,7 +320,7 @@ Directory::Walk(bool recursive, const SongFilter *filter,
}
Directory *child;
directory_for_each_child(child, this) {
directory_for_each_child(child, *this) {
if (visit_directory &&
!visit_directory(*child, error))
return false;
......
......@@ -32,16 +32,16 @@
#define DEVICE_CONTAINER (dev_t)(-2)
#define directory_for_each_child(pos, directory) \
list_for_each_entry(pos, &directory->children, siblings)
list_for_each_entry(pos, &(directory).children, siblings)
#define directory_for_each_child_safe(pos, n, directory) \
list_for_each_entry_safe(pos, n, &directory->children, siblings)
list_for_each_entry_safe(pos, n, &(directory).children, siblings)
#define directory_for_each_song(pos, directory) \
list_for_each_entry(pos, &directory->songs, siblings)
list_for_each_entry(pos, &(directory).songs, siblings)
#define directory_for_each_song_safe(pos, n, directory) \
list_for_each_entry_safe(pos, n, &directory->songs, siblings)
list_for_each_entry_safe(pos, n, &(directory).songs, siblings)
struct Song;
struct db_visitor;
......
......@@ -40,13 +40,13 @@
static constexpr Domain directory_domain("directory");
void
directory_save(FILE *fp, const Directory *directory)
directory_save(FILE *fp, const Directory &directory)
{
if (!directory->IsRoot()) {
if (!directory.IsRoot()) {
fprintf(fp, DIRECTORY_MTIME "%lu\n",
(unsigned long)directory->mtime);
(unsigned long)directory.mtime);
fprintf(fp, "%s%s\n", DIRECTORY_BEGIN, directory->GetPath());
fprintf(fp, "%s%s\n", DIRECTORY_BEGIN, directory.GetPath());
}
Directory *cur;
......@@ -56,7 +56,7 @@ directory_save(FILE *fp, const Directory *directory)
fprintf(fp, DIRECTORY_DIR "%s\n", base);
g_free(base);
directory_save(fp, cur);
directory_save(fp, *cur);
if (ferror(fp))
return;
......@@ -64,27 +64,27 @@ directory_save(FILE *fp, const Directory *directory)
Song *song;
directory_for_each_song(song, directory)
song_save(fp, song);
song_save(fp, *song);
playlist_vector_save(fp, directory->playlists);
playlist_vector_save(fp, directory.playlists);
if (!directory->IsRoot())
fprintf(fp, DIRECTORY_END "%s\n", directory->GetPath());
if (!directory.IsRoot())
fprintf(fp, DIRECTORY_END "%s\n", directory.GetPath());
}
static Directory *
directory_load_subdir(TextFile &file, Directory *parent, const char *name,
directory_load_subdir(TextFile &file, Directory &parent, const char *name,
Error &error)
{
bool success;
if (parent->FindChild(name) != nullptr) {
if (parent.FindChild(name) != nullptr) {
error.Format(directory_domain,
"Duplicate subdirectory '%s'", name);
return nullptr;
}
Directory *directory = parent->CreateChild(name);
Directory *directory = parent.CreateChild(name);
const char *line = file.ReadLine();
if (line == nullptr) {
......@@ -112,7 +112,7 @@ directory_load_subdir(TextFile &file, Directory *parent, const char *name,
return nullptr;
}
success = directory_load(file, directory, error);
success = directory_load(file, *directory, error);
if (!success) {
directory->Delete();
return nullptr;
......@@ -122,7 +122,7 @@ directory_load_subdir(TextFile &file, Directory *parent, const char *name,
}
bool
directory_load(TextFile &file, Directory *directory, Error &error)
directory_load(TextFile &file, Directory &directory, Error &error)
{
const char *line;
......@@ -139,24 +139,24 @@ directory_load(TextFile &file, Directory *directory, Error &error)
const char *name = line + sizeof(SONG_BEGIN) - 1;
Song *song;
if (directory->FindSong(name) != nullptr) {
if (directory.FindSong(name) != nullptr) {
error.Format(directory_domain,
"Duplicate song '%s'", name);
return false;
}
song = song_load(file, directory, name, error);
song = song_load(file, &directory, name, error);
if (song == nullptr)
return false;
directory->AddSong(song);
directory.AddSong(song);
} else if (g_str_has_prefix(line, PLAYLIST_META_BEGIN)) {
/* duplicate the name, because
playlist_metadata_load() will overwrite the
buffer */
char *name = g_strdup(line + sizeof(PLAYLIST_META_BEGIN) - 1);
if (!playlist_metadata_load(file, directory->playlists,
if (!playlist_metadata_load(file, directory.playlists,
name, error)) {
g_free(name);
return false;
......
......@@ -27,9 +27,9 @@ class TextFile;
class Error;
void
directory_save(FILE *fp, const Directory *directory);
directory_save(FILE *fp, const Directory &directory);
bool
directory_load(TextFile &file, Directory *directory, Error &error);
directory_load(TextFile &file, Directory &directory, Error &error);
#endif
......@@ -446,7 +446,7 @@ int mpd_main(int argc, char *argv[])
initialize_decoder_and_player();
volume_init();
initAudioConfig();
audio_output_all_init(&instance->partition->pc);
audio_output_all_init(instance->partition->pc);
client_manager_init();
replay_gain_global_init();
......
......@@ -170,18 +170,18 @@ map_uri_fs(const char *uri)
}
AllocatedPath
map_directory_fs(const Directory *directory)
map_directory_fs(const Directory &directory)
{
assert(!music_dir_fs.IsNull());
if (directory->IsRoot())
if (directory.IsRoot())
return music_dir_fs;
return map_uri_fs(directory->GetPath());
return map_uri_fs(directory.GetPath());
}
AllocatedPath
map_directory_child_fs(const Directory *directory, const char *name)
map_directory_child_fs(const Directory &directory, const char *name)
{
assert(!music_dir_fs.IsNull());
......@@ -217,16 +217,16 @@ map_detached_song_fs(const char *uri_utf8)
}
AllocatedPath
map_song_fs(const Song *song)
map_song_fs(const Song &song)
{
assert(song->IsFile());
assert(song.IsFile());
if (song->IsInDatabase())
return song->IsDetached()
? map_detached_song_fs(song->uri)
: map_directory_child_fs(song->parent, song->uri);
if (song.IsInDatabase())
return song.IsDetached()
? map_detached_song_fs(song.uri)
: map_directory_child_fs(*song.parent, song.uri);
else
return AllocatedPath::FromUTF8(song->uri);
return AllocatedPath::FromUTF8(song.uri);
}
std::string
......
......@@ -91,7 +91,7 @@ map_uri_fs(const char *uri);
*/
gcc_pure
AllocatedPath
map_directory_fs(const Directory *directory);
map_directory_fs(const Directory &directory);
/**
* Determines the file system path of a directory's child (may be a
......@@ -103,7 +103,7 @@ map_directory_fs(const Directory *directory);
*/
gcc_pure
AllocatedPath
map_directory_child_fs(const Directory *directory, const char *name);
map_directory_child_fs(const Directory &directory, const char *name);
/**
* Determines the file system path of a song. This must not be a
......@@ -114,7 +114,7 @@ map_directory_child_fs(const Directory *directory, const char *name);
*/
gcc_pure
AllocatedPath
map_song_fs(const Song *song);
map_song_fs(const Song &song);
/**
* Maps a file system path (relative to the music directory or
......
......@@ -33,7 +33,7 @@
#include <assert.h>
enum command_return
handle_subscribe(Client *client, gcc_unused int argc, char *argv[])
handle_subscribe(Client &client, gcc_unused int argc, char *argv[])
{
assert(argc == 2);
......@@ -62,7 +62,7 @@ handle_subscribe(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_unsubscribe(Client *client, gcc_unused int argc, char *argv[])
handle_unsubscribe(Client &client, gcc_unused int argc, char *argv[])
{
assert(argc == 2);
......@@ -76,7 +76,7 @@ handle_unsubscribe(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_channels(Client *client,
handle_channels(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
assert(argc == 1);
......@@ -93,24 +93,24 @@ handle_channels(Client *client,
}
enum command_return
handle_read_messages(Client *client,
handle_read_messages(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
assert(argc == 1);
while (!client->messages.empty()) {
const ClientMessage &msg = client->messages.front();
while (!client.messages.empty()) {
const ClientMessage &msg = client.messages.front();
client_printf(client, "channel: %s\nmessage: %s\n",
msg.GetChannel(), msg.GetMessage());
client->messages.pop_front();
client.messages.pop_front();
}
return COMMAND_RETURN_OK;
}
enum command_return
handle_send_message(Client *client,
handle_send_message(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
assert(argc == 3);
......@@ -124,7 +124,7 @@ handle_send_message(Client *client,
bool sent = false;
const ClientMessage msg(argv[1], argv[2]);
for (const auto &c : *instance->client_list)
if (client_push_message(c, msg))
if (client_push_message(*c, msg))
sent = true;
if (sent)
......
......@@ -25,18 +25,18 @@
class Client;
enum command_return
handle_subscribe(Client *client, int argc, char *argv[]);
handle_subscribe(Client &client, int argc, char *argv[]);
enum command_return
handle_unsubscribe(Client *client, int argc, char *argv[]);
handle_unsubscribe(Client &client, int argc, char *argv[]);
enum command_return
handle_channels(Client *client, int argc, char *argv[]);
handle_channels(Client &client, int argc, char *argv[]);
enum command_return
handle_read_messages(Client *client, int argc, char *argv[]);
handle_read_messages(Client &client, int argc, char *argv[]);
enum command_return
handle_send_message(Client *client, int argc, char *argv[]);
handle_send_message(Client &client, int argc, char *argv[]);
#endif
......@@ -53,7 +53,7 @@
#include <string.h>
static void
print_spl_list(Client *client, const PlaylistVector &list)
print_spl_list(Client &client, const PlaylistVector &list)
{
for (const auto &i : list) {
client_printf(client, "playlist: %s\n", i.name.c_str());
......@@ -64,7 +64,7 @@ print_spl_list(Client *client, const PlaylistVector &list)
}
enum command_return
handle_urlhandlers(Client *client,
handle_urlhandlers(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
if (client_is_local(client))
......@@ -74,7 +74,7 @@ handle_urlhandlers(Client *client,
}
enum command_return
handle_decoders(Client *client,
handle_decoders(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
decoder_list_print(client);
......@@ -82,7 +82,7 @@ handle_decoders(Client *client,
}
enum command_return
handle_tagtypes(Client *client,
handle_tagtypes(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
tag_print_types(client);
......@@ -90,21 +90,21 @@ handle_tagtypes(Client *client,
}
enum command_return
handle_kill(gcc_unused Client *client,
handle_kill(gcc_unused Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
return COMMAND_RETURN_KILL;
}
enum command_return
handle_close(gcc_unused Client *client,
handle_close(gcc_unused Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
return COMMAND_RETURN_CLOSE;
}
enum command_return
handle_lsinfo(Client *client, int argc, char *argv[])
handle_lsinfo(Client &client, int argc, char *argv[])
{
const char *uri;
......@@ -136,7 +136,7 @@ handle_lsinfo(Client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR;
}
song_print_info(client, song);
song_print_info(client, *song);
song->Free();
return COMMAND_RETURN_OK;
}
......@@ -155,7 +155,7 @@ handle_lsinfo(Client *client, int argc, char *argv[])
}
enum command_return
handle_update(Client *client, gcc_unused int argc, char *argv[])
handle_update(Client &client, gcc_unused int argc, char *argv[])
{
const char *path = "";
unsigned ret;
......@@ -186,7 +186,7 @@ handle_update(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_rescan(Client *client, gcc_unused int argc, char *argv[])
handle_rescan(Client &client, gcc_unused int argc, char *argv[])
{
const char *path = "";
unsigned ret;
......@@ -214,7 +214,7 @@ handle_rescan(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_setvol(Client *client, gcc_unused int argc, char *argv[])
handle_setvol(Client &client, gcc_unused int argc, char *argv[])
{
unsigned level;
bool success;
......@@ -238,7 +238,7 @@ handle_setvol(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_stats(Client *client,
handle_stats(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
stats_print(client);
......@@ -246,14 +246,14 @@ handle_stats(Client *client,
}
enum command_return
handle_ping(gcc_unused Client *client,
handle_ping(gcc_unused Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
return COMMAND_RETURN_OK;
}
enum command_return
handle_password(Client *client, gcc_unused int argc, char *argv[])
handle_password(Client &client, gcc_unused int argc, char *argv[])
{
unsigned permission = 0;
......@@ -268,7 +268,7 @@ handle_password(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_config(Client *client,
handle_config(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
if (!client_is_local(client)) {
......@@ -285,7 +285,7 @@ handle_config(Client *client,
}
enum command_return
handle_idle(Client *client,
handle_idle(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
unsigned flags = 0, j;
......@@ -309,7 +309,7 @@ handle_idle(Client *client,
flags = ~0;
/* enable "idle" mode on this client */
client->IdleWait(flags);
client.IdleWait(flags);
return COMMAND_RETURN_IDLE;
}
......@@ -25,45 +25,45 @@
class Client;
enum command_return
handle_urlhandlers(Client *client, int argc, char *argv[]);
handle_urlhandlers(Client &client, int argc, char *argv[]);
enum command_return
handle_decoders(Client *client, int argc, char *argv[]);
handle_decoders(Client &client, int argc, char *argv[]);
enum command_return
handle_tagtypes(Client *client, int argc, char *argv[]);
handle_tagtypes(Client &client, int argc, char *argv[]);
enum command_return
handle_kill(Client *client, int argc, char *argv[]);
handle_kill(Client &client, int argc, char *argv[]);
enum command_return
handle_close(Client *client, int argc, char *argv[]);
handle_close(Client &client, int argc, char *argv[]);
enum command_return
handle_lsinfo(Client *client, int argc, char *argv[]);
handle_lsinfo(Client &client, int argc, char *argv[]);
enum command_return
handle_update(Client *client, int argc, char *argv[]);
handle_update(Client &client, int argc, char *argv[]);
enum command_return
handle_rescan(Client *client, int argc, char *argv[]);
handle_rescan(Client &client, int argc, char *argv[]);
enum command_return
handle_setvol(Client *client, int argc, char *argv[]);
handle_setvol(Client &client, int argc, char *argv[]);
enum command_return
handle_stats(Client *client, int argc, char *argv[]);
handle_stats(Client &client, int argc, char *argv[]);
enum command_return
handle_ping(Client *client, int argc, char *argv[]);
handle_ping(Client &client, int argc, char *argv[]);
enum command_return
handle_password(Client *client, int argc, char *argv[]);
handle_password(Client &client, int argc, char *argv[]);
enum command_return
handle_config(Client *client, int argc, char *argv[]);
handle_config(Client &client, int argc, char *argv[]);
enum command_return
handle_idle(Client *client, int argc, char *argv[]);
handle_idle(Client &client, int argc, char *argv[]);
#endif
......@@ -103,7 +103,7 @@ audio_output_config_count(void)
}
void
audio_output_all_init(struct player_control *pc)
audio_output_all_init(player_control &pc)
{
const struct config_param *param = nullptr;
unsigned int i;
......@@ -469,17 +469,17 @@ audio_output_all_check(void)
}
bool
audio_output_all_wait(struct player_control *pc, unsigned threshold)
audio_output_all_wait(player_control &pc, unsigned threshold)
{
pc->Lock();
pc.Lock();
if (audio_output_all_check() < threshold) {
pc->Unlock();
pc.Unlock();
return true;
}
pc->Wait();
pc->Unlock();
pc.Wait();
pc.Unlock();
return audio_output_all_check() < threshold;
}
......
......@@ -40,7 +40,7 @@ class Error;
* file and initialize them.
*/
void
audio_output_all_init(struct player_control *pc);
audio_output_all_init(player_control &pc);
/**
* Global finalization: free memory occupied by audio outputs. All
......@@ -135,7 +135,7 @@ audio_output_all_check(void);
* @return true if there are less than #threshold chunks in the pipe
*/
bool
audio_output_all_wait(struct player_control *pc, unsigned threshold);
audio_output_all_wait(player_control &pc, unsigned threshold);
/**
* Puts all audio outputs into pause mode. Most implementations will
......
......@@ -27,7 +27,7 @@
#include <string.h>
enum command_return
handle_enableoutput(Client *client, gcc_unused int argc, char *argv[])
handle_enableoutput(Client &client, gcc_unused int argc, char *argv[])
{
unsigned device;
bool ret;
......@@ -46,7 +46,7 @@ handle_enableoutput(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_disableoutput(Client *client, gcc_unused int argc, char *argv[])
handle_disableoutput(Client &client, gcc_unused int argc, char *argv[])
{
unsigned device;
bool ret;
......@@ -65,7 +65,7 @@ handle_disableoutput(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_toggleoutput(Client *client, gcc_unused int argc, char *argv[])
handle_toggleoutput(Client &client, gcc_unused int argc, char *argv[])
{
unsigned device;
if (!check_unsigned(client, &device, argv[1]))
......@@ -81,7 +81,7 @@ handle_toggleoutput(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_devices(Client *client,
handle_devices(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
printAudioDevices(client);
......
......@@ -25,15 +25,15 @@
class Client;
enum command_return
handle_enableoutput(Client *client, int argc, char *argv[]);
handle_enableoutput(Client &client, int argc, char *argv[]);
enum command_return
handle_disableoutput(Client *client, int argc, char *argv[]);
handle_disableoutput(Client &client, int argc, char *argv[]);
enum command_return
handle_toggleoutput(Client *client, int argc, char *argv[]);
handle_toggleoutput(Client &client, int argc, char *argv[]);
enum command_return
handle_devices(Client *client, int argc, char *argv[]);
handle_devices(Client &client, int argc, char *argv[]);
#endif
......@@ -281,7 +281,7 @@ audio_output_setup(struct audio_output *ao, const config_param &param,
struct audio_output *
audio_output_new(const config_param &param,
struct player_control *pc,
player_control &pc,
Error &error)
{
const struct audio_output_plugin *plugin;
......@@ -324,6 +324,6 @@ audio_output_new(const config_param &param,
return nullptr;
}
ao->player_control = pc;
ao->player_control = &pc;
return ao;
}
......@@ -264,7 +264,7 @@ audio_output_command_is_finished(const struct audio_output *ao)
struct audio_output *
audio_output_new(const config_param &param,
struct player_control *pc,
player_control &pc,
Error &error);
bool
......
......@@ -29,7 +29,7 @@
#include "Client.hxx"
void
printAudioDevices(Client *client)
printAudioDevices(Client &client)
{
const unsigned n = audio_output_count();
......
/*
* Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
......@@ -28,6 +29,6 @@
class Client;
void
printAudioDevices(Client *client);
printAudioDevices(Client &client);
#endif
......@@ -53,46 +53,46 @@
#define COMMAND_STATUS_UPDATING_DB "updating_db"
enum command_return
handle_play(Client *client, int argc, char *argv[])
handle_play(Client &client, int argc, char *argv[])
{
int song = -1;
if (argc == 2 && !check_int(client, &song, argv[1]))
return COMMAND_RETURN_ERROR;
enum playlist_result result = client->partition.PlayPosition(song);
enum playlist_result result = client.partition.PlayPosition(song);
return print_playlist_result(client, result);
}
enum command_return
handle_playid(Client *client, int argc, char *argv[])
handle_playid(Client &client, int argc, char *argv[])
{
int id = -1;
if (argc == 2 && !check_int(client, &id, argv[1]))
return COMMAND_RETURN_ERROR;
enum playlist_result result = client->partition.PlayId(id);
enum playlist_result result = client.partition.PlayId(id);
return print_playlist_result(client, result);
}
enum command_return
handle_stop(Client *client,
handle_stop(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
client->partition.Stop();
client.partition.Stop();
return COMMAND_RETURN_OK;
}
enum command_return
handle_currentsong(Client *client,
handle_currentsong(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
playlist_print_current(client, &client->playlist);
playlist_print_current(client, client.playlist);
return COMMAND_RETURN_OK;
}
enum command_return
handle_pause(Client *client,
handle_pause(Client &client,
int argc, char *argv[])
{
if (argc == 2) {
......@@ -100,22 +100,22 @@ handle_pause(Client *client,
if (!check_bool(client, &pause_flag, argv[1]))
return COMMAND_RETURN_ERROR;
client->player_control->SetPause(pause_flag);
client.player_control.SetPause(pause_flag);
} else
client->player_control->Pause();
client.player_control.Pause();
return COMMAND_RETURN_OK;
}
enum command_return
handle_status(Client *client,
handle_status(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
const char *state = NULL;
int updateJobId;
int song;
const auto player_status = client->player_control->GetStatus();
const auto player_status = client.player_control.GetStatus();
switch (player_status.state) {
case PlayerState::STOP:
......@@ -129,7 +129,7 @@ handle_status(Client *client,
break;
}
const playlist &playlist = client->playlist;
const playlist &playlist = client.playlist;
client_printf(client,
"volume: %i\n"
COMMAND_STATUS_REPEAT ": %i\n"
......@@ -149,9 +149,9 @@ handle_status(Client *client,
playlist.GetConsume(),
(unsigned long)playlist.GetVersion(),
playlist.GetLength(),
(int)(client->player_control->GetCrossFade() + 0.5),
client->player_control->GetMixRampDb(),
client->player_control->GetMixRampDelay(),
(int)(client.player_control.GetCrossFade() + 0.5),
client.player_control.GetMixRampDb(),
client.player_control.GetMixRampDelay(),
state);
song = playlist.GetCurrentPosition();
......@@ -188,7 +188,7 @@ handle_status(Client *client,
updateJobId);
}
Error error = client->player_control->LockGetError();
Error error = client.player_control.LockGetError();
if (error.IsDefined())
client_printf(client,
COMMAND_STATUS_ERROR ": %s\n",
......@@ -206,85 +206,85 @@ handle_status(Client *client,
}
enum command_return
handle_next(Client *client,
handle_next(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
playlist &playlist = client->playlist;
playlist &playlist = client.playlist;
/* single mode is not considered when this is user who
* wants to change song. */
const bool single = playlist.queue.single;
playlist.queue.single = false;
client->partition.PlayNext();
client.partition.PlayNext();
playlist.queue.single = single;
return COMMAND_RETURN_OK;
}
enum command_return
handle_previous(Client *client,
handle_previous(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
client->partition.PlayPrevious();
client.partition.PlayPrevious();
return COMMAND_RETURN_OK;
}
enum command_return
handle_repeat(Client *client, gcc_unused int argc, char *argv[])
handle_repeat(Client &client, gcc_unused int argc, char *argv[])
{
bool status;
if (!check_bool(client, &status, argv[1]))
return COMMAND_RETURN_ERROR;
client->partition.SetRepeat(status);
client.partition.SetRepeat(status);
return COMMAND_RETURN_OK;
}
enum command_return
handle_single(Client *client, gcc_unused int argc, char *argv[])
handle_single(Client &client, gcc_unused int argc, char *argv[])
{
bool status;
if (!check_bool(client, &status, argv[1]))
return COMMAND_RETURN_ERROR;
client->partition.SetSingle(status);
client.partition.SetSingle(status);
return COMMAND_RETURN_OK;
}
enum command_return
handle_consume(Client *client, gcc_unused int argc, char *argv[])
handle_consume(Client &client, gcc_unused int argc, char *argv[])
{
bool status;
if (!check_bool(client, &status, argv[1]))
return COMMAND_RETURN_ERROR;
client->partition.SetConsume(status);
client.partition.SetConsume(status);
return COMMAND_RETURN_OK;
}
enum command_return
handle_random(Client *client, gcc_unused int argc, char *argv[])
handle_random(Client &client, gcc_unused int argc, char *argv[])
{
bool status;
if (!check_bool(client, &status, argv[1]))
return COMMAND_RETURN_ERROR;
client->partition.SetRandom(status);
audio_output_all_set_replay_gain_mode(replay_gain_get_real_mode(client->partition.GetRandom()));
client.partition.SetRandom(status);
audio_output_all_set_replay_gain_mode(replay_gain_get_real_mode(client.partition.GetRandom()));
return COMMAND_RETURN_OK;
}
enum command_return
handle_clearerror(gcc_unused Client *client,
handle_clearerror(gcc_unused Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
client->player_control->ClearError();
client.player_control.ClearError();
return COMMAND_RETURN_OK;
}
enum command_return
handle_seek(Client *client, gcc_unused int argc, char *argv[])
handle_seek(Client &client, gcc_unused int argc, char *argv[])
{
unsigned song, seek_time;
......@@ -294,12 +294,12 @@ handle_seek(Client *client, gcc_unused int argc, char *argv[])
return COMMAND_RETURN_ERROR;
enum playlist_result result =
client->partition.SeekSongPosition(song, seek_time);
client.partition.SeekSongPosition(song, seek_time);
return print_playlist_result(client, result);
}
enum command_return
handle_seekid(Client *client, gcc_unused int argc, char *argv[])
handle_seekid(Client &client, gcc_unused int argc, char *argv[])
{
unsigned id, seek_time;
......@@ -309,12 +309,12 @@ handle_seekid(Client *client, gcc_unused int argc, char *argv[])
return COMMAND_RETURN_ERROR;
enum playlist_result result =
client->partition.SeekSongId(id, seek_time);
client.partition.SeekSongId(id, seek_time);
return print_playlist_result(client, result);
}
enum command_return
handle_seekcur(Client *client, gcc_unused int argc, char *argv[])
handle_seekcur(Client &client, gcc_unused int argc, char *argv[])
{
const char *p = argv[1];
bool relative = *p == '+' || *p == '-';
......@@ -323,48 +323,48 @@ handle_seekcur(Client *client, gcc_unused int argc, char *argv[])
return COMMAND_RETURN_ERROR;
enum playlist_result result =
client->partition.SeekCurrent(seek_time, relative);
client.partition.SeekCurrent(seek_time, relative);
return print_playlist_result(client, result);
}
enum command_return
handle_crossfade(Client *client, gcc_unused int argc, char *argv[])
handle_crossfade(Client &client, gcc_unused int argc, char *argv[])
{
unsigned xfade_time;
if (!check_unsigned(client, &xfade_time, argv[1]))
return COMMAND_RETURN_ERROR;
client->player_control->SetCrossFade(xfade_time);
client.player_control.SetCrossFade(xfade_time);
return COMMAND_RETURN_OK;
}
enum command_return
handle_mixrampdb(Client *client, gcc_unused int argc, char *argv[])
handle_mixrampdb(Client &client, gcc_unused int argc, char *argv[])
{
float db;
if (!check_float(client, &db, argv[1]))
return COMMAND_RETURN_ERROR;
client->player_control->SetMixRampDb(db);
client.player_control.SetMixRampDb(db);
return COMMAND_RETURN_OK;
}
enum command_return
handle_mixrampdelay(Client *client, gcc_unused int argc, char *argv[])
handle_mixrampdelay(Client &client, gcc_unused int argc, char *argv[])
{
float delay_secs;
if (!check_float(client, &delay_secs, argv[1]))
return COMMAND_RETURN_ERROR;
client->player_control->SetMixRampDelay(delay_secs);
client.player_control.SetMixRampDelay(delay_secs);
return COMMAND_RETURN_OK;
}
enum command_return
handle_replay_gain_mode(Client *client,
handle_replay_gain_mode(Client &client,
gcc_unused int argc, char *argv[])
{
if (!replay_gain_set_mode_string(argv[1])) {
......@@ -373,13 +373,13 @@ handle_replay_gain_mode(Client *client,
return COMMAND_RETURN_ERROR;
}
audio_output_all_set_replay_gain_mode(replay_gain_get_real_mode(client->playlist.queue.random));
audio_output_all_set_replay_gain_mode(replay_gain_get_real_mode(client.playlist.queue.random));
return COMMAND_RETURN_OK;
}
enum command_return
handle_replay_gain_status(Client *client,
handle_replay_gain_status(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
client_printf(client, "replay_gain_mode: %s\n",
......
......@@ -25,66 +25,66 @@
class Client;
enum command_return
handle_play(Client *client, int argc, char *argv[]);
handle_play(Client &client, int argc, char *argv[]);
enum command_return
handle_playid(Client *client, int argc, char *argv[]);
handle_playid(Client &client, int argc, char *argv[]);
enum command_return
handle_stop(Client *client, int argc, char *argv[]);
handle_stop(Client &client, int argc, char *argv[]);
enum command_return
handle_currentsong(Client *client, int argc, char *argv[]);
handle_currentsong(Client &client, int argc, char *argv[]);
enum command_return
handle_pause(Client *client, int argc, char *argv[]);
handle_pause(Client &client, int argc, char *argv[]);
enum command_return
handle_status(Client *client, int argc, char *argv[]);
handle_status(Client &client, int argc, char *argv[]);
enum command_return
handle_next(Client *client, int argc, char *argv[]);
handle_next(Client &client, int argc, char *argv[]);
enum command_return
handle_previous(Client *client, int argc, char *avg[]);
handle_previous(Client &client, int argc, char *avg[]);
enum command_return
handle_repeat(Client *client, int argc, char *argv[]);
handle_repeat(Client &client, int argc, char *argv[]);
enum command_return
handle_single(Client *client, int argc, char *argv[]);
handle_single(Client &client, int argc, char *argv[]);
enum command_return
handle_consume(Client *client, int argc, char *argv[]);
handle_consume(Client &client, int argc, char *argv[]);
enum command_return
handle_random(Client *client, int argc, char *argv[]);
handle_random(Client &client, int argc, char *argv[]);
enum command_return
handle_clearerror(Client *client, int argc, char *argv[]);
handle_clearerror(Client &client, int argc, char *argv[]);
enum command_return
handle_seek(Client *client, int argc, char *argv[]);
handle_seek(Client &client, int argc, char *argv[]);
enum command_return
handle_seekid(Client *client, int argc, char *argv[]);
handle_seekid(Client &client, int argc, char *argv[]);
enum command_return
handle_seekcur(Client *client, int argc, char *argv[]);
handle_seekcur(Client &client, int argc, char *argv[]);
enum command_return
handle_crossfade(Client *client, int argc, char *argv[]);
handle_crossfade(Client &client, int argc, char *argv[]);
enum command_return
handle_mixrampdb(Client *client, int argc, char *argv[]);
handle_mixrampdb(Client &client, int argc, char *argv[]);
enum command_return
handle_mixrampdelay(Client *client, int argc, char *argv[]);
handle_mixrampdelay(Client &client, int argc, char *argv[]);
enum command_return
handle_replay_gain_mode(Client *client, int argc, char *argv[]);
handle_replay_gain_mode(Client &client, int argc, char *argv[]);
enum command_return
handle_replay_gain_status(Client *client, int argc, char *argv[]);
handle_replay_gain_status(Client &client, int argc, char *argv[]);
#endif
......@@ -445,7 +445,7 @@ Player::CheckDecoderStartup()
dc.Unlock();
if (output_open &&
!audio_output_all_wait(&pc, 1))
!audio_output_all_wait(pc, 1))
/* the output devices havn't finished playing
all chunks yet - wait for that */
return true;
......@@ -746,7 +746,7 @@ play_chunk(player_control &pc,
inline bool
Player::PlayNextChunk()
{
if (!audio_output_all_wait(&pc, 64))
if (!audio_output_all_wait(pc, 64))
/* the output pipe is still large enough, don't send
another chunk */
return true;
......@@ -1102,7 +1102,7 @@ player_task(void *arg)
player_control &pc = *(player_control *)arg;
decoder_control dc;
decoder_thread_start(&dc);
decoder_thread_start(dc);
MusicBuffer buffer(pc.buffer_chunks);
......
......@@ -50,42 +50,42 @@ playlist::TagChanged()
* Queue a song, addressed by its order number.
*/
static void
playlist_queue_song_order(struct playlist *playlist, struct player_control *pc,
playlist_queue_song_order(playlist &playlist, player_control &pc,
unsigned order)
{
assert(playlist->queue.IsValidOrder(order));
assert(playlist.queue.IsValidOrder(order));
playlist->queued = order;
playlist.queued = order;
Song *song = playlist->queue.GetOrder(order)->DupDetached();
Song *song = playlist.queue.GetOrder(order).DupDetached();
{
const auto uri = song->GetURI();
FormatDebug(playlist_domain, "queue song %i:\"%s\"",
playlist->queued, uri.c_str());
playlist.queued, uri.c_str());
}
pc->EnqueueSong(song);
pc.EnqueueSong(song);
}
/**
* Called if the player thread has started playing the "queued" song.
*/
static void
playlist_song_started(struct playlist *playlist, struct player_control *pc)
playlist_song_started(playlist &playlist, player_control &pc)
{
assert(pc->next_song == nullptr);
assert(playlist->queued >= -1);
assert(pc.next_song == nullptr);
assert(playlist.queued >= -1);
/* queued song has started: copy queued to current,
and notify the clients */
int current = playlist->current;
playlist->current = playlist->queued;
playlist->queued = -1;
int current = playlist.current;
playlist.current = playlist.queued;
playlist.queued = -1;
if(playlist->queue.consume)
playlist->DeleteOrder(*pc, current);
if(playlist.queue.consume)
playlist.DeleteOrder(pc, current);
idle_add(IDLE_PLAYER);
}
......@@ -94,7 +94,7 @@ const Song *
playlist::GetQueuedSong() const
{
return playing && queued >= 0
? queue.GetOrder(queued)
? &queue.GetOrder(queued)
: nullptr;
}
......@@ -127,7 +127,7 @@ playlist::UpdateQueuedSong(player_control &pc, const Song *prev)
}
const Song *const next_song = next_order >= 0
? queue.GetOrder(next_order)
? &queue.GetOrder(next_order)
: nullptr;
if (prev != nullptr && next_song != prev) {
......@@ -138,7 +138,7 @@ playlist::UpdateQueuedSong(player_control &pc, const Song *prev)
if (next_order >= 0) {
if (next_song != prev)
playlist_queue_song_order(this, &pc, next_order);
playlist_queue_song_order(*this, pc, next_order);
else
queued = next_order;
}
......@@ -150,7 +150,7 @@ playlist::PlayOrder(player_control &pc, int order)
playing = true;
queued = -1;
Song *song = queue.GetOrder(order)->DupDetached();
Song *song = queue.GetOrder(order).DupDetached();
{
const auto uri = song->GetURI();
......@@ -163,7 +163,7 @@ playlist::PlayOrder(player_control &pc, int order)
}
static void
playlist_resume_playback(struct playlist *playlist, struct player_control *pc);
playlist_resume_playback(playlist &playlist, player_control &pc);
void
playlist::SyncWithPlayer(player_control &pc)
......@@ -183,12 +183,12 @@ playlist::SyncWithPlayer(player_control &pc)
should be restarted with the next song. That can
happen if the playlist isn't filling the queue fast
enough */
playlist_resume_playback(this, &pc);
playlist_resume_playback(*this, pc);
else {
/* check if the player thread has already started
playing the queued song */
if (pc_next_song == nullptr && queued != -1)
playlist_song_started(this, &pc);
playlist_song_started(*this, pc);
pc.Lock();
pc_next_song = pc.next_song;
......@@ -206,26 +206,26 @@ playlist::SyncWithPlayer(player_control &pc)
* decide whether to re-start playback
*/
static void
playlist_resume_playback(struct playlist *playlist, struct player_control *pc)
playlist_resume_playback(playlist &playlist, player_control &pc)
{
assert(playlist->playing);
assert(pc->GetState() == PlayerState::STOP);
assert(playlist.playing);
assert(pc.GetState() == PlayerState::STOP);
const auto error = pc->GetErrorType();
const auto error = pc.GetErrorType();
if (error == PlayerError::NONE)
playlist->error_count = 0;
playlist.error_count = 0;
else
++playlist->error_count;
++playlist.error_count;
if ((playlist->stop_on_error && error != PlayerError::NONE) ||
if ((playlist.stop_on_error && error != PlayerError::NONE) ||
error == PlayerError::OUTPUT ||
playlist->error_count >= playlist->queue.GetLength())
playlist.error_count >= playlist.queue.GetLength())
/* too many errors, or critical error: stop
playback */
playlist->Stop(*pc);
playlist.Stop(pc);
else
/* continue playback at the next song */
playlist->PlayNext(*pc);
playlist.PlayNext(pc);
}
void
......@@ -246,13 +246,13 @@ playlist::SetRepeat(player_control &pc, bool status)
}
static void
playlist_order(struct playlist *playlist)
playlist_order(playlist &playlist)
{
if (playlist->current >= 0)
if (playlist.current >= 0)
/* update playlist.current, order==position now */
playlist->current = playlist->queue.OrderToPosition(playlist->current);
playlist.current = playlist.queue.OrderToPosition(playlist.current);
playlist->queue.RestoreOrder();
playlist.queue.RestoreOrder();
}
void
......@@ -310,7 +310,7 @@ playlist::SetRandom(player_control &pc, bool status)
} else
current = -1;
} else
playlist_order(this);
playlist_order(*this);
UpdateQueuedSong(pc, queued_song);
......
......@@ -39,7 +39,7 @@
#include <stdlib.h>
static void
print_spl_list(Client *client, const PlaylistVector &list)
print_spl_list(Client &client, const PlaylistVector &list)
{
for (const auto &i : list) {
client_printf(client, "playlist: %s\n", i.name.c_str());
......@@ -50,16 +50,16 @@ print_spl_list(Client *client, const PlaylistVector &list)
}
enum command_return
handle_save(Client *client, gcc_unused int argc, char *argv[])
handle_save(Client &client, gcc_unused int argc, char *argv[])
{
enum playlist_result result;
result = spl_save_playlist(argv[1], &client->playlist);
result = spl_save_playlist(argv[1], client.playlist);
return print_playlist_result(client, result);
}
enum command_return
handle_load(Client *client, int argc, char *argv[])
handle_load(Client &client, int argc, char *argv[])
{
unsigned start_index, end_index;
......@@ -73,13 +73,13 @@ handle_load(Client *client, int argc, char *argv[])
result = playlist_open_into_queue(argv[1],
start_index, end_index,
&client->playlist,
client->player_control, true);
client.playlist,
client.player_control, true);
if (result != PLAYLIST_RESULT_NO_SUCH_LIST)
return print_playlist_result(client, result);
Error error;
if (playlist_load_spl(&client->playlist, client->player_control,
if (playlist_load_spl(client.playlist, client.player_control,
argv[1], start_index, end_index,
error))
return COMMAND_RETURN_OK;
......@@ -99,7 +99,7 @@ handle_load(Client *client, int argc, char *argv[])
}
enum command_return
handle_listplaylist(Client *client, gcc_unused int argc, char *argv[])
handle_listplaylist(Client &client, gcc_unused int argc, char *argv[])
{
if (playlist_file_print(client, argv[1], false))
return COMMAND_RETURN_OK;
......@@ -111,7 +111,7 @@ handle_listplaylist(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_listplaylistinfo(Client *client,
handle_listplaylistinfo(Client &client,
gcc_unused int argc, char *argv[])
{
if (playlist_file_print(client, argv[1], true))
......@@ -124,7 +124,7 @@ handle_listplaylistinfo(Client *client,
}
enum command_return
handle_rm(Client *client, gcc_unused int argc, char *argv[])
handle_rm(Client &client, gcc_unused int argc, char *argv[])
{
Error error;
return spl_delete(argv[1], error)
......@@ -133,7 +133,7 @@ handle_rm(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_rename(Client *client, gcc_unused int argc, char *argv[])
handle_rename(Client &client, gcc_unused int argc, char *argv[])
{
Error error;
return spl_rename(argv[1], argv[2], error)
......@@ -142,7 +142,7 @@ handle_rename(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_playlistdelete(Client *client,
handle_playlistdelete(Client &client,
gcc_unused int argc, char *argv[]) {
char *playlist = argv[1];
unsigned from;
......@@ -157,7 +157,7 @@ handle_playlistdelete(Client *client,
}
enum command_return
handle_playlistmove(Client *client, gcc_unused int argc, char *argv[])
handle_playlistmove(Client &client, gcc_unused int argc, char *argv[])
{
char *playlist = argv[1];
unsigned from, to;
......@@ -174,7 +174,7 @@ handle_playlistmove(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_playlistclear(Client *client, gcc_unused int argc, char *argv[])
handle_playlistclear(Client &client, gcc_unused int argc, char *argv[])
{
Error error;
return spl_clear(argv[1], error)
......@@ -183,7 +183,7 @@ handle_playlistclear(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_playlistadd(Client *client, gcc_unused int argc, char *argv[])
handle_playlistadd(Client &client, gcc_unused int argc, char *argv[])
{
char *playlist = argv[1];
char *uri = argv[2];
......@@ -212,7 +212,7 @@ handle_playlistadd(Client *client, gcc_unused int argc, char *argv[])
}
enum command_return
handle_listplaylists(Client *client,
handle_listplaylists(Client &client,
gcc_unused int argc, gcc_unused char *argv[])
{
Error error;
......
......@@ -25,36 +25,36 @@
class Client;
enum command_return
handle_save(Client *client, int argc, char *argv[]);
handle_save(Client &client, int argc, char *argv[]);
enum command_return
handle_load(Client *client, int argc, char *argv[]);
handle_load(Client &client, int argc, char *argv[]);
enum command_return
handle_listplaylist(Client *client, int argc, char *argv[]);
handle_listplaylist(Client &client, int argc, char *argv[]);
enum command_return
handle_listplaylistinfo(Client *client, int argc, char *argv[]);
handle_listplaylistinfo(Client &client, int argc, char *argv[]);
enum command_return
handle_rm(Client *client, int argc, char *argv[]);
handle_rm(Client &client, int argc, char *argv[]);
enum command_return
handle_rename(Client *client, int argc, char *argv[]);
handle_rename(Client &client, int argc, char *argv[]);
enum command_return
handle_playlistdelete(Client *client, int argc, char *argv[]);
handle_playlistdelete(Client &client, int argc, char *argv[]);
enum command_return
handle_playlistmove(Client *client, int argc, char *argv[]);
handle_playlistmove(Client &client, int argc, char *argv[]);
enum command_return
handle_playlistclear(Client *client, int argc, char *argv[]);
handle_playlistclear(Client &client, int argc, char *argv[]);
enum command_return
handle_playlistadd(Client *client, int argc, char *argv[]);
handle_playlistadd(Client &client, int argc, char *argv[]);
enum command_return
handle_listplaylists(Client *client, int argc, char *argv[]);
handle_listplaylists(Client &client, int argc, char *argv[]);
#endif
......@@ -215,7 +215,7 @@ playlist::SeekSongPosition(player_control &pc, unsigned song, float seek_time)
queued_song = nullptr;
}
Song *the_song = queue.GetOrder(i)->DupDetached();
Song *the_song = queue.GetOrder(i).DupDetached();
if (!pc.Seek(the_song, seek_time)) {
UpdateQueuedSong(pc, queued_song);
......
......@@ -324,7 +324,7 @@ playlist::DeleteSong(struct player_control &pc, const struct Song &song)
{
for (int i = queue.GetLength() - 1; i >= 0; --i)
// TODO: compare URI instead of pointer
if (&song == queue.Get(i))
if (&song == &queue.Get(i))
DeletePosition(pc, i);
}
......
......@@ -365,7 +365,7 @@ spl_remove_index(const char *utf8path, unsigned pos, Error &error)
}
bool
spl_append_song(const char *utf8path, Song *song, Error &error)
spl_append_song(const char *utf8path, const Song &song, Error &error)
{
if (spl_map(error).IsNull())
return false;
......@@ -407,7 +407,7 @@ spl_append_uri(const char *url, const char *utf8file, Error &error)
{
if (uri_has_scheme(url)) {
Song *song = Song::NewRemote(url);
bool success = spl_append_song(utf8file, song, error);
bool success = spl_append_song(utf8file, *song, error);
song->Free();
return success;
} else {
......@@ -419,7 +419,7 @@ spl_append_uri(const char *url, const char *utf8file, Error &error)
if (song == nullptr)
return false;
bool success = spl_append_song(utf8file, song, error);
bool success = spl_append_song(utf8file, *song, error);
db->ReturnSong(song);
return success;
}
......
......@@ -69,7 +69,7 @@ bool
spl_remove_index(const char *utf8path, unsigned pos, Error &error);
bool
spl_append_song(const char *utf8path, Song *song, Error &error);
spl_append_song(const char *utf8path, const Song &song, Error &error);
bool
spl_append_uri(const char *file, const char *utf8file, Error &error);
......
......@@ -39,22 +39,22 @@
#include <glib.h>
void
playlist_print_uris(Client *client, const struct playlist *playlist)
playlist_print_uris(Client &client, const playlist &playlist)
{
const struct queue *queue = &playlist->queue;
const queue &queue = playlist.queue;
queue_print_uris(client, queue, 0, queue->GetLength());
queue_print_uris(client, queue, 0, queue.GetLength());
}
bool
playlist_print_info(Client *client, const struct playlist *playlist,
playlist_print_info(Client &client, const playlist &playlist,
unsigned start, unsigned end)
{
const struct queue *queue = &playlist->queue;
const queue &queue = playlist.queue;
if (end > queue->GetLength())
if (end > queue.GetLength())
/* correct the "end" offset */
end = queue->GetLength();
end = queue.GetLength();
if (start > end)
/* an invalid "start" offset is fatal */
......@@ -65,13 +65,12 @@ playlist_print_info(Client *client, const struct playlist *playlist,
}
bool
playlist_print_id(Client *client, const struct playlist *playlist,
playlist_print_id(Client &client, const playlist &playlist,
unsigned id)
{
const struct queue *queue = &playlist->queue;
int position;
position = queue->IdToPosition(id);
position = playlist.queue.IdToPosition(id);
if (position < 0)
/* no such song */
return false;
......@@ -80,42 +79,42 @@ playlist_print_id(Client *client, const struct playlist *playlist,
}
bool
playlist_print_current(Client *client, const struct playlist *playlist)
playlist_print_current(Client &client, const playlist &playlist)
{
int current_position = playlist->GetCurrentPosition();
int current_position = playlist.GetCurrentPosition();
if (current_position < 0)
return false;
queue_print_info(client, &playlist->queue,
queue_print_info(client, playlist.queue,
current_position, current_position + 1);
return true;
}
void
playlist_print_find(Client *client, const struct playlist *playlist,
playlist_print_find(Client &client, const playlist &playlist,
const SongFilter &filter)
{
queue_find(client, &playlist->queue, filter);
queue_find(client, playlist.queue, filter);
}
void
playlist_print_changes_info(Client *client,
const struct playlist *playlist,
playlist_print_changes_info(Client &client,
const playlist &playlist,
uint32_t version)
{
queue_print_changes_info(client, &playlist->queue, version);
queue_print_changes_info(client, playlist.queue, version);
}
void
playlist_print_changes_position(Client *client,
const struct playlist *playlist,
playlist_print_changes_position(Client &client,
const playlist &playlist,
uint32_t version)
{
queue_print_changes_position(client, &playlist->queue, version);
queue_print_changes_position(client, playlist.queue, version);
}
static bool
PrintSongDetails(Client *client, const char *uri_utf8)
PrintSongDetails(Client &client, const char *uri_utf8)
{
const Database *db = GetDatabase(IgnoreError());
if (db == nullptr)
......@@ -125,13 +124,13 @@ PrintSongDetails(Client *client, const char *uri_utf8)
if (song == nullptr)
return false;
song_print_info(client, song);
song_print_info(client, *song);
db->ReturnSong(song);
return true;
}
bool
spl_print(Client *client, const char *name_utf8, bool detail,
spl_print(Client &client, const char *name_utf8, bool detail,
Error &error)
{
PlaylistFileContents contents = LoadPlaylistFile(name_utf8, error);
......@@ -148,7 +147,7 @@ spl_print(Client *client, const char *name_utf8, bool detail,
}
static void
playlist_provider_print(Client *client, const char *uri,
playlist_provider_print(Client &client, const char *uri,
SongEnumerator &e, bool detail)
{
Song *song;
......@@ -160,9 +159,9 @@ playlist_provider_print(Client *client, const char *uri,
continue;
if (detail)
song_print_info(client, song);
song_print_info(client, *song);
else
song_print_uri(client, song);
song_print_uri(client, *song);
song->Free();
}
......@@ -171,7 +170,7 @@ playlist_provider_print(Client *client, const char *uri,
}
bool
playlist_file_print(Client *client, const char *uri, bool detail)
playlist_file_print(Client &client, const char *uri, bool detail)
{
Mutex mutex;
Cond cond;
......
/*
* Copyright (C) 2003-2012 The Music Player Daemon Project
* http://www.musicpd.org
......@@ -31,7 +32,7 @@ class Error;
* Sends the whole playlist to the client, song URIs only.
*/
void
playlist_print_uris(Client *client, const struct playlist *playlist);
playlist_print_uris(Client &client, const playlist &playlist);
/**
* Sends a range of the playlist to the client, including all known
......@@ -40,7 +41,7 @@ playlist_print_uris(Client *client, const struct playlist *playlist);
* This function however fails when the start offset is invalid.
*/
bool
playlist_print_info(Client *client, const struct playlist *playlist,
playlist_print_info(Client &client, const playlist &playlist,
unsigned start, unsigned end);
/**
......@@ -49,7 +50,7 @@ playlist_print_info(Client *client, const struct playlist *playlist,
* @return true on suite, false if there is no such song
*/
bool
playlist_print_id(Client *client, const struct playlist *playlist,
playlist_print_id(Client &client, const playlist &playlist,
unsigned id);
/**
......@@ -58,29 +59,29 @@ playlist_print_id(Client *client, const struct playlist *playlist,
* @return true on success, false if there is no current song
*/
bool
playlist_print_current(Client *client, const struct playlist *playlist);
playlist_print_current(Client &client, const playlist &playlist);
/**
* Find songs in the playlist.
*/
void
playlist_print_find(Client *client, const struct playlist *playlist,
playlist_print_find(Client &client, const playlist &playlist,
const SongFilter &filter);
/**
* Print detailed changes since the specified playlist version.
*/
void
playlist_print_changes_info(Client *client,
const struct playlist *playlist,
playlist_print_changes_info(Client &client,
const playlist &playlist,
uint32_t version);
/**
* Print changes since the specified playlist version, position only.
*/
void
playlist_print_changes_position(Client *client,
const struct playlist *playlist,
playlist_print_changes_position(Client &client,
const playlist &playlist,
uint32_t version);
/**
......@@ -92,7 +93,7 @@ playlist_print_changes_position(Client *client,
* @return true on success, false if the playlist does not exist
*/
bool
spl_print(Client *client, const char *name_utf8, bool detail,
spl_print(Client &client, const char *name_utf8, bool detail,
Error &error);
/**
......@@ -104,6 +105,6 @@ spl_print(Client *client, const char *name_utf8, bool detail,
* @return true on success, false if the playlist does not exist
*/
bool
playlist_file_print(Client *client, const char *uri, bool detail);
playlist_file_print(Client &client, const char *uri, bool detail);
#endif
......@@ -33,7 +33,7 @@
enum playlist_result
playlist_load_into_queue(const char *uri, SongEnumerator &e,
unsigned start_index, unsigned end_index,
struct playlist *dest, struct player_control *pc,
playlist &dest, player_control &pc,
bool secure)
{
enum playlist_result result;
......@@ -53,7 +53,7 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e,
if (song == nullptr)
continue;
result = dest->AppendSong(*pc, song);
result = dest.AppendSong(pc, song);
song->Free();
if (result != PLAYLIST_RESULT_SUCCESS) {
g_free(base_uri);
......@@ -69,7 +69,7 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e,
enum playlist_result
playlist_open_into_queue(const char *uri,
unsigned start_index, unsigned end_index,
struct playlist *dest, struct player_control *pc,
playlist &dest, player_control &pc,
bool secure)
{
Mutex mutex;
......
......@@ -42,7 +42,7 @@ struct player_control;
enum playlist_result
playlist_load_into_queue(const char *uri, SongEnumerator &e,
unsigned start_index, unsigned end_index,
struct playlist *dest, struct player_control *pc,
playlist &dest, player_control &pc,
bool secure);
/**
......@@ -52,7 +52,7 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e,
enum playlist_result
playlist_open_into_queue(const char *uri,
unsigned start_index, unsigned end_index,
struct playlist *dest, struct player_control *pc,
playlist &dest, player_control &pc,
bool secure);
#endif
......
......@@ -37,14 +37,14 @@
#include <string.h>
void
playlist_print_song(FILE *file, const Song *song)
playlist_print_song(FILE *file, const Song &song)
{
if (playlist_saveAbsolutePaths && song->IsInDatabase()) {
if (playlist_saveAbsolutePaths && song.IsInDatabase()) {
const auto path = map_song_fs(song);
if (!path.IsNull())
fprintf(file, "%s\n", path.c_str());
} else {
const auto uri_utf8 = song->GetURI();
const auto uri_utf8 = song.GetURI();
const auto uri_fs = AllocatedPath::FromUTF8(uri_utf8.c_str());
if (!uri_fs.IsNull())
......@@ -65,7 +65,7 @@ playlist_print_uri(FILE *file, const char *uri)
}
enum playlist_result
spl_save_queue(const char *name_utf8, const struct queue *queue)
spl_save_queue(const char *name_utf8, const queue &queue)
{
if (map_spl_path().IsNull())
return PLAYLIST_RESULT_DISABLED;
......@@ -85,8 +85,8 @@ spl_save_queue(const char *name_utf8, const struct queue *queue)
if (file == nullptr)
return PLAYLIST_RESULT_ERRNO;
for (unsigned i = 0; i < queue->GetLength(); i++)
playlist_print_song(file, queue->Get(i));
for (unsigned i = 0; i < queue.GetLength(); i++)
playlist_print_song(file, queue.Get(i));
fclose(file);
......@@ -95,13 +95,13 @@ spl_save_queue(const char *name_utf8, const struct queue *queue)
}
enum playlist_result
spl_save_playlist(const char *name_utf8, const struct playlist *playlist)
spl_save_playlist(const char *name_utf8, const playlist &playlist)
{
return spl_save_queue(name_utf8, &playlist->queue);
return spl_save_queue(name_utf8, playlist.queue);
}
bool
playlist_load_spl(struct playlist *playlist, struct player_control *pc,
playlist_load_spl(struct playlist &playlist, player_control &pc,
const char *name_utf8,
unsigned start_index, unsigned end_index,
Error &error)
......@@ -119,13 +119,13 @@ playlist_load_spl(struct playlist *playlist, struct player_control *pc,
if (memcmp(uri_utf8.c_str(), "file:///", 8) == 0) {
const char *path_utf8 = uri_utf8.c_str() + 7;
if (playlist->AppendFile(*pc, path_utf8) != PLAYLIST_RESULT_SUCCESS)
if (playlist.AppendFile(pc, path_utf8) != PLAYLIST_RESULT_SUCCESS)
FormatError(playlist_domain,
"can't add file \"%s\"", path_utf8);
continue;
}
if ((playlist->AppendURI(*pc, uri_utf8.c_str())) != PLAYLIST_RESULT_SUCCESS) {
if ((playlist.AppendURI(pc, uri_utf8.c_str())) != PLAYLIST_RESULT_SUCCESS) {
/* for windows compatibility, convert slashes */
char *temp2 = g_strdup(uri_utf8.c_str());
char *p = temp2;
......@@ -135,7 +135,7 @@ playlist_load_spl(struct playlist *playlist, struct player_control *pc,
p++;
}
if (playlist->AppendURI(*pc, temp2) != PLAYLIST_RESULT_SUCCESS)
if (playlist.AppendURI(pc, temp2) != PLAYLIST_RESULT_SUCCESS)
FormatError(playlist_domain,
"can't add file \"%s\"", temp2);
......
......@@ -31,7 +31,7 @@ struct player_control;
class Error;
void
playlist_print_song(FILE *fp, const Song *song);
playlist_print_song(FILE *fp, const Song &song);
void
playlist_print_uri(FILE *fp, const char *uri);
......@@ -40,20 +40,20 @@ playlist_print_uri(FILE *fp, const char *uri);
* Saves a queue object into a stored playlist file.
*/
enum playlist_result
spl_save_queue(const char *name_utf8, const struct queue *queue);
spl_save_queue(const char *name_utf8, const queue &queue);
/**
* Saves a playlist object into a stored playlist file.
*/
enum playlist_result
spl_save_playlist(const char *name_utf8, const struct playlist *playlist);
spl_save_playlist(const char *name_utf8, const playlist &playlist);
/**
* Loads a stored playlist file, and append all songs to the global
* playlist.
*/
bool
playlist_load_spl(struct playlist *playlist, struct player_control *pc,
playlist_load_spl(struct playlist &playlist, player_control &pc,
const char *name_utf8,
unsigned start_index, unsigned end_index,
Error &error);
......
......@@ -64,7 +64,7 @@ apply_song_metadata(Song *dest, const Song *src)
return dest;
if (dest->IsInDatabase()) {
const auto path_fs = map_song_fs(dest);
const auto path_fs = map_song_fs(*dest);
if (path_fs.IsNull())
return dest;
......
......@@ -59,14 +59,14 @@
#define PLAYLIST_BUFFER_SIZE 2*MPD_PATH_MAX
void
playlist_state_save(FILE *fp, const struct playlist *playlist,
struct player_control *pc)
playlist_state_save(FILE *fp, const struct playlist &playlist,
player_control &pc)
{
const auto player_status = pc->GetStatus();
const auto player_status = pc.GetStatus();
fputs(PLAYLIST_STATE_FILE_STATE, fp);
if (playlist->playing) {
if (playlist.playing) {
switch (player_status.state) {
case PlayerState::PAUSE:
fputs(PLAYLIST_STATE_FILE_STATE_PAUSE "\n", fp);
......@@ -75,35 +75,35 @@ playlist_state_save(FILE *fp, const struct playlist *playlist,
fputs(PLAYLIST_STATE_FILE_STATE_PLAY "\n", fp);
}
fprintf(fp, PLAYLIST_STATE_FILE_CURRENT "%i\n",
playlist->queue.OrderToPosition(playlist->current));
playlist.queue.OrderToPosition(playlist.current));
fprintf(fp, PLAYLIST_STATE_FILE_TIME "%i\n",
(int)player_status.elapsed_time);
} else {
fputs(PLAYLIST_STATE_FILE_STATE_STOP "\n", fp);
if (playlist->current >= 0)
if (playlist.current >= 0)
fprintf(fp, PLAYLIST_STATE_FILE_CURRENT "%i\n",
playlist->queue.OrderToPosition(playlist->current));
playlist.queue.OrderToPosition(playlist.current));
}
fprintf(fp, PLAYLIST_STATE_FILE_RANDOM "%i\n", playlist->queue.random);
fprintf(fp, PLAYLIST_STATE_FILE_REPEAT "%i\n", playlist->queue.repeat);
fprintf(fp, PLAYLIST_STATE_FILE_SINGLE "%i\n", playlist->queue.single);
fprintf(fp, PLAYLIST_STATE_FILE_RANDOM "%i\n", playlist.queue.random);
fprintf(fp, PLAYLIST_STATE_FILE_REPEAT "%i\n", playlist.queue.repeat);
fprintf(fp, PLAYLIST_STATE_FILE_SINGLE "%i\n", playlist.queue.single);
fprintf(fp, PLAYLIST_STATE_FILE_CONSUME "%i\n",
playlist->queue.consume);
playlist.queue.consume);
fprintf(fp, PLAYLIST_STATE_FILE_CROSSFADE "%i\n",
(int)pc->GetCrossFade());
(int)pc.GetCrossFade());
fprintf(fp, PLAYLIST_STATE_FILE_MIXRAMPDB "%f\n",
pc->GetMixRampDb());
pc.GetMixRampDb());
fprintf(fp, PLAYLIST_STATE_FILE_MIXRAMPDELAY "%f\n",
pc->GetMixRampDelay());
pc.GetMixRampDelay());
fputs(PLAYLIST_STATE_FILE_PLAYLIST_BEGIN "\n", fp);
queue_save(fp, &playlist->queue);
queue_save(fp, playlist.queue);
fputs(PLAYLIST_STATE_FILE_PLAYLIST_END "\n", fp);
}
static void
playlist_state_load(TextFile &file, struct playlist *playlist)
playlist_state_load(TextFile &file, struct playlist &playlist)
{
const char *line = file.ReadLine();
if (line == nullptr) {
......@@ -112,7 +112,7 @@ playlist_state_load(TextFile &file, struct playlist *playlist)
}
while (!g_str_has_prefix(line, PLAYLIST_STATE_FILE_PLAYLIST_END)) {
queue_load_song(file, line, &playlist->queue);
queue_load_song(file, line, playlist.queue);
line = file.ReadLine();
if (line == nullptr) {
......@@ -123,12 +123,12 @@ playlist_state_load(TextFile &file, struct playlist *playlist)
}
}
playlist->queue.IncrementVersion();
playlist.queue.IncrementVersion();
}
bool
playlist_state_restore(const char *line, TextFile &file,
struct playlist *playlist, struct player_control *pc)
struct playlist &playlist, player_control &pc)
{
int current = -1;
int seek_time = 0;
......@@ -150,24 +150,24 @@ playlist_state_restore(const char *line, TextFile &file,
while ((line = file.ReadLine()) != nullptr) {
if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_TIME)) {
seek_time =
atoi(&(line[strlen(PLAYLIST_STATE_FILE_TIME)]));
atoi(&(line[strlen(PLAYLIST_STATE_FILE_TIME)]));
} else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_REPEAT)) {
playlist->SetRepeat(*pc,
strcmp(&(line[strlen(PLAYLIST_STATE_FILE_REPEAT)]),
"1") == 0);
playlist.SetRepeat(pc,
strcmp(&(line[strlen(PLAYLIST_STATE_FILE_REPEAT)]),
"1") == 0);
} else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_SINGLE)) {
playlist->SetSingle(*pc,
strcmp(&(line[strlen(PLAYLIST_STATE_FILE_SINGLE)]),
"1") == 0);
playlist.SetSingle(pc,
strcmp(&(line[strlen(PLAYLIST_STATE_FILE_SINGLE)]),
"1") == 0);
} else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_CONSUME)) {
playlist->SetConsume(strcmp(&(line[strlen(PLAYLIST_STATE_FILE_CONSUME)]),
"1") == 0);
playlist.SetConsume(strcmp(&(line[strlen(PLAYLIST_STATE_FILE_CONSUME)]),
"1") == 0);
} else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_CROSSFADE)) {
pc->SetCrossFade(atoi(line + strlen(PLAYLIST_STATE_FILE_CROSSFADE)));
pc.SetCrossFade(atoi(line + strlen(PLAYLIST_STATE_FILE_CROSSFADE)));
} else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_MIXRAMPDB)) {
pc->SetMixRampDb(atof(line + strlen(PLAYLIST_STATE_FILE_MIXRAMPDB)));
pc.SetMixRampDb(atof(line + strlen(PLAYLIST_STATE_FILE_MIXRAMPDB)));
} else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_MIXRAMPDELAY)) {
pc->SetMixRampDelay(atof(line + strlen(PLAYLIST_STATE_FILE_MIXRAMPDELAY)));
pc.SetMixRampDelay(atof(line + strlen(PLAYLIST_STATE_FILE_MIXRAMPDELAY)));
} else if (g_str_has_prefix(line, PLAYLIST_STATE_FILE_RANDOM)) {
random_mode =
strcmp(line + strlen(PLAYLIST_STATE_FILE_RANDOM),
......@@ -182,10 +182,10 @@ playlist_state_restore(const char *line, TextFile &file,
}
}
playlist->SetRandom(*pc, random_mode);
playlist.SetRandom(pc, random_mode);
if (!playlist->queue.IsEmpty()) {
if (!playlist->queue.IsValidPosition(current))
if (!playlist.queue.IsEmpty()) {
if (!playlist.queue.IsValidPosition(current))
current = 0;
if (state == PlayerState::PLAY &&
......@@ -199,40 +199,40 @@ playlist_state_restore(const char *line, TextFile &file,
called here, after the audio output states were
restored, before playback begins */
if (state != PlayerState::STOP)
pc->UpdateAudio();
pc.UpdateAudio();
if (state == PlayerState::STOP /* && config_option */)
playlist->current = current;
playlist.current = current;
else if (seek_time == 0)
playlist->PlayPosition(*pc, current);
playlist.PlayPosition(pc, current);
else
playlist->SeekSongPosition(*pc, current, seek_time);
playlist.SeekSongPosition(pc, current, seek_time);
if (state == PlayerState::PAUSE)
pc->Pause();
pc.Pause();
}
return true;
}
unsigned
playlist_state_get_hash(const struct playlist *playlist,
struct player_control *pc)
playlist_state_get_hash(const playlist &playlist,
player_control &pc)
{
const auto player_status = pc->GetStatus();
const auto player_status = pc.GetStatus();
return playlist->queue.version ^
return playlist.queue.version ^
(player_status.state != PlayerState::STOP
? ((int)player_status.elapsed_time << 8)
: 0) ^
(playlist->current >= 0
? (playlist->queue.OrderToPosition(playlist->current) << 16)
(playlist.current >= 0
? (playlist.queue.OrderToPosition(playlist.current) << 16)
: 0) ^
((int)pc->GetCrossFade() << 20) ^
((int)pc.GetCrossFade() << 20) ^
(unsigned(player_status.state) << 24) ^
(playlist->queue.random << 27) ^
(playlist->queue.repeat << 28) ^
(playlist->queue.single << 29) ^
(playlist->queue.consume << 30) ^
(playlist->queue.random << 31);
(playlist.queue.random << 27) ^
(playlist.queue.repeat << 28) ^
(playlist.queue.single << 29) ^
(playlist.queue.consume << 30) ^
(playlist.queue.random << 31);
}
......@@ -32,12 +32,12 @@ struct player_control;
class TextFile;
void
playlist_state_save(FILE *fp, const struct playlist *playlist,
struct player_control *pc);
playlist_state_save(FILE *fp, const struct playlist &playlist,
player_control &pc);
bool
playlist_state_restore(const char *line, TextFile &file,
struct playlist *playlist, struct player_control *pc);
struct playlist &playlist, player_control &pc);
/**
* Generates a hash number for the current state of the playlist and
......@@ -46,7 +46,7 @@ playlist_state_restore(const char *line, TextFile &file,
* be saved.
*/
unsigned
playlist_state_get_hash(const struct playlist *playlist,
struct player_control *pc);
playlist_state_get_hash(const struct playlist &playlist,
player_control &c);
#endif
......@@ -232,9 +232,11 @@ queue::DeletePosition(unsigned position)
{
assert(position < length);
Song *song = Get(position);
assert(!song->IsInDatabase() || song->IsDetached());
song->Free();
{
Song &song = Get(position);
assert(!song.IsInDatabase() || song.IsDetached());
song.Free();
}
const unsigned id = PositionToId(position);
const unsigned _order = PositionToOrder(position);
......
......@@ -200,16 +200,16 @@ struct queue {
/**
* Returns the song at the specified position.
*/
Song *Get(unsigned position) const {
Song &Get(unsigned position) const {
assert(position < length);
return items[position].song;
return *items[position].song;
}
/**
* Returns the song at the specified order number.
*/
Song *GetOrder(unsigned _order) const {
Song &GetOrder(unsigned _order) const {
return Get(OrderToPosition(_order));
}
......
......@@ -25,60 +25,60 @@
class Client;
enum command_return
handle_add(Client *client, int argc, char *argv[]);
handle_add(Client &client, int argc, char *argv[]);
enum command_return
handle_addid(Client *client, int argc, char *argv[]);
handle_addid(Client &client, int argc, char *argv[]);
enum command_return
handle_delete(Client *client, int argc, char *argv[]);
handle_delete(Client &client, int argc, char *argv[]);
enum command_return
handle_deleteid(Client *client, int argc, char *argv[]);
handle_deleteid(Client &client, int argc, char *argv[]);
enum command_return
handle_playlist(Client *client, int argc, char *argv[]);
handle_playlist(Client &client, int argc, char *argv[]);
enum command_return
handle_shuffle(Client *client, int argc, char *argv[]);
handle_shuffle(Client &client, int argc, char *argv[]);
enum command_return
handle_clear(Client *client, int argc, char *argv[]);
handle_clear(Client &client, int argc, char *argv[]);
enum command_return
handle_plchanges(Client *client, int argc, char *argv[]);
handle_plchanges(Client &client, int argc, char *argv[]);
enum command_return
handle_plchangesposid(Client *client, int argc, char *argv[]);
handle_plchangesposid(Client &client, int argc, char *argv[]);
enum command_return
handle_playlistinfo(Client *client, int argc, char *argv[]);
handle_playlistinfo(Client &client, int argc, char *argv[]);
enum command_return
handle_playlistid(Client *client, int argc, char *argv[]);
handle_playlistid(Client &client, int argc, char *argv[]);
enum command_return
handle_playlistfind(Client *client, int argc, char *argv[]);
handle_playlistfind(Client &client, int argc, char *argv[]);
enum command_return
handle_playlistsearch(Client *client, int argc, char *argv[]);
handle_playlistsearch(Client &client, int argc, char *argv[]);
enum command_return
handle_prio(Client *client, int argc, char *argv[]);
handle_prio(Client &client, int argc, char *argv[]);
enum command_return
handle_prioid(Client *client, int argc, char *argv[]);
handle_prioid(Client &client, int argc, char *argv[]);
enum command_return
handle_move(Client *client, int argc, char *argv[]);
handle_move(Client &client, int argc, char *argv[]);
enum command_return
handle_moveid(Client *client, int argc, char *argv[]);
handle_moveid(Client &client, int argc, char *argv[]);
enum command_return
handle_swap(Client *client, int argc, char *argv[]);
handle_swap(Client &client, int argc, char *argv[]);
enum command_return
handle_swapid(Client *client, int argc, char *argv[]);
handle_swapid(Client &client, int argc, char *argv[]);
#endif
......@@ -38,70 +38,70 @@ extern "C" {
* @param end the index of the last song (excluding)
*/
static void
queue_print_song_info(Client *client, const struct queue *queue,
queue_print_song_info(Client &client, const queue &queue,
unsigned position)
{
song_print_info(client, queue->Get(position));
song_print_info(client, queue.Get(position));
client_printf(client, "Pos: %u\nId: %u\n",
position, queue->PositionToId(position));
position, queue.PositionToId(position));
uint8_t priority = queue->GetPriorityAtPosition(position);
uint8_t priority = queue.GetPriorityAtPosition(position);
if (priority != 0)
client_printf(client, "Prio: %u\n", priority);
}
void
queue_print_info(Client *client, const struct queue *queue,
queue_print_info(Client &client, const queue &queue,
unsigned start, unsigned end)
{
assert(start <= end);
assert(end <= queue->GetLength());
assert(end <= queue.GetLength());
for (unsigned i = start; i < end; ++i)
queue_print_song_info(client, queue, i);
}
void
queue_print_uris(Client *client, const struct queue *queue,
queue_print_uris(Client &client, const queue &queue,
unsigned start, unsigned end)
{
assert(start <= end);
assert(end <= queue->GetLength());
assert(end <= queue.GetLength());
for (unsigned i = start; i < end; ++i) {
client_printf(client, "%i:", i);
song_print_uri(client, queue->Get(i));
song_print_uri(client, queue.Get(i));
}
}
void
queue_print_changes_info(Client *client, const struct queue *queue,
queue_print_changes_info(Client &client, const queue &queue,
uint32_t version)
{
for (unsigned i = 0; i < queue->GetLength(); i++) {
if (queue->IsNewerAtPosition(i, version))
for (unsigned i = 0; i < queue.GetLength(); i++) {
if (queue.IsNewerAtPosition(i, version))
queue_print_song_info(client, queue, i);
}
}
void
queue_print_changes_position(Client *client, const struct queue *queue,
queue_print_changes_position(Client &client, const queue &queue,
uint32_t version)
{
for (unsigned i = 0; i < queue->GetLength(); i++)
if (queue->IsNewerAtPosition(i, version))
for (unsigned i = 0; i < queue.GetLength(); i++)
if (queue.IsNewerAtPosition(i, version))
client_printf(client, "cpos: %i\nId: %i\n",
i, queue->PositionToId(i));
i, queue.PositionToId(i));
}
void
queue_find(Client *client, const struct queue *queue,
queue_find(Client &client, const queue &queue,
const SongFilter &filter)
{
for (unsigned i = 0; i < queue->GetLength(); i++) {
const Song *song = queue->Get(i);
for (unsigned i = 0; i < queue.GetLength(); i++) {
const Song &song = queue.Get(i);
if (filter.Match(*song))
if (filter.Match(song))
queue_print_song_info(client, queue, i);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment