1 /* Copyright (C) 2006 Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */
3 /** \file recv_common.c common functions of para_recv and para_audiod */
9 #include "recv_cmd.lsg.h"
14 #include "buffer_tree.h"
19 * Call the init function of each paraslash receiver.
21 * Receivers employ the user_data feature of the lopsub library: Each receiver
22 * of the recv_cmd suite defines a struct receiver as its user data.
23 * recv_init() obtains a pointer to this structure by calling lls_user_data().
24 * If the receiver has an init function (i.e., if ->init is not NULL), ->init()
25 * is called to initialize the receiver.
31 FOR_EACH_RECEIVER(i) {
32 const struct lls_command *cmd = RECV_CMD(i);
33 const struct receiver *r = lls_user_data(cmd);
40 * Check if the given string is a valid receiver specifier.
42 * \param ra string of the form receiver_name [options...]
43 * \param lprp Filled in on success, undefined else.
45 * This function checks whether \a ra starts with the name of a receiver,
46 * optionally followed by options for that receiver. If a valid receiver name
47 * was found the remaining part of \a ra is passed to the receiver's config
50 * If a NULL pointer or an empty string is passed as the first argument, the
51 * hhtp receiver with no options is assumed.
53 * \return On success the number of the receiver is returned. On errors, the
54 * function calls exit(EXIT_FAILURE).
56 int check_receiver_arg(const char *ra, struct lls_parse_result **lprp)
58 int ret, argc, receiver_num;
59 char *errctx = NULL, **argv;
60 const struct lls_command *cmd;
65 argv = para_malloc(2 * sizeof(char*));
66 argv[0] = para_strdup("http");
69 ret = create_argv(ra, " \t\n", &argv);
71 PARA_EMERG_LOG("%s\n", para_strerror(-ret));
76 ret = lls(lls_lookup_subcmd(argv[0], recv_cmd_suite, &errctx));
78 PARA_EMERG_LOG("%s: %s\n", errctx? errctx : argv[0],
83 cmd = RECV_CMD(receiver_num);
84 ret = lls(lls_parse(argc, argv, cmd, lprp, &errctx));
87 PARA_ERROR_LOG("%s\n", errctx);
88 PARA_EMERG_LOG("%s\n", para_strerror(-ret));
97 * Print out the help texts to all receivers.
99 * \param detailed Whether to print the short or the detailed help.
101 void print_receiver_helps(bool detailed)
105 printf("\nAvailable receivers: ");
106 FOR_EACH_RECEIVER(i) {
107 const struct lls_command *cmd = RECV_CMD(i);
108 printf("%s%s", i? " " : "", lls_command_name(cmd));
111 FOR_EACH_RECEIVER(i) {
112 const struct lls_command *cmd = RECV_CMD(i);
113 char *help = detailed? lls_long_help(cmd) : lls_short_help(cmd);
116 printf("%s\n", help);
122 * Simple pre-select hook, used by all receivers.
124 * \param s Scheduler info.
125 * \param rn The receiver node.
127 * This requests a minimal delay from the scheduler if the status of the buffer
128 * tree node indicates an error/eof condition. No file descriptors are added to
129 * the fd sets of \a s.
131 * \return The status of the btr node of the receiver node, i.e. the return
132 * value of the underlying call to \ref btr_node_status().
134 int generic_recv_pre_select(struct sched *s, struct receiver_node *rn)
136 int ret = btr_node_status(rn->btrn, 0, BTR_NT_ROOT);