diff options
Diffstat (limited to '')
-rw-r--r-- | src/ClientInternal.hxx (renamed from src/client_internal.h) | 79 |
1 files changed, 38 insertions, 41 deletions
diff --git a/src/client_internal.h b/src/ClientInternal.hxx index ba97e4b8f..6f3035671 100644 --- a/src/client_internal.h +++ b/src/ClientInternal.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2011 The Music Player Daemon Project + * Copyright (C) 2003-2013 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -17,13 +17,20 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#ifndef MPD_CLIENT_INTERNAL_H -#define MPD_CLIENT_INTERNAL_H +#ifndef MPD_CLIENT_INTERNAL_HXX +#define MPD_CLIENT_INTERNAL_HXX -#include "client.h" -#include "client_message.h" +#include "Client.hxx" +#include "ClientMessage.hxx" +#include "CommandListBuilder.hxx" #include "command.h" +#include <set> +#include <string> +#include <list> + +#include <glib.h> + #undef G_LOG_DOMAIN #define G_LOG_DOMAIN "client" @@ -37,7 +44,9 @@ struct deferred_buffer { char data[sizeof(long)]; }; -struct client { +class Client { +public: + struct playlist &playlist; struct player_control *player_control; GIOChannel *channel; @@ -56,9 +65,8 @@ struct client { */ GTimer *last_activity; - GSList *cmd_list; /* for when in list mode */ - int cmd_list_OK; /* print OK after each command execution */ - size_t cmd_list_size; /* mem cmd_list consumes */ + CommandListBuilder cmd_list; + GQueue *deferred_send; /* for output if client is slow */ size_t deferred_bytes; /* mem deferred_send consumes */ unsigned int num; /* client number */ @@ -79,7 +87,7 @@ struct client { /** * A list of channel names this client is subscribed to. */ - GSList *subscriptions; + std::set<std::string> subscriptions; /** * The number of subscriptions in #subscriptions. Used to @@ -88,15 +96,19 @@ struct client { unsigned num_subscriptions; /** - * A list of messages this client has received in reverse - * order (latest first). + * A list of messages this client has received. */ - GSList *messages; + std::list<ClientMessage> messages; - /** - * The number of messages in #messages. - */ - unsigned num_messages; + Client(struct playlist &playlist, + struct player_control *player_control, + int fd, int uid, int num); + ~Client(); + + gcc_pure + bool IsSubscribed(const char *channel_name) const { + return subscriptions.find(channel_name) != subscriptions.end(); + } }; extern unsigned int client_max_connections; @@ -110,38 +122,23 @@ client_list_is_empty(void); bool client_list_is_full(void); -struct client * +Client * client_list_get_first(void); void -client_list_add(struct client *client); +client_list_add(Client *client); void client_list_foreach(GFunc func, gpointer user_data); void -client_list_remove(struct client *client); +client_list_remove(Client *client); void -client_close(struct client *client); - -static inline void -new_cmd_list_ptr(struct client *client, const char *s) -{ - client->cmd_list = g_slist_prepend(client->cmd_list, g_strdup(s)); -} - -static inline void -free_cmd_list(GSList *list) -{ - for (GSList *tmp = list; tmp != NULL; tmp = g_slist_next(tmp)) - g_free(tmp->data); - - g_slist_free(list); -} +client_close(Client *client); void -client_set_expired(struct client *client); +client_set_expired(Client *client); /** * Schedule an "expired" check for all clients: permanently delete @@ -157,16 +154,16 @@ void client_deinit_expire(void); enum command_return -client_read(struct client *client); +client_read(Client *client); enum command_return -client_process_line(struct client *client, char *line); +client_process_line(Client *client, char *line); void -client_write_deferred(struct client *client); +client_write_deferred(Client *client); void -client_write_output(struct client *client); +client_write_output(Client *client); gboolean client_in_event(GIOChannel *source, GIOCondition condition, |