2 * Copyright (C) 2005-2008 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file recv.c the stand-alone audio stream receiver */
17 #include "recv.cmdline.h"
22 /** the gengetopt args info struct */
23 struct recv_args_info conf;
25 /** always log to stderr */
26 INIT_STDERR_LOGGING(conf.loglevel_arg);
28 /** init array of error codes used by para_recv */
31 __noreturn static void print_help_and_die(void)
34 int i, d = conf.detailed_help_given;
35 const char **p = d? recv_args_info_detailed_help
36 : recv_args_info_help;
38 printf_or_die("%s\n\n", RECV_CMDLINE_PARSER_PACKAGE "-"
39 RECV_CMDLINE_PARSER_VERSION);
40 printf_or_die("%s\n\n", recv_args_info_usage);
42 printf_or_die("%s\n", *p);
44 printf_or_die("\nAvailable receivers: \n\t");
46 printf_or_die("%s%s", i? " " : "", receivers[i].name);
47 printf_or_die("\n\n");
48 FOR_EACH_RECEIVER(i) {
49 struct receiver *r = receivers + i;
51 if (!r->help.short_help)
53 printf_or_die("Options for %s:\n", r->name);
54 ggo_print_help(&r->help, d);
59 static void *parse_config(int argc, char *argv[], int *receiver_num)
61 if (recv_cmdline_parser(argc, argv, &conf))
63 HANDLE_VERSION_FLAG("recv", conf);
64 if (conf.help_given || conf.detailed_help_given)
66 return check_receiver_arg(conf.receiver_arg, receiver_num);
70 * the main function of para_recv
72 * \param argc number of arguments
73 * \param argv vector of arguments
75 * para_recv uses the specified receiver to receive an audio stream sent by
76 * para_server. The received data is written to stdout.
78 * \return \a EXIT_SUCCESS on success, \a EXIT_FAILURE on errors.
80 int main(int argc, char *argv[])
82 int ret, r_opened = 0, receiver_num;
83 struct receiver *r = NULL;
84 struct receiver_node rn;
85 struct stdout_task sot;
86 static struct sched s;
88 s.default_timeout.tv_sec = 1;
89 s.default_timeout.tv_usec = 0;
91 memset(&sot, 0, sizeof(struct stdout_task));
92 memset(&rn, 0, sizeof(struct receiver_node));
93 FOR_EACH_RECEIVER(ret)
94 receivers[ret].init(&receivers[ret]);
96 rn.conf = parse_config(argc, argv, &receiver_num);
98 PARA_EMERG_LOG("parse failed\n");
101 r = &receivers[receiver_num];
108 stdout_set_defaults(&sot);
110 sot.loaded = &rn.loaded;
111 sot.input_error = &rn.task.error;
112 register_task(&sot.task);
114 rn.task.pre_select = r->pre_select;
115 rn.task.post_select = r->post_select;
116 sprintf(rn.task.status, "receiver node");
117 register_task(&rn.task);
126 PARA_ERROR_LOG("%s\n", para_strerror(-ret));
127 return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;