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 \ref http_recv.c, \ref 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 void (*init)(void);
52 /**
53 * Open one instance of the receiver.
54 *
55 * This should allocate the output buffer of the given receiver node
56 * and prepare it for retrieving the audio stream according to the
57 * configuration stored in rn->lpr.
58 *
59 * \sa struct \ref receiver_node.
60 */
61 int (*open)(struct receiver_node *rn);
62 /**
63 * Close this instance of the receiver.
64 *
65 * It should free all resources associated with given receiver node
66 * that were allocated during the corresponding open call.
67 *
68 * \sa \ref receiver_node.
69 */
70 void (*close)(struct receiver_node *rn);
71 /**
72 * Add file descriptors to fd_sets and compute timeout for select(2).
73 *
74 * If this is not NULL, the function is called in each iteration of the
75 * scheduler's select loop. The receiver may define it to add file
76 * descriptors to the file descriptor sets given by s. Those will be
77 * monitored in the subsequent call to select(2). The function may also
78 * lower the timeout value of s to make select(2) return earlier if no
79 * file descriptors are ready for I/O.
80 *
81 * \sa select(2), \ref time.c, struct \ref sched.
82 */
83 void (*pre_select)(struct sched *s, void *context);
84 /**
85 * Evaluate the result from select(2).
86 *
87 * This is called after the call to select(2). It should check all file
88 * descriptors which were added to any of the fd sets in the previous
89 * call to ->pre_select() and perform (non-blocking) I/O operations on
90 * those fds which are ready for I/O, for example in order to establish
91 * a connection or to receive a part of the audio stream.
92 *
93 * \sa select(2), struct \ref receiver.
94 */
95 int (*post_select)(struct sched *s, void *context);
96 /**
97 * Answer a buffer tree query.
98 *
99 * This optional function pointer allows for inter node communication
100 * of the buffer tree nodes. See \ref btr_command_handler for details.
101 */
102 btr_command_handler execute;
103 };
104
105 #define RECV_CMD(_num) (lls_cmd(_num, recv_cmd_suite))
106
107 #define RECV_CMD_OPT_RESULT(_recv, _opt, _lpr) \
108 (lls_opt_result(LSG_RECV_CMD_ ## _recv ## _OPT_ ## _opt, _lpr))
109 #define RECV_CMD_OPT_GIVEN(_recv, _opt, _lpr) \
110 (lls_opt_given(RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
111 #define RECV_CMD_OPT_STRING_VAL(_recv, _opt, _lpr) \
112 (lls_string_val(0, RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
113 #define RECV_CMD_OPT_UINT32_VAL(_recv, _opt, _lpr) \
114 (lls_uint32_val(0, RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
115 #define RECV_CMD_OPT_INT32_VAL(_recv, _opt, _lpr) \
116 (lls_int32_val(0, RECV_CMD_OPT_RESULT(_recv, _opt, _lpr)))
117
118 /** Iterate over all available receivers. */
119 #define FOR_EACH_RECEIVER(i) for (i = 1; lls_cmd(i, recv_cmd_suite); i++)
120
121 void recv_init(void);
122 int check_receiver_arg(const char *ra, struct lls_parse_result **lprp);
123 void print_receiver_helps(bool detailed);
124 int generic_recv_pre_select(struct sched *s, struct receiver_node *rn);