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 * Check if the given string is a valid receiver specifier.
21 * \param ra string of the form receiver_name [options...]
22 * \param lprp Filled in on success, undefined else.
24 * This function checks whether \a ra starts with the name of a receiver,
25 * optionally followed by options for that receiver. If a valid receiver name
26 * was found the remaining part of \a ra is passed to the receiver's config
29 * If a NULL pointer or an empty string is passed as the first argument, the
30 * hhtp receiver with no options is assumed.
32 * \return On success the number of the receiver is returned. On errors, the
33 * function calls exit(EXIT_FAILURE).
35 int check_receiver_arg(const char *ra, struct lls_parse_result **lprp)
37 int ret, argc, receiver_num;
38 char *errctx = NULL, **argv;
39 const struct lls_command *cmd;
44 argv = alloc(2 * sizeof(char*));
45 argv[0] = para_strdup("http");
48 ret = create_argv(ra, " \t\n", &argv);
50 PARA_EMERG_LOG("%s\n", para_strerror(-ret));
55 ret = lls(lls_lookup_subcmd(argv[0], recv_cmd_suite, &errctx));
57 PARA_EMERG_LOG("%s: %s\n", errctx? errctx : argv[0],
62 cmd = RECV_CMD(receiver_num);
63 ret = lls(lls_parse(argc, argv, cmd, lprp, &errctx));
66 PARA_ERROR_LOG("%s\n", errctx);
67 PARA_EMERG_LOG("%s\n", para_strerror(-ret));
76 * Print out the help texts to all receivers.
78 * \param detailed Whether to print the short or the detailed help.
80 void print_receiver_helps(bool detailed)
84 printf("\nAvailable receivers: ");
85 FOR_EACH_RECEIVER(i) {
86 const struct lls_command *cmd = RECV_CMD(i);
87 printf("%s%s", i? " " : "", lls_command_name(cmd));
90 FOR_EACH_RECEIVER(i) {
91 const struct lls_command *cmd = RECV_CMD(i);
92 char *help = detailed? lls_long_help(cmd) : lls_short_help(cmd);
101 * Request a minimal timeout in case of buffer tree errors.
103 * \param s The scheduler instance.
104 * \param rn The buffer tree node is derived from this.
106 * If the buffer tree node of the given receiver node is in error or EOF state,
107 * a minimal I/O timeout is requested from the scheduler. Otherwise, the
108 * function does nothing. No file descriptors are asked to be monitored.
110 * \return The status of of the receiver node's buffer tree node. That is, the
111 * return value of the underlying call to \ref btr_node_status().
113 int generic_recv_pre_monitor(struct sched *s, struct receiver_node *rn)
115 int ret = btr_node_status(rn->btrn, 0, BTR_NT_ROOT);