ClientInternal.hxx 3.69 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2013 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

Max Kellermann's avatar
Max Kellermann committed
20 21
#ifndef MPD_CLIENT_INTERNAL_HXX
#define MPD_CLIENT_INTERNAL_HXX
22

Max Kellermann's avatar
Max Kellermann committed
23 24
#include "Client.hxx"
#include "ClientMessage.hxx"
25
#include "CommandListBuilder.hxx"
26 27
#include "command.h"

28 29
#include <set>
#include <string>
30
#include <list>
31

32 33
#include <glib.h>

34 35
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "client"
36

37 38 39 40 41
enum {
	CLIENT_MAX_SUBSCRIPTIONS = 16,
	CLIENT_MAX_MESSAGES = 64,
};

42 43 44 45 46
struct deferred_buffer {
	size_t size;
	char data[sizeof(long)];
};

47 48
class Client {
public:
49 50
	struct player_control *player_control;

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
	GIOChannel *channel;
	guint source_id;

	/** the buffer for reading lines from the #channel */
	struct fifo_buffer *input;

	unsigned permission;

	/** the uid of the client process, or -1 if unknown */
	int uid;

	/**
	 * How long since the last activity from this client?
	 */
	GTimer *last_activity;

67 68
	CommandListBuilder cmd_list;

69 70 71 72
	GQueue *deferred_send;	/* for output if client is slow */
	size_t deferred_bytes;	/* mem deferred_send consumes */
	unsigned int num;	/* client number */

73
	char send_buf[16384];
74 75 76 77 78 79 80 81 82 83 84
	size_t send_buf_used;	/* bytes used this instance */

	/** is this client waiting for an "idle" response? */
	bool idle_waiting;

	/** idle flags pending on this client, to be sent as soon as
	    the client enters "idle" */
	unsigned idle_flags;

	/** idle flags that the client wants to receive */
	unsigned idle_subscriptions;
85 86 87 88

	/**
	 * A list of channel names this client is subscribed to.
	 */
89
	std::set<std::string> subscriptions;
90 91 92 93 94 95 96 97

	/**
	 * The number of subscriptions in #subscriptions.  Used to
	 * limit the number of subscriptions.
	 */
	unsigned num_subscriptions;

	/**
98
	 * A list of messages this client has received.
99
	 */
100
	std::list<ClientMessage> messages;
101

102 103 104 105
	Client(struct player_control *player_control,
	       int fd, int uid, int num);
	~Client();

106 107 108 109
	gcc_pure
	bool IsSubscribed(const char *channel_name) const {
		return subscriptions.find(channel_name) != subscriptions.end();
	}
110 111
};

112 113 114 115 116 117 118 119 120 121 122
extern unsigned int client_max_connections;
extern int client_timeout;
extern size_t client_max_command_list_size;
extern size_t client_max_output_buffer_size;

bool
client_list_is_empty(void);

bool
client_list_is_full(void);

123
Client *
124 125 126
client_list_get_first(void);

void
127
client_list_add(Client *client);
128 129 130 131 132

void
client_list_foreach(GFunc func, gpointer user_data);

void
133
client_list_remove(Client *client);
134 135

void
136
client_close(Client *client);
137 138

void
139
client_set_expired(Client *client);
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154

/**
 * Schedule an "expired" check for all clients: permanently delete
 * clients which have been set "expired" with client_set_expired().
 */
void
client_schedule_expire(void);

/**
 * Removes a scheduled "expired" check.
 */
void
client_deinit_expire(void);

enum command_return
155
client_read(Client *client);
156 157

enum command_return
158
client_process_line(Client *client, char *line);
159 160

void
161
client_write_deferred(Client *client);
162 163

void
164
client_write_output(Client *client);
165 166 167 168 169

gboolean
client_in_event(GIOChannel *source, GIOCondition condition,
		gpointer data);

170
#endif