Introduce generic_recv_pre_select().
[paraslash.git] / recv.h
1 /*
2  * Copyright (C) 2005-2009 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         /** The output buffer. */
16         char *buf;
17         /** The amount of bytes in \a buf. */
18         size_t loaded;
19         /** Receiver-specific data. */
20         void *private_data;
21         /** Pointer to the error member of the consumer. */
22         int *output_error;
23         /** Pointer to the configuration data for this instance. */
24         void *conf;
25         /** The task associated with this instance. */
26         struct task task;
27         /** The receiver node is always the root of the buffer tree. */
28         struct btr_node *btrn;
29 };
30
31 /**
32  * Describes one supported paraslash receiver.
33  *
34  * \sa http_recv.c, udp_recv.c
35  */
36 struct receiver {
37         /**
38          * The name of the receiver.
39          */
40         const char *name;
41         /**
42          * The receiver init function.
43          *
44          * It must fill in all other function pointers and is assumed to succeed.
45          *
46          * \sa http_recv_init udp_recv_init.
47          */
48         void (*init)(struct receiver *r);
49         /**
50          * The command line parser of the receiver.
51          *
52          * It should check whether the command line options given by \a argc and \a
53          * argv are valid.  On success, it should return a pointer to the
54          * receiver-specific configuration data determined by \a argc and \a argv.
55          * Note that this might be called more than once with different values of
56          * \a argc and \a argv.
57          */
58         void *(*parse_config)(int argc, char **argv);
59         /**
60          * Open one instance of the receiver.
61          *
62          * This should allocate the output buffer of \a rn. and may also
63          * perform any other work necessary for retrieving the stream according
64          * to the configuration stored in the \a conf member of \a rn which is
65          * guaranteed to point to valid configuration data (as previously
66          * obtained from the config parser).
67          *
68          * \sa receiver_node::conf, receiver_node::buf.
69          */
70         int (*open)(struct receiver_node *rn);
71         /**
72          * Close this instance of the receiver.
73          *
74          * It should free all resources associated with given receiver node
75          * that were allocated during the corresponding open call.
76          *
77          * \sa receiver_node.
78          */
79         void (*close)(struct receiver_node *rn);
80         /**
81          * Deactivate the receiver.
82          *
83          * Clean up what init has allocated.
84          */
85         void (*shutdown)(void);
86         /**
87          * Add file descriptors to fd_sets and compute timeout for select(2).
88          *
89          * The pre_select function gets called from the driving application
90          * before entering its select loop. The receiver may use this hook to
91          * add any file descriptors to the sets of file descriptors given by \a
92          * s.
93          *
94          * \sa select(2), time.c struct task, struct sched.
95          */
96         void (*pre_select)(struct sched *s, struct task *t);
97         /**
98          * Evaluate the result from select().
99          *
100          * This hook gets called after the call to select(). It should check
101          * all file descriptors which were added to any of the the fd sets
102          * during the previous call to pre_select. According to the result, it
103          * may then use any non-blocking I/O to establish a connection or to
104          * receive the audio data.
105          *
106          * \sa select(2), struct receiver.
107          */
108         void (*post_select)(struct sched *s, struct task *t);
109
110         /** The two help texts of this receiver. */
111         struct ggo_help help;
112 };
113
114
115 /** \cond */
116 extern void http_recv_init(struct receiver *r);
117 #define HTTP_RECEIVER {.name = "http", .init = http_recv_init},
118 extern void dccp_recv_init(struct receiver *r);
119 #define DCCP_RECEIVER {.name = "dccp", .init = dccp_recv_init},
120 extern void udp_recv_init(struct receiver *r);
121 #define UDP_RECEIVER {.name = "udp", .init = udp_recv_init},
122
123 extern struct receiver receivers[];
124 /** \endcond */
125
126 /** Define an array of all available receivers. */
127 #define DEFINE_RECEIVER_ARRAY struct receiver receivers[] = { \
128         HTTP_RECEIVER \
129         DCCP_RECEIVER \
130         UDP_RECEIVER \
131         {.name = NULL}};
132
133 /** Iterate over all available receivers. */
134 #define FOR_EACH_RECEIVER(i) for (i = 0; receivers[i].name; i++)
135
136 void recv_init(void);
137 void *check_receiver_arg(char *ra, int *receiver_num);
138 void print_receiver_helps(int detailed);
139 int generic_recv_pre_select(struct sched *s, struct task *t);