2 * Copyright (C) 2005-2006 Andre Noll <maan@systemlinux.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
19 /** \file db.h data structures common to all audio file selectors */
21 #include <sys/select.h>
24 int find_audio_files(const char *dirname, int (*f)(const char *, const char *));
27 * describes one of para_server's supported database tools
29 * There is exactly one such struct for each supported database tool. During
30 * the startup part of para_server the \a init() function of the activated
31 * database tool gets called which fills in the other members.
36 struct audio_file_selector {
38 * name name of this database tool
42 * the database init routine
44 * It should check its command line options and do all necessary initialization
45 * like connecting to a database server.
47 * A negative return value indicates an initialization error and means that
48 * this database tool should be ignored for now (it may later be activated
49 * again via the cdt command).
51 * If \a init() returns success (non-negative return value), it must have
52 * initialized in all non-optional function pointers of the given selector
53 * struct. Moreover, \a cmd_list must point to a NULL-terminated array which
54 * holds the list of all commands that are supported by this database tool.
56 int (*init)(struct audio_file_selector *self);
58 * list of commands supported by this selector
60 struct server_command *cmd_list;
62 * pointer to function returning list of at most \a num audio files to be
65 * \a get_audio_file_list() must return a pointer to a array of at most \a num
66 * char* pointers (terminated by a NULL pointer), or NULL on errors. Both the
67 * array and its contents must be dynamically allocated and are freed by the
71 char **(*get_audio_file_list)(unsigned int num);
76 * The \a update_audio_file pointer is optional and need not be supplied. In this
77 * case it is not neccessary to init this pointer from within init(). If
78 * \a update_audio_file is non-NULL, the function it points to gets called
79 * whenever a new audio file was successfully loaded and is going to be
80 * streamed by any of paraslash's senders. The full path of the audio file is
81 * passed \a update_audio_file().
84 void (*update_audio_file)(char *audio_file);
87 * shutdown this database tool and free all resources
89 * This gets called whenever the database tool changes (via the cdt command),
90 * or when para_server receives the HUP signal, or when para_server shuts down.
91 * It is assumed to succeed.
93 void (*shutdown)(void);
96 * add file descriptors to fd_sets
98 * The pre_select function of the activated database tool gets called just
99 * before para_server enters its main select loop. The selector may add its own
100 * file descriptors to the \a rfds or the \a wfds set.
102 * If a file descriptor was added, \a max_fileno must be increased by
103 * this function, if neccessary.
107 int (*pre_select)(fd_set *rfds, fd_set *wfds);
109 * handle the file descriptors which are ready for I/O
111 * If the pre_select hook added one ore more file descriptors to the read or write
112 * set, this is the hook to check the result and do any I/O on those descriptors
113 * which are ready for reading/writing.
115 void (*post_select)(fd_set *rfds, fd_set *wfds);
117 * each selector has its private data pointer */
121 int mysql_dbtool_init(struct audio_file_selector*);
122 int plm_dbtool_init(struct audio_file_selector*);
123 int random_dbtool_init(struct audio_file_selector*);