2 * Copyright (C) 2005-2009 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 */
10 #include <sys/types.h>
18 #include "recv.cmdline.h"
24 /** the gengetopt args info struct */
25 struct recv_args_info conf;
28 /** Always log to stderr. */
29 INIT_STDERR_LOGGING(loglevel);
31 /** init array of error codes used by para_recv */
34 __noreturn static void print_help_and_die(void)
36 int d = conf.detailed_help_given;
37 const char **p = d? recv_args_info_detailed_help
38 : recv_args_info_help;
40 printf_or_die("%s\n\n", RECV_CMDLINE_PARSER_PACKAGE "-"
41 RECV_CMDLINE_PARSER_VERSION);
42 printf_or_die("%s\n\n", recv_args_info_usage);
44 printf_or_die("%s\n", *p);
45 print_receiver_helps(d);
49 static void *parse_config(int argc, char *argv[], int *receiver_num)
51 if (recv_cmdline_parser(argc, argv, &conf))
53 HANDLE_VERSION_FLAG("recv", conf);
54 if (conf.help_given || conf.detailed_help_given)
56 return check_receiver_arg(conf.receiver_arg, receiver_num);
60 * the main function of para_recv
62 * \param argc number of arguments
63 * \param argv vector of arguments
65 * para_recv uses the specified receiver to receive an audio stream sent by
66 * para_server. The received data is written to stdout.
68 * \return \a EXIT_SUCCESS on success, \a EXIT_FAILURE on errors.
70 int main(int argc, char *argv[])
72 int ret, r_opened = 0, receiver_num;
73 struct receiver *r = NULL;
74 struct receiver_node rn;
75 struct stdout_task sot;
76 static struct sched s;
78 s.default_timeout.tv_sec = 1;
79 s.default_timeout.tv_usec = 0;
81 memset(&sot, 0, sizeof(struct stdout_task));
82 memset(&rn, 0, sizeof(struct receiver_node));
85 rn.conf = parse_config(argc, argv, &receiver_num);
87 PARA_EMERG_LOG("parse failed\n");
90 loglevel = get_loglevel_by_name(conf.loglevel_arg);
91 r = &receivers[receiver_num];
98 stdout_set_defaults(&sot);
100 sot.loaded = &rn.loaded;
101 sot.input_error = &rn.task.error;
102 register_task(&sot.task);
104 rn.task.pre_select = r->pre_select;
105 rn.task.post_select = r->post_select;
106 sprintf(rn.task.status, "receiver node");
107 register_task(&rn.task);
116 PARA_ERROR_LOG("%s\n", para_strerror(-ret));
117 return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;