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.
25 * Receivers employ the user_data feature of the lopsub library: Each receiver
26 * of the recv_cmd suite defines a struct receiver as its user data.
27 * recv_init() obtains a pointer to this structure by calling lls_user_data().
28 * If the receiver has an init function (i.e., if ->init is not NULL), ->init()
29 * is called to initialize the receiver.
35 FOR_EACH_RECEIVER(i) {
36 const struct lls_command *cmd = RECV_CMD(i);
37 const struct receiver *r = lls_user_data(cmd);
44 * Check if the given string is a valid receiver specifier.
46 * \param ra string of the form receiver_name [options...]
47 * \param lprp Filled in on success, undefined else.
49 * This function checks whether \a ra starts with the name of a receiver,
50 * optionally followed by options for that receiver. If a valid receiver name
51 * was found the remaining part of \a ra is passed to the receiver's config
54 * If a NULL pointer or an empty string is passed as the first argument, the
55 * hhtp receiver with no options is assumed.
57 * \return On success the number of the receiver is returned. On errors, the
58 * function calls exit(EXIT_FAILURE).
60 int check_receiver_arg(const char *ra, struct lls_parse_result **lprp)
62 int ret, argc, receiver_num;
63 char *errctx = NULL, **argv;
64 const struct lls_command *cmd;
69 argv = para_malloc(2 * sizeof(char*));
70 argv[0] = para_strdup("http");
73 ret = create_argv(ra, " \t\n", &argv);
75 PARA_EMERG_LOG("%s\n", para_strerror(-ret));
80 ret = lls(lls_lookup_subcmd(argv[0], recv_cmd_suite, &errctx));
82 PARA_EMERG_LOG("%s: %s\n", errctx? errctx : argv[0],
87 cmd = RECV_CMD(receiver_num);
88 ret = lls(lls_parse(argc, argv, cmd, lprp, &errctx));
91 PARA_ERROR_LOG("%s\n", errctx);
92 PARA_EMERG_LOG("%s\n", para_strerror(-ret));
101 * Print out the help texts to all receivers.
103 * \param detailed Whether to print the short or the detailed help.
105 void print_receiver_helps(bool detailed)
109 printf("\nAvailable receivers: ");
110 FOR_EACH_RECEIVER(i) {
111 const struct lls_command *cmd = RECV_CMD(i);
112 printf("%s%s", i? " " : "", lls_command_name(cmd));
115 FOR_EACH_RECEIVER(i) {
116 const struct lls_command *cmd = RECV_CMD(i);
117 char *help = detailed? lls_long_help(cmd) : lls_short_help(cmd);
120 printf("%s\n", help);
126 * Simple pre-select hook, used by all receivers.
128 * \param s Scheduler info.
129 * \param rn The receiver node.
131 * This requests a minimal delay from the scheduler if the status of the buffer
132 * tree node indicates an error/eof condition. No file descriptors are added to
133 * the fd sets of \a s.
135 * \return The status of the btr node of the receiver node, i.e. the return
136 * value of the underlying call to \ref btr_node_status().
138 int generic_recv_pre_select(struct sched *s, struct receiver_node *rn)
140 int ret = btr_node_status(rn->btrn, 0, BTR_NT_ROOT);