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