replace standard GPL header by a one-line pointer to COPYING
[paraslash.git] / afs.h
1 /*
2 * Copyright (C) 2005-2007 Andre Noll <maan@systemlinux.org>
3 *
4 * Licensed under the GPL v2. For licencing details see COPYING.
5 */
6
7 /** \file afs.h data structures common to all audio file selectors */
8
9 #include <sys/select.h>
10
11
12 int find_audio_files(const char *dirname, int (*f)(const char *, const char *));
13
14 /**
15 * describes one supported audio file selector
16 *
17 * There is one such struct for each supported selector. During the startup
18 * part of para_server the \a init() function of the activated selector gets
19 * called which fills in all other function pointers.
20 *
21 */
22 struct audio_file_selector {
23 /**
24 * name name of this selector
25 */
26 const char *name;
27 /**
28 * the init routine of the selector
29 *
30 * It should check its command line options and do all necessary initialization
31 * like connecting to a database server.
32 *
33 * A negative return value indicates an initialization error and means that
34 * this selector should be ignored for now (it may later be activated again via
35 * the chs command).
36 *
37 * If \a init() returns success (non-negative return value), it must have
38 * initialized in all non-optional function pointers of the given selector
39 * struct. Moreover, \a cmd_list must point to a NULL-terminated array which
40 * holds the list of all commands that are supported by this selector.
41 */
42 int (*init)(struct audio_file_selector *self);
43 /**
44 * list of commands supported by this selector
45 */
46 struct server_command *cmd_list;
47 /**
48 * pointer to function returning list of at most \a num audio files to be
49 * streamed next
50 *
51 * \a get_audio_file_list() must return a pointer to a array of at most \a num
52 * char* pointers (terminated by a NULL pointer), or NULL on errors. Both the
53 * array and its contents must be dynamically allocated and are freed by the
54 * caller.
55 *
56 */
57 char **(*get_audio_file_list)(unsigned int num);
58 /**
59 *
60 * the update hook
61 *
62 * The \a update_audio_file pointer is optional and need not be supplied. In this
63 * case it is not neccessary to init this pointer from within init(). If
64 * \a update_audio_file is non-NULL, the function it points to gets called
65 * whenever a new audio file was successfully loaded and is going to be
66 * streamed by any of paraslash's senders. The full path of the audio file is
67 * passed \a update_audio_file().
68 *
69 */
70 void (*update_audio_file)(char *audio_file);
71 /**
72 *
73 * shutdown this selector and free all resources
74 *
75 * This gets called whenever the audio file selector changes. The reason for
76 * this change might be that some user sent the chs command, that para_server
77 * receives the HUP signal, or that para_server shuts down. It is assumed to
78 * succeed.
79 */
80 void (*shutdown)(void);
81 /**
82 *
83 * add file descriptors to fd_sets
84 *
85 * The pre_select function of the activated selector gets called just before
86 * para_server enters its main select loop. The selector may add its own file
87 * descriptors to the \a rfds or the \a wfds set.
88 *
89 * \return The highest-numbered file descriptor which was added to either of
90 * the two fd sets (or -1 if no file descriptors were added).
91 *
92 * \sa select(2)
93 */
94 int (*pre_select)(fd_set *rfds, fd_set *wfds);
95 /**
96 * handle the file descriptors which are ready for I/O
97 *
98 * If the pre_select hook added one ore more file descriptors to the read or write
99 * set, this is the hook to check the result and do any I/O on those descriptors
100 * which are ready for reading/writing.
101 */
102 void (*post_select)(fd_set *rfds, fd_set *wfds);
103 /**
104 * each selector has its private data pointer */
105 void *private_data;
106 };
107
108 int mysql_selector_init(struct audio_file_selector*);
109 int playlist_selector_init(struct audio_file_selector*);
110 int random_selector_init(struct audio_file_selector*);
111