2 * Copyright (C) 2006-2011 Andre Noll <maan@systemlinux.org>
4 * Licensed under the GPL v2. For licencing details see COPYING.
7 /** \file recv_common.c common functions of para_recv and para_audiod */
18 #include "buffer_tree.h"
20 DEFINE_RECEIVER_ARRAY
;
23 * Call the init function of each paraslash receiver.
30 receivers
[i
].init(&receivers
[i
]);
33 static void *parse_receiver_args(int receiver_num
, char *options
)
35 struct receiver
*r
= &receivers
[receiver_num
];
41 PARA_DEBUG_LOG("%s, options: %s\n", r
->name
,
42 options
? options
: "(none)");
44 PARA_DEBUG_LOG("options: %s\n", options
);
45 argc
= create_argv(options
, " \t", &argv
);
48 for (i
= argc
- 1; i
>= 0; i
--)
49 argv
[i
+ 1] = argv
[i
];
53 argv
= para_malloc(2 * sizeof(char*));
56 argv
[0] = make_message("%s_recv", r
->name
);
57 conf
= r
->parse_config(argc
, argv
);
58 for (i
= 0; i
< argc
; i
++)
65 * check if given string is a valid command line for any receiver
67 * \param \ra string of the form receiver_name:options
68 * \param receiver_num contains the number of the receiver upon success
70 * This function checks whether \a ra starts with the name of a supported
71 * paraslash receiver, optinally followed by a colon and any options for that
72 * receiver. If a valid receiver name was found and further are present, the
73 * remaining part of \a ra is passed to that receiver's config parser.
75 * \return On success, a pointer to the gengetopt args info struct is returned
76 * and \a receiver_num contains the number of the receiver. Otherwise this function
79 void *check_receiver_arg(char *ra
, int *receiver_num
)
83 PARA_DEBUG_LOG("checking %s\n", ra
);
84 for (j
= 0; receivers
[j
].name
; j
++) {
85 const char *name
= receivers
[j
].name
;
86 size_t len
= strlen(name
);
90 if (strncmp(name
, ra
, len
))
95 if (c
&& !receivers
[j
].parse_config
)
98 return parse_receiver_args(j
, c
? ra
+ len
+ 1: NULL
);
100 PARA_ERROR_LOG("receiver not found\n");
105 * Print out the help texts to all receivers.
107 * \param detailed Whether the detailed help should be printed.
109 void print_receiver_helps(int detailed
)
113 printf_or_die("\nAvailable receivers: \n\t");
115 printf_or_die("%s%s", i
? " " : "", receivers
[i
].name
);
116 printf_or_die("\n\n");
117 FOR_EACH_RECEIVER(i
) {
118 struct receiver
*r
= receivers
+ i
;
119 if (!r
->help
.short_help
)
121 printf_or_die("Options for %s:\n", r
->name
);
122 ggo_print_help(&r
->help
, detailed
);
127 * Simple pre-select hook, used by all receivers.
129 * \param s Scheduler info.
130 * \param t Determines the receiver node.
132 * This requests a minimal delay from the scheduler if the status of the buffer
133 * tree node indicates an error/eof condition. No file descriptors are added to
134 * the fd sets of \a s.
138 int generic_recv_pre_select(struct sched
*s
, struct task
*t
)
140 struct receiver_node
*rn
= container_of(t
, struct receiver_node
, task
);
141 int ret
= btr_node_status(rn
->btrn
, 0, BTR_NT_ROOT
);