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