use %zd instead of %d for size_t
[paraslash.git] / db.h
1 /*
2 * Copyright (C) 2005-2006 Andre Noll <maan@systemlinux.org>
3 *
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.
8 *
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.
13 *
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.
17 */
18
19 /** \file db.h data structures common to all database tools */
20
21 #include <sys/select.h>
22
23 enum supported_dbtools {DBT_DOPEY,
24 #ifdef HAVE_MYSQL
25 DBT_MYSQL,
26 #endif
27 NUM_DBTOOLS
28 };
29
30 int find_audio_files(const char *dirname, int (*f)(const char *, const char *));
31
32 /**
33 * describes one of para_server's supported database tools
34 *
35 * There is exactly one such struct for each supported database tool. During
36 * the startup part of para_server the \a init() function of the activated
37 * database tool gets called which fills in the other members.
38
39 *
40 *
41 */
42 struct dbtool {
43 /**
44 * name name of this database tool
45 */
46 const char *name;
47 /**
48 * the database init routine
49 *
50 * It should check its command line options and do all necessary initialization
51 * like connecting to a database server.
52 *
53 * A negative return value indicates an initialization error and means that
54 * this database tool should be ignored for now (it may later be activated
55 * again via the cdt command).
56 *
57 * If \a init() returns success (non-negative return value), it must have
58 * initialized in all non-optional function pointers of the given dbtool
59 * struct. Moreover, \a cmd_list must point to a NULL-terminated array which
60 * holds the list of all commands that are supported by this database tool.
61 */
62 int (*init)(struct dbtool *self);
63 /**
64 * list of commands supported by this dbtool
65 */
66 struct server_command *cmd_list;
67 /**
68 * pointer to function returning list of at most \a num audio files to be
69 * streamed next
70 *
71 * \a get_audio_file_list() must return a pointer to a array of at most \a num
72 * char* pointers (terminated by a NULL pointer), or NULL on errors. Both the
73 * array and its contents must be dynamically allocated and are freed by the
74 * caller.
75 *
76 */
77 char **(*get_audio_file_list)(unsigned int num);
78 /**
79 *
80 * the update hook
81 *
82 * The \a update_audio_file pointer is optional and need not be supplied. In this
83 * case it is not neccessary to init this pointer from within init(). If
84 * \a update_audio_file is non-NULL, the function it points to gets called
85 * whenever a new audio file was successfully loaded and is going to be
86 * streamed by any of paraslash's senders. The full path of the audio file is
87 * passed \a update_audio_file().
88 *
89 */
90 void (*update_audio_file)(char *audio_file);
91 /**
92 *
93 * shutdown this database tool and free all resources
94 *
95 * This gets called whenever the database tool changes (via the cdt command),
96 * or when para_server receives the HUP signal, or when para_server shuts down.
97 * It is assumed to succeed.
98 */
99 void (*shutdown)(void);
100 /**
101 *
102 * add file descriptors to fd_sets
103 *
104 * The pre_select function of the activated database tool gets called just
105 * before para_server enters its main select loop. The dbtool may add its own
106 * file descriptors to the \a rfds or the \a wfds set.
107 *
108 * If a file descriptor was added, \a max_fileno must be increased by
109 * this function, if neccessary.
110 *
111 * \sa select(2)
112 */
113 int (*pre_select)(fd_set *rfds, fd_set *wfds);
114 /**
115 * handle the file descriptors which are ready for I/O
116 *
117 * If the pre_select hook added one ore more file descriptors to the read or write
118 * set, this is the hook to check the result and do any I/O on those descriptors
119 * which are ready for reading/writing.
120 */
121 void (*post_select)(fd_set *rfds, fd_set *wfds);
122 /**
123 * each dbtool has its private data pointer */
124 void *private_data;
125 };
126
127 int mysql_dbtool_init(struct dbtool*);
128 int plm_dbtool_init(struct dbtool*);
129 int random_dbtool_init(struct dbtool*);
130