Commit d360f17a authored by Max Kellermann's avatar Max Kellermann

Client: add Partition reference attribute

playlist and player_control are deprecated.
parent a6ee6be9
...@@ -27,15 +27,14 @@ ...@@ -27,15 +27,14 @@
#include <stdarg.h> #include <stdarg.h>
struct sockaddr; struct sockaddr;
struct playlist; struct Partition;
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 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); int fd, const struct sockaddr *sa, size_t sa_length, int uid);
gcc_pure gcc_pure
......
...@@ -44,8 +44,11 @@ struct deferred_buffer { ...@@ -44,8 +44,11 @@ struct deferred_buffer {
char data[sizeof(long)]; char data[sizeof(long)];
}; };
struct Partition;
class Client { class Client {
public: public:
Partition &partition;
struct playlist &playlist; struct playlist &playlist;
struct player_control *player_control; struct player_control *player_control;
...@@ -100,8 +103,7 @@ public: ...@@ -100,8 +103,7 @@ public:
*/ */
std::list<ClientMessage> messages; std::list<ClientMessage> messages;
Client(struct playlist &playlist, Client(Partition &partition,
struct player_control *player_control,
int fd, int uid, int num); int fd, int uid, int num);
~Client(); ~Client();
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "config.h" #include "config.h"
#include "ClientInternal.hxx" #include "ClientInternal.hxx"
#include "Partition.hxx"
#include "fd_util.h" #include "fd_util.h"
extern "C" { extern "C" {
#include "fifo_buffer.h" #include "fifo_buffer.h"
...@@ -45,10 +46,10 @@ extern "C" { ...@@ -45,10 +46,10 @@ extern "C" {
static const char GREETING[] = "OK MPD " PROTOCOL_VERSION "\n"; static const char GREETING[] = "OK MPD " PROTOCOL_VERSION "\n";
Client::Client(struct playlist &_playlist, Client::Client(Partition &_partition,
struct player_control *_player_control,
int fd, int _uid, int _num) 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)), input(fifo_buffer_new(4096)),
permission(getDefaultPermissions()), permission(getDefaultPermissions()),
uid(_uid), uid(_uid),
...@@ -94,13 +95,12 @@ Client::~Client() ...@@ -94,13 +95,12 @@ Client::~Client()
} }
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) int fd, const struct sockaddr *sa, size_t sa_length, int uid)
{ {
static unsigned int next_client_num; static unsigned int next_client_num;
char *remote; char *remote;
assert(player_control != NULL);
assert(fd >= 0); assert(fd >= 0);
#ifdef HAVE_LIBWRAP #ifdef HAVE_LIBWRAP
...@@ -134,7 +134,7 @@ client_new(struct playlist &playlist, struct player_control *player_control, ...@@ -134,7 +134,7 @@ client_new(struct playlist &playlist, struct player_control *player_control,
return; return;
} }
Client *client = new Client(playlist, player_control, fd, uid, Client *client = new Client(partition, fd, uid,
next_client_num++); next_client_num++);
(void)send(fd, GREETING, sizeof(GREETING) - 1, 0); (void)send(fd, GREETING, sizeof(GREETING) - 1, 0);
......
...@@ -92,8 +92,8 @@ handle_match_add(Client *client, int argc, char *argv[], bool fold_case) ...@@ -92,8 +92,8 @@ handle_match_add(Client *client, int argc, char *argv[], bool fold_case)
} }
GError *error = NULL; GError *error = NULL;
return findAddIn(client->playlist, client->player_control, return AddFromDatabase(client->partition,
"", &filter, &error) "", &filter, &error)
? COMMAND_RETURN_OK ? COMMAND_RETURN_OK
: print_error(client, error); : print_error(client, error);
} }
......
...@@ -22,16 +22,16 @@ ...@@ -22,16 +22,16 @@
#include "DatabaseSelection.hxx" #include "DatabaseSelection.hxx"
#include "DatabaseGlue.hxx" #include "DatabaseGlue.hxx"
#include "DatabasePlugin.hxx" #include "DatabasePlugin.hxx"
#include "Playlist.hxx" #include "Partition.hxx"
#include <functional> #include <functional>
static bool static bool
AddToQueue(struct playlist &playlist, struct player_control *pc, AddToQueue(Partition &partition, song &song, GError **error_r)
song &song, GError **error_r)
{ {
enum playlist_result result = 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) { if (result != PLAYLIST_RESULT_SUCCESS) {
g_set_error(error_r, playlist_quark(), result, g_set_error(error_r, playlist_quark(), result,
"Playlist error"); "Playlist error");
...@@ -42,9 +42,9 @@ AddToQueue(struct playlist &playlist, struct player_control *pc, ...@@ -42,9 +42,9 @@ AddToQueue(struct playlist &playlist, struct player_control *pc,
} }
bool bool
findAddIn(struct playlist &playlist, struct player_control *pc, AddFromDatabase(Partition &partition,
const char *uri, const char *uri,
const SongFilter *filter, GError **error_r) const SongFilter *filter, GError **error_r)
{ {
const Database *db = GetDatabase(error_r); const Database *db = GetDatabase(error_r);
if (db == nullptr) if (db == nullptr)
...@@ -53,6 +53,6 @@ findAddIn(struct playlist &playlist, struct player_control *pc, ...@@ -53,6 +53,6 @@ findAddIn(struct playlist &playlist, struct player_control *pc,
const DatabaseSelection selection(uri, true, filter); const DatabaseSelection selection(uri, true, filter);
using namespace std::placeholders; 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); return db->Visit(selection, f, error_r);
} }
...@@ -24,13 +24,12 @@ ...@@ -24,13 +24,12 @@
#include "gerror.h" #include "gerror.h"
class SongFilter; class SongFilter;
struct playlist; struct Partition;
struct player_control;
gcc_nonnull(2,3) gcc_nonnull(2)
bool bool
findAddIn(struct playlist &playlist, struct player_control *pc, AddFromDatabase(Partition &partition,
const char *name, const char *name,
const SongFilter *filter, GError **error_r); const SongFilter *filter, GError **error_r);
#endif #endif
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "config.h" #include "config.h"
#include "Listen.hxx" #include "Listen.hxx"
#include "Main.hxx" #include "Main.hxx"
#include "Partition.hxx"
#include "Client.hxx" #include "Client.hxx"
#include "conf.h" #include "conf.h"
...@@ -47,7 +46,7 @@ static void ...@@ -47,7 +46,7 @@ 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_partition->playlist, &global_partition->pc, client_new(*global_partition,
fd, address, address_length, uid); fd, address, address_length, uid);
} }
......
...@@ -70,8 +70,8 @@ handle_add(Client *client, G_GNUC_UNUSED int argc, char *argv[]) ...@@ -70,8 +70,8 @@ handle_add(Client *client, G_GNUC_UNUSED int argc, char *argv[])
} }
GError *error = NULL; GError *error = NULL;
return findAddIn(client->playlist, client->player_control, return AddFromDatabase(client->partition,
uri, nullptr, &error) uri, nullptr, &error)
? COMMAND_RETURN_OK ? COMMAND_RETURN_OK
: print_error(client, error); : print_error(client, error);
} }
......
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