ClientInternal.hxx 3.24 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

23
#include "check.h"
Max Kellermann's avatar
Max Kellermann committed
24 25
#include "Client.hxx"
#include "ClientMessage.hxx"
26
#include "CommandListBuilder.hxx"
27
#include "event/FullyBufferedSocket.hxx"
28
#include "event/TimeoutMonitor.hxx"
29 30
#include "command.h"

31 32
#include <set>
#include <string>
33
#include <list>
34

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

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

43 44
struct Partition;

45
class Client final : private FullyBufferedSocket, TimeoutMonitor {
46
public:
47
	Partition &partition;
48
	struct playlist &playlist;
49 50
	struct player_control *player_control;

51 52 53 54 55
	unsigned permission;

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

56 57
	CommandListBuilder cmd_list;

58 59 60 61 62 63 64 65 66 67 68
	unsigned int num;	/* client number */

	/** 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;
69 70 71 72

	/**
	 * A list of channel names this client is subscribed to.
	 */
73
	std::set<std::string> subscriptions;
74 75 76 77 78 79 80 81

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

	/**
82
	 * A list of messages this client has received.
83
	 */
84
	std::list<ClientMessage> messages;
85

86
	Client(EventLoop &loop, Partition &partition,
87 88
	       int fd, int uid, int num);

89
	bool IsConnected() const {
90
		return FullyBufferedSocket::IsDefined();
91 92
	}

93 94 95 96
	gcc_pure
	bool IsSubscribed(const char *channel_name) const {
		return subscriptions.find(channel_name) != subscriptions.end();
	}
97 98 99

	gcc_pure
	bool IsExpired() const {
100
		return !FullyBufferedSocket::IsDefined();
101 102 103 104
	}

	void Close();
	void SetExpired();
105

106
	using FullyBufferedSocket::Write;
107

108 109 110 111 112 113 114
	/**
	 * Send "idle" response to this client.
	 */
	void IdleNotify();
	void IdleAdd(unsigned flags);
	bool IdleWait(unsigned flags);

115 116 117 118 119 120
private:
	/* virtual methods from class BufferedSocket */
	virtual InputResult OnSocketInput(const void *data,
					  size_t length) override;
	virtual void OnSocketError(GError *error) override;
	virtual void OnSocketClosed() override;
121 122

	/* virtual methods from class TimeoutMonitor */
123
	virtual void OnTimeout() override;
124 125
};

126 127 128 129 130
extern int client_timeout;
extern size_t client_max_command_list_size;
extern size_t client_max_output_buffer_size;

enum command_return
131
client_process_line(Client *client, char *line);
132

133
#endif