| 1 |
/* $Id: connection.h,v 1.3 1999/03/10 07:58:03 boyns Exp $ */ |
| 2 |
|
| 3 |
/* |
| 4 |
* Copyright (C) 1993-99 Mark R. Boyns <[email protected]> |
| 5 |
* |
| 6 |
* This file is part of rplay. |
| 7 |
* |
| 8 |
* rplay is free software; you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU General Public License as published by |
| 10 |
* the Free Software Foundation; either version 2 of the License, or |
| 11 |
* (at your option) any later version. |
| 12 |
* |
| 13 |
* rplay is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU General Public License |
| 19 |
* along with rplay; see the file COPYING. If not, write to the |
| 20 |
* Free Software Foundation, Inc., |
| 21 |
* 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. |
| 22 |
*/ |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#ifndef _connection_h |
| 27 |
#define _connection_h |
| 28 |
|
| 29 |
#ifdef HAVE_CONFIG_H |
| 30 |
#include "config.h" |
| 31 |
#endif |
| 32 |
#include <sys/param.h> |
| 33 |
#include <sys/types.h> |
| 34 |
#include <sys/time.h> |
| 35 |
#include "sound.h" |
| 36 |
#include "server.h" |
| 37 |
#include "buffer.h" |
| 38 |
#include "spool.h" |
| 39 |
|
| 40 |
/* |
| 41 |
* event types |
| 42 |
*/ |
| 43 |
#define EVENT_NULL 0 |
| 44 |
#define EVENT_READ_COMMAND (1<<0) /* read an RPTP command (client) */ |
| 45 |
#define EVENT_CONNECT (1<<1) /* connect to a server (server) */ |
| 46 |
#define EVENT_READ_CONNECT_REPLY (1<<2) /* read a connect reply (server) */ |
| 47 |
#define EVENT_WRITE_FIND (1<<3) /* write a find command (server) */ |
| 48 |
#define EVENT_READ_FIND_REPLY (1<<4) /* read a find reply (server) */ |
| 49 |
#define EVENT_WRITE_GET (1<<5) /* write a get command (server) */ |
| 50 |
#define EVENT_READ_GET_REPLY (1<<6) /* read a get reply (server) */ |
| 51 |
#define EVENT_READ_SOUND (1<<7) /* read a sound (both) */ |
| 52 |
#define EVENT_WRITE (1<<8) /* write buffers (client) */ |
| 53 |
#define EVENT_WRITE_SOUND (1<<9) /* write a sound (client) */ |
| 54 |
#define EVENT_WRITE_TIMEOUT (1<<10) /* write connection timeout message (both) */ |
| 55 |
#define EVENT_NOTIFY (1<<11) /* event notification (client) */ |
| 56 |
#define EVENT_READ_FLOW (1<<12) /* read a flow */ |
| 57 |
#define EVENT_WAIT_FLOW (1<<13) /* pause the incoming flow data */ |
| 58 |
#define EVENT_PIPE_FLOW (1<<14) /* piped flow data */ |
| 59 |
#define EVENT_WRITE_MONITOR (1<<15) /* write audio monitor data */ |
| 60 |
#define EVENT_WAIT_MONITOR (1<<16) /* write audio monitor data */ |
| 61 |
|
| 62 |
/* |
| 63 |
* notify events |
| 64 |
*/ |
| 65 |
#define NOTIFY_NONE 0 |
| 66 |
#define NOTIFY_VOLUME (1<<0) |
| 67 |
#define NOTIFY_PLAY (1<<1) |
| 68 |
#define NOTIFY_PAUSE (1<<2) |
| 69 |
#define NOTIFY_CONTINUE (1<<3) |
| 70 |
#define NOTIFY_STOP (1<<4) |
| 71 |
#define NOTIFY_DONE (1<<5) |
| 72 |
#define NOTIFY_SKIP (1<<6) |
| 73 |
#define NOTIFY_STATE (1<<7) |
| 74 |
#define NOTIFY_FLOW (1<<8) |
| 75 |
#define NOTIFY_MODIFY (1<<9) |
| 76 |
#define NOTIFY_LEVEL (1<<10) |
| 77 |
#define NOTIFY_POSITION (1<<11) |
| 78 |
#define NOTIFY_MONITOR (1<<12) |
| 79 |
#define NOTIFY_ANY (0xffffffff) |
| 80 |
#define NOTIFY_SPOOL (NOTIFY_PLAY|NOTIFY_PAUSE|NOTIFY_CONTINUE|NOTIFY_STOP|NOTIFY_DONE|NOTIFY_SKIP|NOTIFY_MODIFY|NOTIFY_FLOW) |
| 81 |
|
| 82 |
/* |
| 83 |
* connection types |
| 84 |
*/ |
| 85 |
#define CONNECTION_NULL 0 |
| 86 |
#define CONNECTION_CLIENT 1 |
| 87 |
#define CONNECTION_SERVER 2 |
| 88 |
|
| 89 |
typedef struct _event |
| 90 |
{ |
| 91 |
struct _event *next; |
| 92 |
int type; |
| 93 |
int nbytes; |
| 94 |
int byte_offset; |
| 95 |
int nleft; |
| 96 |
char *start; |
| 97 |
char *ptr; |
| 98 |
BUFFER *buffer; |
| 99 |
SOUND *sound; |
| 100 |
int fd; |
| 101 |
int nconnects; |
| 102 |
time_t time; |
| 103 |
int success; |
| 104 |
int id; |
| 105 |
int wait_mask; |
| 106 |
SINDEX *si; |
| 107 |
} |
| 108 |
EVENT; |
| 109 |
|
| 110 |
#define NOTIFY_RATE_LEVEL 0 |
| 111 |
#define NOTIFY_RATE_POSITION 1 |
| 112 |
#define NOTIFY_RATE_MAX 2 |
| 113 |
|
| 114 |
typedef struct |
| 115 |
{ |
| 116 |
double rate; /* event notify-rate */ |
| 117 |
double next; /* next notify time */ |
| 118 |
} |
| 119 |
NOTIFY_RATE; |
| 120 |
|
| 121 |
typedef struct _connection |
| 122 |
{ |
| 123 |
struct _connection *next; |
| 124 |
struct _connection *prev; |
| 125 |
struct sockaddr_in sin; |
| 126 |
int type; |
| 127 |
int fd; |
| 128 |
EVENT *event; |
| 129 |
EVENT **ep; |
| 130 |
SERVER *server; |
| 131 |
time_t time; |
| 132 |
char *application; |
| 133 |
int notify_mask; |
| 134 |
int notify_id; |
| 135 |
NOTIFY_RATE notify_rate[NOTIFY_RATE_MAX]; |
| 136 |
int monitor; |
| 137 |
} |
| 138 |
CONNECTION; |
| 139 |
|
| 140 |
extern CONNECTION *connections; |
| 141 |
extern int nconnections; |
| 142 |
extern int connection_want_level_notify; |
| 143 |
extern int connection_level_notify; |
| 144 |
|
| 145 |
#ifdef __STDC__ |
| 146 |
extern CONNECTION *connection_create (int type); |
| 147 |
extern void connection_destroy (CONNECTION *c); |
| 148 |
extern void connection_client_open (int fd); |
| 149 |
extern void connection_update (fd_set * read_fds, fd_set * write_fds); |
| 150 |
extern void connection_close (CONNECTION *c); |
| 151 |
extern void connection_cleanup (); |
| 152 |
extern void connection_update_fdset (CONNECTION *c); |
| 153 |
extern void connection_reply (CONNECTION *c, char *fmt,...); |
| 154 |
extern CONNECTION *connection_server_open (SERVER *server, SOUND *sound); |
| 155 |
extern void connection_server_reopen (CONNECTION *c); |
| 156 |
extern void connection_server_ping (CONNECTION *c); |
| 157 |
extern void connection_check_timeout (); |
| 158 |
extern void connection_timeout (CONNECTION *c); |
| 159 |
extern void connection_server_forward_sound (CONNECTION *c, SOUND *s); |
| 160 |
extern void connection_server_foward (CONNECTION *c); |
| 161 |
extern BUFFER *connection_list_create (); |
| 162 |
extern void connection_notify (CONNECTION *c, int wait_event,...); |
| 163 |
extern void connection_flow_pause (SPOOL *sp); |
| 164 |
extern void connection_flow_continue (SPOOL *sp); |
| 165 |
extern int connection_idle (); |
| 166 |
extern EVENT *event_create (int event_type,...); |
| 167 |
extern void event_first (CONNECTION *c, EVENT *e); |
| 168 |
extern void event_insert_before (CONNECTION *c, EVENT *e, int mask); |
| 169 |
extern void event_insert (CONNECTION *c, EVENT *e); |
| 170 |
extern void event_delete (CONNECTION *c, int replace); |
| 171 |
extern void event_update (CONNECTION *c); |
| 172 |
extern void event_destroy (EVENT *e); |
| 173 |
extern void event_replace (CONNECTION *c, EVENT *e); |
| 174 |
#else |
| 175 |
extern CONNECTION *connection_create ( /* int type */ ); |
| 176 |
extern void connection_destroy ( /* CONNECTION *c */ ); |
| 177 |
extern void connection_client_open ( /* int fd */ ); |
| 178 |
extern void connection_update ( /* fd_set *read_fds, fd_set *write_fds */ ); |
| 179 |
extern void connection_close ( /* CONNECTION *c */ ); |
| 180 |
extern void connection_cleanup (); |
| 181 |
extern void connection_update_fdset ( /* CONNECTION *c */ ); |
| 182 |
extern void connection_reply ( /* CONNECTION *c, char *fmt, ... */ ); |
| 183 |
extern CONNECTION *connection_server_open ( /* SERVER *server, SOUND *sound */ ); |
| 184 |
extern void connection_server_ping ( /* CONNECTION *c */ ); |
| 185 |
extern void connection_check_timeout (); |
| 186 |
extern void connection_timeout ( /* CONNECTION *c */ ); |
| 187 |
extern void connection_server_forward_sound ( /* CONNECTION *c, SOUND *s */ ); |
| 188 |
extern void connection_server_foward ( /* CONNECTION *c */ ); |
| 189 |
extern BUFFER *connection_list_create (); |
| 190 |
extern void connection_notify ( /* CONNECTION *c, int wait_event, ... */ ); |
| 191 |
extern void connection_flow_pause ( /* SPOOL *sp */ ); |
| 192 |
extern void connection_flow_continue ( /* SPOOL *sp */ ); |
| 193 |
extern int connection_idle (); |
| 194 |
extern EVENT *event_create ( /* int event_type, ... */ ); |
| 195 |
extern void event_first ( /* CONNECTION *c, EVENT *e */ ); |
| 196 |
extern void event_insert_before ( /* CONNECTION *c, EVENT *e, int mask */ ); |
| 197 |
extern void event_insert ( /* CONNECTION *c, EVENT *e */ ); |
| 198 |
extern void event_delete ( /* CONNECTION *c, int replace */ ); |
| 199 |
extern void event_update ( /* CONNECTION *c */ ); |
| 200 |
extern void event_destroy ( /* EVENT *e */ ); |
| 201 |
extern void event_replace ( /* CONNECTION *c, EVENT *e */ ); |
| 202 |
#endif |
| 203 |
|
| 204 |
#endif /* _connection_h */ |