recv: Make ->btrp and ->fd generic.
[paraslash.git] / recv.h
1 /*
2 * Copyright (C) 2005-2011 Andre Noll <maan@systemlinux.org>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 /** \file recv.h Receiver-related structures and exported symbols of recv_common.c. */
8
9 /**
10 * Describes one instance of a receiver.
11 */
12 struct receiver_node {
13 /** Points to the corresponding receiver. */
14 struct receiver *receiver;
15 /** Receiver-specific data. */
16 void *private_data;
17 /** Pointer to the configuration data for this instance. */
18 void *conf;
19 /** The task associated with this instance. */
20 struct task task;
21 /** The receiver node is always the root of the buffer tree. */
22 struct btr_node *btrn;
23 /** Each receiver node maintains a buffer pool for the received data. */
24 struct btr_pool *btrp;
25 /**
26 * The file descriptor to receive the stream.
27 *
28 * The pre_select function of the receiver adds this file descriptor to
29 * the set of file descriptors which are watched for readability or
30 * writability, depending on the state of the connection (if any).
31 *
32 * If \a fd is readable, the post_select function of the receiver reads
33 * data from this fd into the buffer pool area of \a btrp.
34 *
35 * \sa \ref receiver.
36 */
37 int fd;
38 };
39
40 /**
41 * Describes one supported paraslash receiver.
42 *
43 * \sa http_recv.c, udp_recv.c
44 */
45 struct receiver {
46 /**
47 * The name of the receiver.
48 */
49 const char *name;
50 /**
51 * The receiver init function.
52 *
53 * It must fill in all other function pointers and is assumed to succeed.
54 *
55 * \sa http_recv_init udp_recv_init.
56 */
57 void (*init)(struct receiver *r);
58 /**
59 * The command line parser of the receiver.
60 *
61 * It should check whether the command line options given by \a argc and \a
62 * argv are valid. On success, it should return a pointer to the
63 * receiver-specific configuration data determined by \a argc and \a argv.
64 * Note that this might be called more than once with different values of
65 * \a argc and \a argv.
66 */
67 void *(*parse_config)(int argc, char **argv);
68 /**
69 * Deallocate the configuration structure of a receiver node.
70 *
71 * This calls the receiver-specific cleanup function generated by
72 * gengetopt.
73 */
74 void (*free_config)(void *conf);
75 /**
76 * Open one instance of the receiver.
77 *
78 * This should allocate the output buffer of \a rn. and may also
79 * perform any other work necessary for retrieving the stream according
80 * to the configuration stored in the \a conf member of \a rn which is
81 * guaranteed to point to valid configuration data (as previously
82 * obtained from the config parser).
83 *
84 * \sa receiver_node::conf, receiver_node::buf.
85 */
86 int (*open)(struct receiver_node *rn);
87 /**
88 * Close this instance of the receiver.
89 *
90 * It should free all resources associated with given receiver node
91 * that were allocated during the corresponding open call.
92 *
93 * \sa receiver_node.
94 */
95 void (*close)(struct receiver_node *rn);
96 /**
97 * Add file descriptors to fd_sets and compute timeout for select(2).
98 *
99 * The pre_select function gets called from the driving application
100 * before entering its select loop. The receiver may use this hook to
101 * add any file descriptors to the sets of file descriptors given by \a
102 * s.
103 *
104 * \sa select(2), time.c struct task, struct sched.
105 */
106 void (*pre_select)(struct sched *s, struct task *t);
107 /**
108 * Evaluate the result from select().
109 *
110 * This hook gets called after the call to select(). It should check
111 * all file descriptors which were added to any of the the fd sets
112 * during the previous call to pre_select. According to the result, it
113 * may then use any non-blocking I/O to establish a connection or to
114 * receive the audio data.
115 *
116 * \sa select(2), struct receiver.
117 */
118 void (*post_select)(struct sched *s, struct task *t);
119
120 /** The two help texts of this receiver. */
121 struct ggo_help help;
122 };
123
124 /** Define an array of all available receivers. */
125 #define DEFINE_RECEIVER_ARRAY struct receiver receivers[] = { \
126 HTTP_RECEIVER \
127 DCCP_RECEIVER \
128 UDP_RECEIVER \
129 {.name = NULL}};
130
131 /** Iterate over all available receivers. */
132 #define FOR_EACH_RECEIVER(i) for (i = 0; receivers[i].name; i++)
133
134 void recv_init(void);
135 void *check_receiver_arg(char *ra, int *receiver_num);
136 void print_receiver_helps(int detailed);
137 int generic_recv_pre_select(struct sched *s, struct task *t);
138
139 /** \cond receiver */
140 extern void http_recv_init(struct receiver *r);
141 #define HTTP_RECEIVER {.name = "http", .init = http_recv_init},
142 extern void dccp_recv_init(struct receiver *r);
143 #define DCCP_RECEIVER {.name = "dccp", .init = dccp_recv_init},
144 extern void udp_recv_init(struct receiver *r);
145 #define UDP_RECEIVER {.name = "udp", .init = udp_recv_init},
146
147 extern struct receiver receivers[];
148 /** \endcond receiver */
149