2009-07-28 16:42:40 +02:00
|
|
|
/*
|
2013-01-03 10:33:04 +01:00
|
|
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
2009-07-28 16:42:40 +02:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-01-03 10:33:04 +01:00
|
|
|
#ifndef MPD_CLIENT_INTERNAL_HXX
|
|
|
|
#define MPD_CLIENT_INTERNAL_HXX
|
2009-07-28 16:42:40 +02:00
|
|
|
|
2013-01-14 23:49:43 +01:00
|
|
|
#include "check.h"
|
2013-01-03 10:33:04 +01:00
|
|
|
#include "Client.hxx"
|
|
|
|
#include "ClientMessage.hxx"
|
2013-01-04 00:50:13 +01:00
|
|
|
#include "CommandListBuilder.hxx"
|
2013-01-30 10:36:47 +01:00
|
|
|
#include "event/FullyBufferedSocket.hxx"
|
2013-01-16 21:39:40 +01:00
|
|
|
#include "event/TimeoutMonitor.hxx"
|
2009-07-28 17:17:23 +02:00
|
|
|
#include "command.h"
|
|
|
|
|
2013-01-03 11:31:32 +01:00
|
|
|
#include <set>
|
|
|
|
#include <string>
|
2013-01-04 14:44:06 +01:00
|
|
|
#include <list>
|
2013-01-03 11:31:32 +01:00
|
|
|
|
2011-01-29 09:26:22 +01:00
|
|
|
enum {
|
|
|
|
CLIENT_MAX_SUBSCRIPTIONS = 16,
|
|
|
|
CLIENT_MAX_MESSAGES = 64,
|
|
|
|
};
|
|
|
|
|
2013-01-07 10:59:56 +01:00
|
|
|
struct Partition;
|
|
|
|
|
2013-01-30 10:36:47 +01:00
|
|
|
class Client final : private FullyBufferedSocket, TimeoutMonitor {
|
2013-01-03 17:27:26 +01:00
|
|
|
public:
|
2013-01-07 10:59:56 +01:00
|
|
|
Partition &partition;
|
2013-01-04 23:07:11 +01:00
|
|
|
struct playlist &playlist;
|
2009-11-03 21:08:48 +01:00
|
|
|
struct player_control *player_control;
|
|
|
|
|
2009-07-28 16:42:40 +02:00
|
|
|
unsigned permission;
|
|
|
|
|
|
|
|
/** the uid of the client process, or -1 if unknown */
|
|
|
|
int uid;
|
|
|
|
|
2013-01-04 00:50:13 +01:00
|
|
|
CommandListBuilder cmd_list;
|
|
|
|
|
2009-07-28 16:42:40 +02:00
|
|
|
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;
|
2011-01-29 09:26:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A list of channel names this client is subscribed to.
|
|
|
|
*/
|
2013-01-03 11:31:32 +01:00
|
|
|
std::set<std::string> subscriptions;
|
2011-01-29 09:26:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The number of subscriptions in #subscriptions. Used to
|
|
|
|
* limit the number of subscriptions.
|
|
|
|
*/
|
|
|
|
unsigned num_subscriptions;
|
|
|
|
|
|
|
|
/**
|
2013-01-03 18:07:48 +01:00
|
|
|
* A list of messages this client has received.
|
2011-01-29 09:26:22 +01:00
|
|
|
*/
|
2013-01-04 14:44:06 +01:00
|
|
|
std::list<ClientMessage> messages;
|
2013-01-03 11:31:32 +01:00
|
|
|
|
2013-01-14 23:42:06 +01:00
|
|
|
Client(EventLoop &loop, Partition &partition,
|
2013-01-03 23:32:05 +01:00
|
|
|
int fd, int uid, int num);
|
|
|
|
|
2013-01-14 23:42:06 +01:00
|
|
|
bool IsConnected() const {
|
2013-01-30 10:36:47 +01:00
|
|
|
return FullyBufferedSocket::IsDefined();
|
2013-01-14 23:42:06 +01:00
|
|
|
}
|
|
|
|
|
2013-01-03 11:31:32 +01:00
|
|
|
gcc_pure
|
|
|
|
bool IsSubscribed(const char *channel_name) const {
|
|
|
|
return subscriptions.find(channel_name) != subscriptions.end();
|
|
|
|
}
|
2013-01-15 10:11:08 +01:00
|
|
|
|
|
|
|
gcc_pure
|
|
|
|
bool IsExpired() const {
|
2013-01-30 10:36:47 +01:00
|
|
|
return !FullyBufferedSocket::IsDefined();
|
2013-01-15 10:11:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Close();
|
|
|
|
void SetExpired();
|
2013-01-14 23:42:06 +01:00
|
|
|
|
2013-01-30 10:36:47 +01:00
|
|
|
using FullyBufferedSocket::Write;
|
2013-01-14 23:42:06 +01:00
|
|
|
|
2013-01-16 21:46:13 +01:00
|
|
|
/**
|
|
|
|
* Send "idle" response to this client.
|
|
|
|
*/
|
|
|
|
void IdleNotify();
|
|
|
|
void IdleAdd(unsigned flags);
|
|
|
|
bool IdleWait(unsigned flags);
|
|
|
|
|
2013-01-14 23:42:06 +01:00
|
|
|
private:
|
|
|
|
/* virtual methods from class BufferedSocket */
|
|
|
|
virtual InputResult OnSocketInput(const void *data,
|
|
|
|
size_t length) override;
|
2013-08-10 18:02:44 +02:00
|
|
|
virtual void OnSocketError(Error &&error) override;
|
2013-01-14 23:42:06 +01:00
|
|
|
virtual void OnSocketClosed() override;
|
2013-01-16 21:39:40 +01:00
|
|
|
|
|
|
|
/* virtual methods from class TimeoutMonitor */
|
2013-04-08 23:14:07 +02:00
|
|
|
virtual void OnTimeout() override;
|
2009-07-28 16:42:40 +02:00
|
|
|
};
|
|
|
|
|
2013-09-27 22:31:24 +02:00
|
|
|
extern const class Domain client_domain;
|
|
|
|
|
2009-07-28 17:17:23 +02:00
|
|
|
extern int client_timeout;
|
|
|
|
extern size_t client_max_command_list_size;
|
|
|
|
extern size_t client_max_output_buffer_size;
|
|
|
|
|
|
|
|
enum command_return
|
2013-01-03 17:27:26 +01:00
|
|
|
client_process_line(Client *client, char *line);
|
2009-07-28 17:17:23 +02:00
|
|
|
|
2009-07-28 16:42:40 +02:00
|
|
|
#endif
|