Intoduce send_common.c and use it from the dccp sender.
[paraslash.git] / send.h
1 /*
2 * Copyright (C) 2005-2008 Andre Noll <maan@systemlinux.org>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 /** \file send.h Sender-related defines and structures. */
8
9 /** The sender subcommands. */
10 enum {SENDER_ADD, SENDER_DELETE, SENDER_ALLOW, SENDER_DENY, SENDER_ON, SENDER_OFF, NUM_SENDER_CMDS};
11
12 /**
13 * Describes one supported sender of para_server.
14 *
15 * \sa http_send.c ortp_send.c, dccp_send.c.
16 */
17 struct sender {
18 /** The name of the sender. */
19 const char *name;
20 /**
21 * The init function of this sender.
22 *
23 * It must fill in all function pointers of \a s as well as the \a
24 * client_cmds array, see below. It should also do all necessary
25 * preparations to init this sending facility, for example it could
26 * open a tcp port.
27 */
28 void (*init)(struct sender *s);
29 /**
30 * Return the help text of this sender.
31 *
32 * The result must be dynamically allocated and is freed by the caller.
33 */
34 char* (*help)(void);
35 /**
36 * Return current status info about this sender.
37 *
38 * The result must be dynamically allocated and is freed by the caller.
39 */
40 char* (*info)(void);
41 /**
42 * The send-hook.
43 *
44 * It gets called whenever para_server is playing and the current
45 * audio format handler indicates that another chunk of data should
46 * be sent now. The two parameters \a current_chunk and \a chunks_sent
47 * only differ if the stream was repositioned by the \a ff or \a jmp
48 * command. Of course, \a buf is a pointer to the chunk of data which
49 * should be sent, and \a len is the length of this buffer.
50 */
51 void (*send)(long unsigned current_chunk, long unsigned chunks_sent,
52 const char *buf, size_t len);
53 /**
54 * Add file descriptors to fd_sets.
55 *
56 * The pre_select function of each supported sender is called just before
57 * para_server enters its main select loop. Each sender may add its own
58 * file descriptors to the \a rfds or the \a wfds set.
59 *
60 * If a file descriptor was added, \a max_fileno must be increased by
61 * this function, if necessary.
62 *
63 * \sa select(2).
64 */
65 void (*pre_select)(int *max_fileno, fd_set *rfds, fd_set *wfds);
66 /**
67 * Handle the file descriptors which are ready for I/O.
68 *
69 * If the pre_select hook added one ore more file descriptors to the
70 * read or write set, this is the hook to check the result and do any
71 * I/O on those descriptors which are ready for reading/writing.
72 */
73 void (*post_select)(fd_set *rfds, fd_set *wfds);
74 /**
75 * Terminate all connected clients.
76 *
77 * This is called e.g. if the stop command was executed. It should make
78 * the clients aware of the end-of-file condition.
79 */
80 void (*shutdown_clients)(void);
81 /**
82 * Array of function pointers for the sender subcommands.
83 *
84 * Each sender may implement any subset of the sender commands by
85 * filling in the appropriate function pointer in the array. A \p NULL
86 * pointer means this command is not implemented by this sender.
87 */
88 int (*client_cmds[NUM_SENDER_CMDS])(struct sender_command_data*);
89 };
90
91 /** Describes one client, connected to a paraslash sender. */
92 struct sender_client {
93 /** The file descriptor of the client. */
94 int fd;
95 /** The socket "name" of the client. */
96 char *name;
97 /** The position of this client in the client list. */
98 struct list_head node;
99 /** Non-zero if audio file header has been sent. */
100 int header_sent;
101 /** The list of pending chunks for this client. */
102 struct chunk_queue *cq;
103 /** Data specific to the particular sender. */
104 void *private_data;
105 };
106
107 int open_sender(unsigned l4type, int port);
108 void shutdown_client(struct sender_client *sc);
109 void send_chunk(struct sender_client *sc, size_t max_bytes_per_write,
110 long unsigned current_chunk, const char *buf, size_t len);