Client: add Partition reference attribute

playlist and player_control are deprecated.
This commit is contained in:
Max Kellermann 2013-01-07 10:59:56 +01:00
parent a6ee6be960
commit d360f17a59
8 changed files with 30 additions and 31 deletions

View File

@ -27,15 +27,14 @@
#include <stdarg.h>
struct sockaddr;
struct playlist;
struct player_control;
struct Partition;
class Client;
void client_manager_init(void);
void client_manager_deinit(void);
void
client_new(struct playlist &playlist, struct player_control *player_control,
client_new(Partition &partition,
int fd, const struct sockaddr *sa, size_t sa_length, int uid);
gcc_pure

View File

@ -44,8 +44,11 @@ struct deferred_buffer {
char data[sizeof(long)];
};
struct Partition;
class Client {
public:
Partition &partition;
struct playlist &playlist;
struct player_control *player_control;
@ -100,8 +103,7 @@ public:
*/
std::list<ClientMessage> messages;
Client(struct playlist &playlist,
struct player_control *player_control,
Client(Partition &partition,
int fd, int uid, int num);
~Client();

View File

@ -19,6 +19,7 @@
#include "config.h"
#include "ClientInternal.hxx"
#include "Partition.hxx"
#include "fd_util.h"
extern "C" {
#include "fifo_buffer.h"
@ -45,10 +46,10 @@ extern "C" {
static const char GREETING[] = "OK MPD " PROTOCOL_VERSION "\n";
Client::Client(struct playlist &_playlist,
struct player_control *_player_control,
Client::Client(Partition &_partition,
int fd, int _uid, int _num)
:playlist(_playlist), player_control(_player_control),
:partition(_partition),
playlist(partition.playlist), player_control(&partition.pc),
input(fifo_buffer_new(4096)),
permission(getDefaultPermissions()),
uid(_uid),
@ -94,13 +95,12 @@ Client::~Client()
}
void
client_new(struct playlist &playlist, struct player_control *player_control,
client_new(Partition &partition,
int fd, const struct sockaddr *sa, size_t sa_length, int uid)
{
static unsigned int next_client_num;
char *remote;
assert(player_control != NULL);
assert(fd >= 0);
#ifdef HAVE_LIBWRAP
@ -134,7 +134,7 @@ client_new(struct playlist &playlist, struct player_control *player_control,
return;
}
Client *client = new Client(playlist, player_control, fd, uid,
Client *client = new Client(partition, fd, uid,
next_client_num++);
(void)send(fd, GREETING, sizeof(GREETING) - 1, 0);

View File

@ -92,7 +92,7 @@ handle_match_add(Client *client, int argc, char *argv[], bool fold_case)
}
GError *error = NULL;
return findAddIn(client->playlist, client->player_control,
return AddFromDatabase(client->partition,
"", &filter, &error)
? COMMAND_RETURN_OK
: print_error(client, error);

View File

@ -22,16 +22,16 @@
#include "DatabaseSelection.hxx"
#include "DatabaseGlue.hxx"
#include "DatabasePlugin.hxx"
#include "Playlist.hxx"
#include "Partition.hxx"
#include <functional>
static bool
AddToQueue(struct playlist &playlist, struct player_control *pc,
song &song, GError **error_r)
AddToQueue(Partition &partition, song &song, GError **error_r)
{
enum playlist_result result =
playlist_append_song(&playlist, pc, &song, NULL);
playlist_append_song(&partition.playlist, &partition.pc,
&song, NULL);
if (result != PLAYLIST_RESULT_SUCCESS) {
g_set_error(error_r, playlist_quark(), result,
"Playlist error");
@ -42,7 +42,7 @@ AddToQueue(struct playlist &playlist, struct player_control *pc,
}
bool
findAddIn(struct playlist &playlist, struct player_control *pc,
AddFromDatabase(Partition &partition,
const char *uri,
const SongFilter *filter, GError **error_r)
{
@ -53,6 +53,6 @@ findAddIn(struct playlist &playlist, struct player_control *pc,
const DatabaseSelection selection(uri, true, filter);
using namespace std::placeholders;
const auto f = std::bind(AddToQueue, std::ref(playlist), pc, _1, _2);
const auto f = std::bind(AddToQueue, std::ref(partition), _1, _2);
return db->Visit(selection, f, error_r);
}

View File

@ -24,12 +24,11 @@
#include "gerror.h"
class SongFilter;
struct playlist;
struct player_control;
struct Partition;
gcc_nonnull(2,3)
gcc_nonnull(2)
bool
findAddIn(struct playlist &playlist, struct player_control *pc,
AddFromDatabase(Partition &partition,
const char *name,
const SongFilter *filter, GError **error_r);

View File

@ -20,7 +20,6 @@
#include "config.h"
#include "Listen.hxx"
#include "Main.hxx"
#include "Partition.hxx"
#include "Client.hxx"
#include "conf.h"
@ -47,7 +46,7 @@ static void
listen_callback(int fd, const struct sockaddr *address,
size_t address_length, int uid, G_GNUC_UNUSED void *ctx)
{
client_new(global_partition->playlist, &global_partition->pc,
client_new(*global_partition,
fd, address, address_length, uid);
}

View File

@ -70,7 +70,7 @@ handle_add(Client *client, G_GNUC_UNUSED int argc, char *argv[])
}
GError *error = NULL;
return findAddIn(client->playlist, client->player_control,
return AddFromDatabase(client->partition,
uri, nullptr, &error)
? COMMAND_RETURN_OK
: print_error(client, error);