Commit fe8e77e5 authored by Max Kellermann's avatar Max Kellermann

Client: add "playlist" attribute

Reduce access to the global variable "g_playlist".
parent b0833084
...@@ -27,13 +27,15 @@ ...@@ -27,13 +27,15 @@
#include <stdarg.h> #include <stdarg.h>
struct sockaddr; struct sockaddr;
struct playlist;
struct player_control; struct player_control;
class Client; class Client;
void client_manager_init(void); void client_manager_init(void);
void client_manager_deinit(void); void client_manager_deinit(void);
void client_new(struct player_control *player_control, void
client_new(struct playlist &playlist, struct player_control *player_control,
int fd, const struct sockaddr *sa, size_t sa_length, int uid); int fd, const struct sockaddr *sa, size_t sa_length, int uid);
gcc_pure gcc_pure
......
...@@ -46,6 +46,7 @@ struct deferred_buffer { ...@@ -46,6 +46,7 @@ struct deferred_buffer {
class Client { class Client {
public: public:
struct playlist &playlist;
struct player_control *player_control; struct player_control *player_control;
GIOChannel *channel; GIOChannel *channel;
...@@ -99,7 +100,8 @@ public: ...@@ -99,7 +100,8 @@ public:
*/ */
std::list<ClientMessage> messages; std::list<ClientMessage> messages;
Client(struct player_control *player_control, Client(struct playlist &playlist,
struct player_control *player_control,
int fd, int uid, int num); int fd, int uid, int num);
~Client(); ~Client();
......
...@@ -45,9 +45,10 @@ extern "C" { ...@@ -45,9 +45,10 @@ extern "C" {
static const char GREETING[] = "OK MPD " PROTOCOL_VERSION "\n"; static const char GREETING[] = "OK MPD " PROTOCOL_VERSION "\n";
Client::Client(struct player_control *_player_control, Client::Client(struct playlist &_playlist,
struct player_control *_player_control,
int fd, int _uid, int _num) int fd, int _uid, int _num)
:player_control(_player_control), :playlist(_playlist), player_control(_player_control),
input(fifo_buffer_new(4096)), input(fifo_buffer_new(4096)),
permission(getDefaultPermissions()), permission(getDefaultPermissions()),
uid(_uid), uid(_uid),
...@@ -93,7 +94,7 @@ Client::~Client() ...@@ -93,7 +94,7 @@ Client::~Client()
} }
void void
client_new(struct player_control *player_control, client_new(struct playlist &playlist, struct player_control *player_control,
int fd, const struct sockaddr *sa, size_t sa_length, int uid) int fd, const struct sockaddr *sa, size_t sa_length, int uid)
{ {
static unsigned int next_client_num; static unsigned int next_client_num;
...@@ -133,7 +134,7 @@ client_new(struct player_control *player_control, ...@@ -133,7 +134,7 @@ client_new(struct player_control *player_control,
return; return;
} }
Client *client = new Client(player_control, fd, uid, Client *client = new Client(playlist, player_control, fd, uid,
next_client_num++); next_client_num++);
(void)send(fd, GREETING, sizeof(GREETING) - 1, 0); (void)send(fd, GREETING, sizeof(GREETING) - 1, 0);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "config.h" #include "config.h"
#include "Listen.hxx" #include "Listen.hxx"
#include "Main.hxx" #include "Main.hxx"
#include "Playlist.hxx"
#include "Client.hxx" #include "Client.hxx"
extern "C" { extern "C" {
...@@ -46,7 +47,8 @@ static void ...@@ -46,7 +47,8 @@ static void
listen_callback(int fd, const struct sockaddr *address, listen_callback(int fd, const struct sockaddr *address,
size_t address_length, int uid, G_GNUC_UNUSED void *ctx) size_t address_length, int uid, G_GNUC_UNUSED void *ctx)
{ {
client_new(global_player_control, fd, address, address_length, uid); client_new(g_playlist, global_player_control,
fd, address, address_length, uid);
} }
static bool static bool
......
...@@ -65,7 +65,8 @@ handle_play(Client *client, int argc, char *argv[]) ...@@ -65,7 +65,8 @@ handle_play(Client *client, int argc, char *argv[])
if (argc == 2 && !check_int(client, &song, argv[1])) if (argc == 2 && !check_int(client, &song, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = playlist_play(&g_playlist, client->player_control, song); result = playlist_play(&client->playlist, client->player_control,
song);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
...@@ -78,15 +79,16 @@ handle_playid(Client *client, int argc, char *argv[]) ...@@ -78,15 +79,16 @@ handle_playid(Client *client, int argc, char *argv[])
if (argc == 2 && !check_int(client, &id, argv[1])) if (argc == 2 && !check_int(client, &id, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = playlist_play_id(&g_playlist, client->player_control, id); result = playlist_play_id(&client->playlist, client->player_control,
id);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
enum command_return enum command_return
handle_stop(G_GNUC_UNUSED Client *client, handle_stop(Client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{ {
playlist_stop(&g_playlist, client->player_control); playlist_stop(&client->playlist, client->player_control);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
...@@ -94,7 +96,7 @@ enum command_return ...@@ -94,7 +96,7 @@ enum command_return
handle_currentsong(Client *client, handle_currentsong(Client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{ {
playlist_print_current(client, &g_playlist); playlist_print_current(client, &client->playlist);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
...@@ -138,6 +140,7 @@ handle_status(Client *client, ...@@ -138,6 +140,7 @@ handle_status(Client *client,
break; break;
} }
const playlist &playlist = client->playlist;
client_printf(client, client_printf(client,
"volume: %i\n" "volume: %i\n"
COMMAND_STATUS_REPEAT ": %i\n" COMMAND_STATUS_REPEAT ": %i\n"
...@@ -151,23 +154,23 @@ handle_status(Client *client, ...@@ -151,23 +154,23 @@ handle_status(Client *client,
COMMAND_STATUS_MIXRAMPDELAY ": %f\n" COMMAND_STATUS_MIXRAMPDELAY ": %f\n"
COMMAND_STATUS_STATE ": %s\n", COMMAND_STATUS_STATE ": %s\n",
volume_level_get(), volume_level_get(),
playlist_get_repeat(&g_playlist), playlist_get_repeat(&playlist),
playlist_get_random(&g_playlist), playlist_get_random(&playlist),
playlist_get_single(&g_playlist), playlist_get_single(&playlist),
playlist_get_consume(&g_playlist), playlist_get_consume(&playlist),
playlist_get_version(&g_playlist), playlist_get_version(&playlist),
playlist_get_length(&g_playlist), playlist_get_length(&playlist),
(int)(pc_get_cross_fade(client->player_control) + 0.5), (int)(pc_get_cross_fade(client->player_control) + 0.5),
pc_get_mixramp_db(client->player_control), pc_get_mixramp_db(client->player_control),
pc_get_mixramp_delay(client->player_control), pc_get_mixramp_delay(client->player_control),
state); state);
song = playlist_get_current_song(&g_playlist); song = playlist_get_current_song(&playlist);
if (song >= 0) { if (song >= 0) {
client_printf(client, client_printf(client,
COMMAND_STATUS_SONG ": %i\n" COMMAND_STATUS_SONG ": %i\n"
COMMAND_STATUS_SONGID ": %u\n", COMMAND_STATUS_SONGID ": %u\n",
song, playlist_get_song_id(&g_playlist, song)); song, playlist_get_song_id(&playlist, song));
} }
if (player_status.state != PLAYER_STATE_STOP) { if (player_status.state != PLAYER_STATE_STOP) {
...@@ -200,37 +203,39 @@ handle_status(Client *client, ...@@ -200,37 +203,39 @@ handle_status(Client *client,
g_free(error); g_free(error);
} }
song = playlist_get_next_song(&g_playlist); song = playlist_get_next_song(&playlist);
if (song >= 0) { if (song >= 0) {
client_printf(client, client_printf(client,
COMMAND_STATUS_NEXTSONG ": %i\n" COMMAND_STATUS_NEXTSONG ": %i\n"
COMMAND_STATUS_NEXTSONGID ": %u\n", COMMAND_STATUS_NEXTSONGID ": %u\n",
song, playlist_get_song_id(&g_playlist, song)); song, playlist_get_song_id(&playlist, song));
} }
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
enum command_return enum command_return
handle_next(G_GNUC_UNUSED Client *client, handle_next(Client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{ {
playlist &playlist = client->playlist;
/* single mode is not considered when this is user who /* single mode is not considered when this is user who
* wants to change song. */ * wants to change song. */
const bool single = g_playlist.queue.single; const bool single = playlist.queue.single;
g_playlist.queue.single = false; playlist.queue.single = false;
playlist_next(&g_playlist, client->player_control); playlist_next(&playlist, client->player_control);
g_playlist.queue.single = single; playlist.queue.single = single;
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
enum command_return enum command_return
handle_previous(G_GNUC_UNUSED Client *client, handle_previous(Client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{ {
playlist_previous(&g_playlist, client->player_control); playlist_previous(&client->playlist, client->player_control);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
...@@ -241,7 +246,7 @@ handle_repeat(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -241,7 +246,7 @@ handle_repeat(Client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!check_bool(client, &status, argv[1])) if (!check_bool(client, &status, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
playlist_set_repeat(&g_playlist, client->player_control, status); playlist_set_repeat(&client->playlist, client->player_control, status);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
...@@ -252,7 +257,7 @@ handle_single(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -252,7 +257,7 @@ handle_single(Client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!check_bool(client, &status, argv[1])) if (!check_bool(client, &status, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
playlist_set_single(&g_playlist, client->player_control, status); playlist_set_single(&client->playlist, client->player_control, status);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
...@@ -263,7 +268,7 @@ handle_consume(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -263,7 +268,7 @@ handle_consume(Client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!check_bool(client, &status, argv[1])) if (!check_bool(client, &status, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
playlist_set_consume(&g_playlist, status); playlist_set_consume(&client->playlist, status);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
...@@ -274,7 +279,7 @@ handle_random(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -274,7 +279,7 @@ handle_random(Client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!check_bool(client, &status, argv[1])) if (!check_bool(client, &status, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
playlist_set_random(&g_playlist, client->player_control, status); playlist_set_random(&client->playlist, client->player_control, status);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
...@@ -297,7 +302,7 @@ handle_seek(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -297,7 +302,7 @@ handle_seek(Client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!check_unsigned(client, &seek_time, argv[2])) if (!check_unsigned(client, &seek_time, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = playlist_seek_song(&g_playlist, client->player_control, result = playlist_seek_song(&client->playlist, client->player_control,
song, seek_time); song, seek_time);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
...@@ -313,7 +318,8 @@ handle_seekid(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -313,7 +318,8 @@ handle_seekid(Client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!check_unsigned(client, &seek_time, argv[2])) if (!check_unsigned(client, &seek_time, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = playlist_seek_song_id(&g_playlist, client->player_control, result = playlist_seek_song_id(&client->playlist,
client->player_control,
id, seek_time); id, seek_time);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
...@@ -328,7 +334,8 @@ handle_seekcur(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -328,7 +334,8 @@ handle_seekcur(Client *client, G_GNUC_UNUSED int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = enum playlist_result result =
playlist_seek_current(&g_playlist, client->player_control, playlist_seek_current(&client->playlist,
client->player_control,
seek_time, relative); seek_time, relative);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
......
...@@ -56,7 +56,7 @@ handle_save(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -56,7 +56,7 @@ handle_save(Client *client, G_GNUC_UNUSED int argc, char *argv[])
{ {
enum playlist_result result; enum playlist_result result;
result = spl_save_playlist(argv[1], &g_playlist); result = spl_save_playlist(argv[1], &client->playlist);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
...@@ -75,13 +75,13 @@ handle_load(Client *client, int argc, char *argv[]) ...@@ -75,13 +75,13 @@ handle_load(Client *client, int argc, char *argv[])
result = playlist_open_into_queue(argv[1], result = playlist_open_into_queue(argv[1],
start_index, end_index, start_index, end_index,
&g_playlist, &client->playlist,
client->player_control, true); client->player_control, true);
if (result != PLAYLIST_RESULT_NO_SUCH_LIST) if (result != PLAYLIST_RESULT_NO_SUCH_LIST)
return print_playlist_result(client, result); return print_playlist_result(client, result);
GError *error = NULL; GError *error = NULL;
if (playlist_load_spl(&g_playlist, client->player_control, if (playlist_load_spl(&client->playlist, client->player_control,
argv[1], start_index, end_index, argv[1], start_index, end_index,
&error)) &error))
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
......
...@@ -49,7 +49,7 @@ handle_add(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -49,7 +49,7 @@ handle_add(Client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!client_allow_file(client, path, &error)) if (!client_allow_file(client, path, &error))
return print_error(client, error); return print_error(client, error);
result = playlist_append_file(&g_playlist, result = playlist_append_file(&client->playlist,
client->player_control, client->player_control,
path, path,
NULL); NULL);
...@@ -63,7 +63,7 @@ handle_add(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -63,7 +63,7 @@ handle_add(Client *client, G_GNUC_UNUSED int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
} }
result = playlist_append_uri(&g_playlist, result = playlist_append_uri(&client->playlist,
client->player_control, client->player_control,
uri, NULL); uri, NULL);
return print_playlist_result(client, result); return print_playlist_result(client, result);
...@@ -89,7 +89,7 @@ handle_addid(Client *client, int argc, char *argv[]) ...@@ -89,7 +89,7 @@ handle_addid(Client *client, int argc, char *argv[])
if (!client_allow_file(client, path, &error)) if (!client_allow_file(client, path, &error))
return print_error(client, error); return print_error(client, error);
result = playlist_append_file(&g_playlist, result = playlist_append_file(&client->playlist,
client->player_control, client->player_control,
path, path,
&added_id); &added_id);
...@@ -100,7 +100,7 @@ handle_addid(Client *client, int argc, char *argv[]) ...@@ -100,7 +100,7 @@ handle_addid(Client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
} }
result = playlist_append_uri(&g_playlist, result = playlist_append_uri(&client->playlist,
client->player_control, client->player_control,
uri, &added_id); uri, &added_id);
} }
...@@ -112,12 +112,14 @@ handle_addid(Client *client, int argc, char *argv[]) ...@@ -112,12 +112,14 @@ handle_addid(Client *client, int argc, char *argv[])
unsigned to; unsigned to;
if (!check_unsigned(client, &to, argv[2])) if (!check_unsigned(client, &to, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = playlist_move_id(&g_playlist, client->player_control, result = playlist_move_id(&client->playlist,
client->player_control,
added_id, to); added_id, to);
if (result != PLAYLIST_RESULT_SUCCESS) { if (result != PLAYLIST_RESULT_SUCCESS) {
enum command_return ret = enum command_return ret =
print_playlist_result(client, result); print_playlist_result(client, result);
playlist_delete_id(&g_playlist, client->player_control, playlist_delete_id(&client->playlist,
client->player_control,
added_id); added_id);
return ret; return ret;
} }
...@@ -136,7 +138,8 @@ handle_delete(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -136,7 +138,8 @@ handle_delete(Client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!check_range(client, &start, &end, argv[1])) if (!check_range(client, &start, &end, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = playlist_delete_range(&g_playlist, client->player_control, result = playlist_delete_range(&client->playlist,
client->player_control,
start, end); start, end);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
...@@ -150,7 +153,8 @@ handle_deleteid(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -150,7 +153,8 @@ handle_deleteid(Client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!check_unsigned(client, &id, argv[1])) if (!check_unsigned(client, &id, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = playlist_delete_id(&g_playlist, client->player_control, id); result = playlist_delete_id(&client->playlist,
client->player_control, id);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
...@@ -158,7 +162,7 @@ enum command_return ...@@ -158,7 +162,7 @@ enum command_return
handle_playlist(Client *client, handle_playlist(Client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{ {
playlist_print_uris(client, &g_playlist); playlist_print_uris(client, &client->playlist);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
...@@ -166,11 +170,12 @@ enum command_return ...@@ -166,11 +170,12 @@ enum command_return
handle_shuffle(G_GNUC_UNUSED Client *client, handle_shuffle(G_GNUC_UNUSED Client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{ {
unsigned start = 0, end = queue_length(&g_playlist.queue); unsigned start = 0, end = queue_length(&client->playlist.queue);
if (argc == 2 && !check_range(client, &start, &end, argv[1])) if (argc == 2 && !check_range(client, &start, &end, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
playlist_shuffle(&g_playlist, client->player_control, start, end); playlist_shuffle(&client->playlist, client->player_control,
start, end);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
...@@ -178,7 +183,7 @@ enum command_return ...@@ -178,7 +183,7 @@ enum command_return
handle_clear(G_GNUC_UNUSED Client *client, handle_clear(G_GNUC_UNUSED Client *client,
G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[]) G_GNUC_UNUSED int argc, G_GNUC_UNUSED char *argv[])
{ {
playlist_clear(&g_playlist, client->player_control); playlist_clear(&client->playlist, client->player_control);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
...@@ -190,7 +195,7 @@ handle_plchanges(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -190,7 +195,7 @@ handle_plchanges(Client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!check_uint32(client, &version, argv[1])) if (!check_uint32(client, &version, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
playlist_print_changes_info(client, &g_playlist, version); playlist_print_changes_info(client, &client->playlist, version);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
...@@ -202,7 +207,7 @@ handle_plchangesposid(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -202,7 +207,7 @@ handle_plchangesposid(Client *client, G_GNUC_UNUSED int argc, char *argv[])
if (!check_uint32(client, &version, argv[1])) if (!check_uint32(client, &version, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
playlist_print_changes_position(client, &g_playlist, version); playlist_print_changes_position(client, &client->playlist, version);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
...@@ -215,7 +220,7 @@ handle_playlistinfo(Client *client, int argc, char *argv[]) ...@@ -215,7 +220,7 @@ handle_playlistinfo(Client *client, int argc, char *argv[])
if (argc == 2 && !check_range(client, &start, &end, argv[1])) if (argc == 2 && !check_range(client, &start, &end, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
ret = playlist_print_info(client, &g_playlist, start, end); ret = playlist_print_info(client, &client->playlist, start, end);
if (!ret) if (!ret)
return print_playlist_result(client, return print_playlist_result(client,
PLAYLIST_RESULT_BAD_RANGE); PLAYLIST_RESULT_BAD_RANGE);
...@@ -231,12 +236,12 @@ handle_playlistid(Client *client, int argc, char *argv[]) ...@@ -231,12 +236,12 @@ handle_playlistid(Client *client, int argc, char *argv[])
if (!check_unsigned(client, &id, argv[1])) if (!check_unsigned(client, &id, argv[1]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
bool ret = playlist_print_id(client, &g_playlist, id); bool ret = playlist_print_id(client, &client->playlist, id);
if (!ret) if (!ret)
return print_playlist_result(client, return print_playlist_result(client,
PLAYLIST_RESULT_NO_SUCH_SONG); PLAYLIST_RESULT_NO_SUCH_SONG);
} else { } else {
playlist_print_info(client, &g_playlist, 0, G_MAXUINT); playlist_print_info(client, &client->playlist, 0, G_MAXUINT);
} }
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
...@@ -252,7 +257,7 @@ handle_playlist_match(Client *client, int argc, char *argv[], ...@@ -252,7 +257,7 @@ handle_playlist_match(Client *client, int argc, char *argv[],
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
} }
playlist_print_find(client, &g_playlist, filter); playlist_print_find(client, &client->playlist, filter);
return COMMAND_RETURN_OK; return COMMAND_RETURN_OK;
} }
...@@ -289,7 +294,7 @@ handle_prio(Client *client, int argc, char *argv[]) ...@@ -289,7 +294,7 @@ handle_prio(Client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = enum playlist_result result =
playlist_set_priority(&g_playlist, playlist_set_priority(&client->playlist,
client->player_control, client->player_control,
start_position, end_position, start_position, end_position,
priority); priority);
...@@ -320,7 +325,7 @@ handle_prioid(Client *client, int argc, char *argv[]) ...@@ -320,7 +325,7 @@ handle_prioid(Client *client, int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
enum playlist_result result = enum playlist_result result =
playlist_set_priority_id(&g_playlist, playlist_set_priority_id(&client->playlist,
client->player_control, client->player_control,
song_id, priority); song_id, priority);
if (result != PLAYLIST_RESULT_SUCCESS) if (result != PLAYLIST_RESULT_SUCCESS)
...@@ -341,7 +346,7 @@ handle_move(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -341,7 +346,7 @@ handle_move(Client *client, G_GNUC_UNUSED int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
if (!check_int(client, &to, argv[2])) if (!check_int(client, &to, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = playlist_move_range(&g_playlist, client->player_control, result = playlist_move_range(&client->playlist, client->player_control,
start, end, to); start, end, to);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
...@@ -357,7 +362,7 @@ handle_moveid(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -357,7 +362,7 @@ handle_moveid(Client *client, G_GNUC_UNUSED int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
if (!check_int(client, &to, argv[2])) if (!check_int(client, &to, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = playlist_move_id(&g_playlist, client->player_control, result = playlist_move_id(&client->playlist, client->player_control,
id, to); id, to);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
...@@ -372,7 +377,7 @@ handle_swap(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -372,7 +377,7 @@ handle_swap(Client *client, G_GNUC_UNUSED int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
if (!check_unsigned(client, &song2, argv[2])) if (!check_unsigned(client, &song2, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = playlist_swap_songs(&g_playlist, client->player_control, result = playlist_swap_songs(&client->playlist, client->player_control,
song1, song2); song1, song2);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
...@@ -387,7 +392,8 @@ handle_swapid(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -387,7 +392,8 @@ handle_swapid(Client *client, G_GNUC_UNUSED int argc, char *argv[])
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
if (!check_unsigned(client, &id2, argv[2])) if (!check_unsigned(client, &id2, argv[2]))
return COMMAND_RETURN_ERROR; return COMMAND_RETURN_ERROR;
result = playlist_swap_songs_id(&g_playlist, client->player_control, result = playlist_swap_songs_id(&client->playlist,
client->player_control,
id1, id2); id1, id2);
return print_playlist_result(client, result); return print_playlist_result(client, result);
} }
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