write: Simplify config parsers.
[paraslash.git] / write.h
1 /*
2 * Copyright (C) 2006-2010 Andre Noll <maan@systemlinux.org>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 /** \file write.h Writer-related structures. */
8
9 /** The list of supported writers. */
10 enum writer_enum {WRITER_ENUM};
11
12 /**
13 * Describes one running instance of a writer.
14 */
15 struct writer_node {
16 /** The number of this writer. */
17 int writer_num;
18 /** Writer-specific data. */
19 void *private_data;
20 /** The writer-specific configuration of this node. */
21 void *conf;
22 struct btr_node *btrn;
23 struct task task;
24 size_t min_iqs;
25 };
26
27 /** Describes one supported writer. */
28 struct writer {
29 /**
30 * The init function of the writer.
31 *
32 * It must fill in all other function pointers of the given
33 * writer structure.
34 */
35 void (*init)(struct writer *w);
36 /**
37 * The command line parser of the writer.
38 *
39 * It should check whether the command line options given by \a options
40 * are valid and return a pointer to the writer-specific configuration
41 * data determined by \a options. This function must either succeed or
42 * call exit(). Note that parse_config_or_die() might be called more
43 * than once with different values of \a options. \sa \ref
44 * free_config().
45 */
46 void *(*parse_config_or_die)(const char *options);
47 /**
48 * Dellocate all configuration resources.
49 *
50 * This should free whatever was allocated by \ref parse_config_or_die().
51 */
52 void (*free_config)(void *config);
53 /**
54 * Open one instance of this writer.
55 *
56 * This function should perform any work necessary to write the incoming
57 * stream. To this aim, it may allocate its private data structure and store
58 * a pointer to that structure via the given writer_node parameter.
59 */
60 int (*open)(struct writer_node *);
61 /**
62 * Prepare the fd sets for select.
63 *
64 * This is called from scheduler. It may use the sched pointer to add
65 * any file descriptors or to decrease the select timeout.
66 */
67 void (*pre_select)(struct sched *s, struct task *t);
68 /**
69 * Write audio data.
70 *
71 * Called from the post_select function of the writer node's task.
72 */
73 void (*post_select)(struct sched *s, struct task *t);
74 /**
75 * Close one instance of the writer.
76 *
77 * This function is assumed to succeed.
78 */
79 void (*close)(struct writer_node *);
80 /**
81 * Shutdown the writer
82 *
83 * This is a optional function pointer used for cleaning up.
84 */
85 void (*shutdown)(struct writer_node *);
86 struct ggo_help help;
87 btr_command_handler execute;
88 };
89
90 /** Loop over each supported writer. */
91 #define FOR_EACH_WRITER(i) for (i = 0; i < NUM_SUPPORTED_WRITERS; i++)
92
93 /** Declare the init functions of all supported writers. */
94 DECLARE_WRITER_INITS;
95
96 /** Array containing the name of each writer. */
97 extern const char *writer_names[];
98
99 /** The writer structure for each supported writer. */
100 extern struct writer writers[NUM_SUPPORTED_WRITERS];