Merge branch 'refs/heads/t/lopsub'
[paraslash.git] / recv.h
1 /*
2 * Copyright (C) 2005 Andre Noll <maan@tuebingen.mpg.de>
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 const struct receiver *receiver;
15 /** Receiver-specific data. */
16 void *private_data;
17 /** The parsed command line options for this instance. */
18 struct lls_parse_result *lpr;
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 optional receiver init function.
48 *
49 * Performs any initialization needed before the receiver can be opened.
50 *
51 * \sa http_recv_init udp_recv_init.
52 */
53 void (*init)(void);
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, void *context);
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 fd sets during
91 * the previous call to pre_select. According to the result, it may
92 * 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 int (*post_select)(struct sched *s, void *context);
98
99 /**
100 * Answer a buffer tree query.
101 *
102 * This optional function pointer is used for inter node communications
103 * of the buffer tree nodes. See \ref btr_command_handler for details.
104 */
105 btr_command_handler execute;
106 };
107
108 #define RECV_CMD(_num) (lls_cmd(_num, recv_cmd_suite))
109
110 #define RECV_CMD_OPT_RESULT(_recv, _opt, _lpr) \
111 (lls_opt_result(LSG_RECV_CMD_ ## _recv ## _OPT_ ## _opt, _lpr))
112 #define RECV_CMD_OPT_GIVEN(_recv, _opt, _lpr) \
113 (lls_opt_given(RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
114 #define RECV_CMD_OPT_STRING_VAL(_recv, _opt, _lpr) \
115 (lls_string_val(0, RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
116 #define RECV_CMD_OPT_UINT32_VAL(_recv, _opt, _lpr) \
117 (lls_uint32_val(0, RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
118 #define RECV_CMD_OPT_INT32_VAL(_recv, _opt, _lpr) \
119 (lls_int32_val(0, RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
120
121 /** Iterate over all available receivers. */
122 #define FOR_EACH_RECEIVER(i) for (i = 1; lls_cmd(i, recv_cmd_suite); i++)
123
124 void recv_init(void);
125 int check_receiver_arg(const char *ra, struct lls_parse_result **lprp);
126 void print_receiver_helps(bool detailed);
127 int generic_recv_pre_select(struct sched *s, struct receiver_node *rn);