MPD 0.17~git
src/client_internal.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-2011 The Music Player Daemon Project
00003  * http://www.musicpd.org
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, write to the Free Software Foundation, Inc.,
00017  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00018  */
00019 
00020 #ifndef MPD_CLIENT_INTERNAL_H
00021 #define MPD_CLIENT_INTERNAL_H
00022 
00023 #include "client.h"
00024 #include "client_message.h"
00025 #include "command.h"
00026 
00027 #undef G_LOG_DOMAIN
00028 #define G_LOG_DOMAIN "client"
00029 
00030 enum {
00031         CLIENT_MAX_SUBSCRIPTIONS = 16,
00032         CLIENT_MAX_MESSAGES = 64,
00033 };
00034 
00035 struct deferred_buffer {
00036         size_t size;
00037         char data[sizeof(long)];
00038 };
00039 
00040 struct client {
00041         struct player_control *player_control;
00042 
00043         GIOChannel *channel;
00044         guint source_id;
00045 
00047         struct fifo_buffer *input;
00048 
00049         unsigned permission;
00050 
00052         int uid;
00053 
00057         GTimer *last_activity;
00058 
00059         GSList *cmd_list;       /* for when in list mode */
00060         int cmd_list_OK;        /* print OK after each command execution */
00061         size_t cmd_list_size;   /* mem cmd_list consumes */
00062         GQueue *deferred_send;  /* for output if client is slow */
00063         size_t deferred_bytes;  /* mem deferred_send consumes */
00064         unsigned int num;       /* client number */
00065 
00066         char send_buf[16384];
00067         size_t send_buf_used;   /* bytes used this instance */
00068 
00070         bool idle_waiting;
00071 
00074         unsigned idle_flags;
00075 
00077         unsigned idle_subscriptions;
00078 
00082         GSList *subscriptions;
00083 
00088         unsigned num_subscriptions;
00089 
00094         GSList *messages;
00095 
00099         unsigned num_messages;
00100 };
00101 
00102 extern unsigned int client_max_connections;
00103 extern int client_timeout;
00104 extern size_t client_max_command_list_size;
00105 extern size_t client_max_output_buffer_size;
00106 
00107 bool
00108 client_list_is_empty(void);
00109 
00110 bool
00111 client_list_is_full(void);
00112 
00113 struct client *
00114 client_list_get_first(void);
00115 
00116 void
00117 client_list_add(struct client *client);
00118 
00119 void
00120 client_list_foreach(GFunc func, gpointer user_data);
00121 
00122 void
00123 client_list_remove(struct client *client);
00124 
00125 void
00126 client_close(struct client *client);
00127 
00128 static inline void
00129 new_cmd_list_ptr(struct client *client, const char *s)
00130 {
00131         client->cmd_list = g_slist_prepend(client->cmd_list, g_strdup(s));
00132 }
00133 
00134 static inline void
00135 free_cmd_list(GSList *list)
00136 {
00137         for (GSList *tmp = list; tmp != NULL; tmp = g_slist_next(tmp))
00138                 g_free(tmp->data);
00139 
00140         g_slist_free(list);
00141 }
00142 
00143 void
00144 client_set_expired(struct client *client);
00145 
00150 void
00151 client_schedule_expire(void);
00152 
00156 void
00157 client_deinit_expire(void);
00158 
00159 enum command_return
00160 client_read(struct client *client);
00161 
00162 enum command_return
00163 client_process_line(struct client *client, char *line);
00164 
00165 void
00166 client_write_deferred(struct client *client);
00167 
00168 void
00169 client_write_output(struct client *client);
00170 
00171 gboolean
00172 client_in_event(GIOChannel *source, GIOCondition condition,
00173                 gpointer data);
00174 
00175 #endif