2 * Copyright (C) 2006 Andre Noll <maan@tuebingen.mpg.de>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file recv_common.c common functions of para_recv and para_audiod */
13 #include "recv_cmd.lsg.h"
18 #include "buffer_tree.h"
23 * Call the init function of each paraslash receiver.
29 FOR_EACH_RECEIVER(i) {
30 const struct lls_command *cmd = RECV_CMD(i);
31 const struct receiver *r = lls_user_data(cmd);
38 * Check if the given string is a valid receiver specifier.
40 * \param ra string of the form receiver_name [options...]
41 * \param lprp Filled in on success, undefined else.
43 * This function checks whether \a ra starts with the name of a receiver,
44 * optionally followed by options for that receiver. If a valid receiver name
45 * was found the remaining part of \a ra is passed to the receiver's config
48 * If a NULL pointer or an empty string is passed as the first argument, the
49 * hhtp receiver with no options is assumed.
51 * \return On success the number of the receiver is returned. On errors, the
52 * function calls exit(EXIT_FAILURE).
54 int check_receiver_arg(const char *ra, struct lls_parse_result **lprp)
56 int ret, argc, receiver_num;
57 char *errctx = NULL, **argv;
58 const struct lls_command *cmd;
63 argv = para_malloc(2 * sizeof(char*));
64 argv[0] = para_strdup("http");
67 ret = create_argv(ra, " \t\n", &argv);
69 PARA_EMERG_LOG("%s\n", para_strerror(-ret));
74 ret = lls(lls_lookup_subcmd(argv[0], recv_cmd_suite, &errctx));
76 PARA_EMERG_LOG("%s: %s\n", errctx? errctx : argv[0],
81 cmd = RECV_CMD(receiver_num);
82 ret = lls(lls_parse(argc, argv, cmd, lprp, &errctx));
85 PARA_ERROR_LOG("%s\n", errctx);
86 PARA_EMERG_LOG("%s\n", para_strerror(-ret));
95 * Print out the help texts to all receivers.
97 * \param detailed Whether to print the short or the detailed help.
99 void print_receiver_helps(bool detailed)
103 printf("\nAvailable receivers: ");
104 FOR_EACH_RECEIVER(i) {
105 const struct lls_command *cmd = RECV_CMD(i);
106 printf("%s%s", i? " " : "", lls_command_name(cmd));
109 FOR_EACH_RECEIVER(i) {
110 const struct lls_command *cmd = RECV_CMD(i);
111 char *help = detailed? lls_long_help(cmd) : lls_short_help(cmd);
114 printf("%s\n", help);
120 * Simple pre-select hook, used by all receivers.
122 * \param s Scheduler info.
123 * \param rn The receiver node.
125 * This requests a minimal delay from the scheduler if the status of the buffer
126 * tree node indicates an error/eof condition. No file descriptors are added to
127 * the fd sets of \a s.
129 * \return The status of the btr node of the receiver node, i.e. the return
130 * value of the underlying call to \ref btr_node_status().
132 int generic_recv_pre_select(struct sched *s, struct receiver_node *rn)
134 int ret = btr_node_status(rn->btrn, 0, BTR_NT_ROOT);