chiark / gitweb /
"make distcheck" now passes
[disorder] / doc / disorder.3
1 .\"
2 .\" Copyright (C) 2004-2008 Richard Kettlewell
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, but
10 .\" WITHOUT ANY WARRANTY; without even the implied warranty of
11 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 .\" 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-1307
17 .\" USA
18 .\"
19 .TH disorder 3
20 .SH NAME
21 disorder \- plugin interface to DisOrder jukebox
22 .SH SYNOPSIS
23 .B "#include <disorder.h>"
24 .SH DESCRIPTION
25 This header file defines the plugin interface to DisOrder.
26 .PP
27 The first half of this man page describes the functions DisOrder
28 provides to plugins; the second half describes the functions that
29 plugins must provide.
30 .SH "MEMORY ALLOCATION"
31 DisOrder uses a garbage collector internally.
32 Therefore it is recommended that plugins use the provided memory
33 allocation interface, rather than calling \fBmalloc\fR(3) etc directly.
34 .PP
35 .nf
36 \fBvoid *disorder_malloc(size_t);
37 void *disorder_realloc(void *, size_t);
38 .fi
39 .IP
40 These functions behave much like \fBmalloc\fR(3) and \fBrealloc\fR(3)
41 except that they never fail; they always zero out the memory
42 allocated; and you do not need to free the result.
43 .IP
44 They may still return a null pointer if asked for a 0-sized
45 allocation.
46 .PP
47 .nf
48 \fBvoid *disorder_malloc_noptr(size_t);
49 void *disorder_realloc_noptr(void *, size_t);
50 .fi
51 .IP
52 These functions are like \fBmalloc\fR(3) and \fBrealloc\fR(3)
53 except that they never fail and you must not put any pointer
54 values in the allocated memory.
55 .IP
56 They may still return a null pointer if asked for a 0-sized
57 allocation.
58 They do not guarantee to zero out the memory allocated.
59 .PP
60 .nf
61 \fBchar *disorder_strdup(const char *);
62 char *disorder_strndup(const char *, size_t);
63 .fi
64 .IP
65 These functions are like \fBstrdup\fR(3) and \fBstrndup\fR(3) except
66 that they never fail and you do not need to free the result.
67 .PP
68 .nf
69 \fBint disorder_asprintf(char **rp, const char *fmt, ...);
70 int disorder_snprintf(char buffer[], size_t bufsize,
71                       const char *fmt, ...);
72 .fi
73 .IP
74 These function are like \fBsnprintf\fR(3) and \fBasprintf\fR(3).
75 .B disorder_asprintf
76 never fails on memory allocation and
77 you do not need to free the results.
78 .IP
79 Floating point conversions and wide character support are not
80 currently implemented.
81 .IP
82 These functions will cope with UTF-8 even if the current locale uses
83 some other encoding.
84 .PP
85 "Never fail" in the above means that the process is terminated on error.
86 .SH LOGGING
87 Standard error doesn't reliably go anywhere in current versions of DisOrder,
88 and whether syslog is to be used varies depending on how the program is
89 invoked.
90 Therefore plugins should use these functions to log any errors or
91 informational messages.
92 .PP
93 .nf
94 \fBvoid disorder_error(int errno_value, const char *fmt, ...);
95 .fi
96 .IP
97 Log an error message.
98 If \fBerrno_value\fR is not 0 then the relevant
99 string is included in the error message.
100 .PP
101 .nf
102 \fBvoid disorder_fatal(int errno_value, const char *fmt, ...);
103 .fi
104 .IP
105 Log an error message and then terminate the process.
106 If \fBerrno_value\fR is not 0 then the relevant string is included in the
107 error message.
108 .IP
109 .B disorder_fatal
110 is the right way to terminate the process if a fatal error arises.
111 You shouldn't usually try to use \fBexit\fR(3) or \fB_exit\fR(2).
112 .PP
113 .nf
114 \fBvoid disorder_info(const char *fmt, ...);
115 .fi
116 .IP
117 Log a message.
118 .IP
119 .SH "TRACK DATABASE"
120 The functions in this section provide a way of accessing the track database.
121 In server plugins these access the database directly; in client plugins the
122 requests are transmitted to the server over a socket.
123 .PP
124 All strings in this section are encoded using UTF-8.
125 .PP
126 .nf
127 \fBint disorder_track_exists(const char *track);
128 .fi
129 .IP
130 This function returns non-0 if \fBtrack\fR exists and 0 if it does
131 not.
132 .PP
133 .nf
134 \fBconst char *disorder_track_get_data(const char *track,
135                                     const char *key);
136 .fi
137 .IP
138 This function looks up the value of \fBkey\fR for \fBtrack\fR and
139 returns a pointer to a copy of it.
140 Do not bother to free the pointer.
141 If the track or key are not found a null pointer is returned.
142 .PP
143 .nf
144 \fBint disorder_track_set_data(const char *track,
145                             const char *key,
146                             const char *value);
147 .fi
148 .IP
149 This function sets the value of \fBkey\fR for \fBtrack\fR to
150 \fBvalue\fR.
151 On success, 0 is returned; on error, -1 is returned.
152 .IP
153 If \fBvalue\fR is a null pointer then the preference is deleted.
154 .IP
155 Values starting with an underscore are stored in the tracks database,
156 and are lost if the track is deleted; they should only ever have
157 values that can be regenerated on demand.
158 Other values are stored in the prefs database and never get
159 automatically deleted.
160 .SH "PLUGIN FUNCTIONS"
161 This section describes the functions that you must implement to write various
162 plugins.
163 All of the plugins have at least one standard implementation available
164 in the DisOrder source.
165 .PP
166 Some functions are listed as only available in server plugins.
167 Currently this means that they are not even defined outside the
168 server.
169 .PP
170 All strings in this section are encoded using UTF-8.
171 .SS "Tracklength Plugins"
172 These are server plugins defined by the \fBtracklength\fR directive.
173 .PP
174 .nf
175 \fBlong disorder_tracklength(const char *track,
176                           const char *path);
177 .fi
178 .IP
179 Called to calculate the length of a track.
180 \fBtrack\fR is the track name (UTF-8) and \fBpath\fR is the path
181 name if there was one, or a null pointer otherwise.
182 \fBpath\fR will be the same byte string return from
183 the scanner plugin, and so presumably encoded according to the
184 filesystem encoding.
185 .IP
186 To clarify this point, if the track must be opened to compute its
187 length, you would normally use \fBpath\fR and not \fBtrack\fR.
188 .IP
189 If the return value is positive it should be the track length in
190 seconds (round up if it is not an integral number of seconds long).
191 .IP
192 If the return value is zero then the track length is unknown.
193 .IP
194 If the return value is negative then an error occurred determining the
195 track length.
196 .PP
197 Tracklength plugins are invoked from a subprocess of the server, so
198 they can block without disturbing the server's operation.
199 .SS notify.so
200 This is a server plugin.
201 .PP
202 .nf
203 \fBvoid disorder_notify_play(const char *track,
204                           const char *submitter);
205 .fi
206 .IP
207 Called when \fBtrack\fR is about to be played.
208 \fBsubmitter\fR identifies the submitter or is a null pointer if
209 the track was picked for random play.
210 .PP
211 .nf
212 \fBvoid disorder_notify_scratch(const char *track,
213                              const char *submitter,
214                              const char *scratcher,
215                              int seconds);
216 .fi
217 .IP
218 Called when \fBtrack\fR is scratched by \fBscratcher\fR.
219 \fBsubmitter\fR identifies the submitter or is a null pointer if
220 the track was picked for random play.
221 \fBseconds\fR is the number of seconds since the track started playing.
222 .PP
223 .nf
224 \fBvoid disorder_notify_not_scratched(const char *track,
225                                    const char *submitter);
226 .fi
227 .IP
228 Called when \fBtrack\fR completes without being scratched (an error might have
229 occurred though).
230 \fBsubmitter\fR identifies the submitter or is a null pointer if the
231 track was picked for random play.
232 .PP
233 .nf
234 \fBvoid disorder_notify_queue(const char *track,
235                            const char *submitter);
236 .fi
237 .IP
238 Called when \fBtrack\fR is added to the queue by \fBsubmitter\fR
239 (which is never a null pointer).
240 Not called for scratches.
241 .PP
242 .nf
243 \fBvoid disorder_notify_queue_remove(const char *track,
244                                   const char *remover);
245 .fi
246 .IP
247 Called when \fBtrack\fR is removed from queue by \fBremover\fR (which
248 is never a null pointer).
249 .PP
250 .nf
251 \fBvoid disorder_notify_queue_move(const char *track,
252                                 const char *remover);
253 .fi
254 .IP
255 Called when \fBtrack\fR is moved in the queue by \fBmover\fR
256 (which is never a null pointer).
257 .PP
258 .nf
259 \fBvoid disorder_notify_pause(const char *track,
260                            const char *who);
261 .fi
262 .IP
263 Called when \fBtrack\fR is paused by \fBwho\fR
264 (which might be a null pointer).
265 .PP
266 .nf
267 \fBvoid disorder_notify_resume(const char *track,
268                             const char *who);
269 .fi
270 .IP
271 Called when \fBtrack\fR is resumed by \fBwho\fR
272 (which might be a null pointer).
273 .SS "Scanner Plugins"
274 Scanner plugins are server plugins and may have any name; they are
275 chosen via the configuration file.
276 .PP
277 .nf
278 \fBvoid disorder_scan(const char *root);
279 .fi
280 .IP
281 Write a list of files below \fBroot\fR to standard output.
282 Each filename should be in the encoding defined for this root in the
283 configuration file and should be terminated by character 0.
284 .IP
285 It is up to the plugin implementor whether they prefer to use stdio or
286 write to file descriptor 1 directly.
287 .IP
288 All the filenames had better start with \fBroot\fR as this is used to
289 match them back up to the right collection to call
290 \fBdisorder_check\fR on.
291 .PP
292 .nf
293 \fBint disorder_check(const char *root, const char *path);
294 .fi
295 .IP
296 Check whether file \fBpath\fR under \fBroot\fR still exists.
297 Should return 1 if it exists, 0 if it does not and -1 on error.
298 This is run in the main server process.
299 .PP
300 Both scan and recheck are executed inside a subprocess, so it will not
301 break the server if they block for an extended period (though of
302 course, they should not gratuitously take longer than necessary to do
303 their jobs).
304 .SS "Player plugins"
305 Player plugins are server plugins and may have any name; they are
306 chosen via the configuration file.
307 .PP
308 .nf
309 extern const unsigned long disorder_player_type;
310 .fi
311 .IP
312 This defines the player type and capabilities.
313 It should consist of a single type value ORed with any number of
314 capability values.
315 The following are known type values:
316 .RS
317 .TP
318 .B DISORDER_PLAYER_STANDALONE
319 A standalone player that writes directly to some suitable audio
320 device.
321 .TP
322 .B DISORDER_PLAYER_RAW
323 A player that writes raw samples to \fB$DISORDER_RAW_FD\fR, for
324 instance by using the \fBdisorder\fR libao driver.
325 .RE
326 .IP
327 Known capabilities are:
328 .RS
329 .TP
330 .B DISORDER_PLAYER_PREFORK
331 Supports the prefork and cleanup calls.
332 .TP
333 .B DISORDER_PLAYER_PAUSES
334 Supports the pause and resume calls.
335 .RE
336 .PP
337 .nf
338 \fBvoid *disorder_play_prefork(const char *track);
339 .fi
340 .IP
341 Called before a track is played, if \fB_PREFORK\fR is set.
342 \fBtrack\fR is the name of the track in UTF-8.
343 This function must never block, as it runs inside the main loop of the server.
344 .IP
345 The return value will be passed to the functions below as \fBdata\fR.
346 On error, a null pointer should be returned.
347 .PP
348 .nf
349 \fBvoid disorder_play_cleanup(void *data);
350 .fi
351 .IP
352 Called after a track has been completed, if \fB_PREFORK\fR is set, for
353 instance to release the memory used by \fBdata\fR.
354 This function must never block, as it runs inside the main loop of the server.
355 .PP
356 .nf
357 \fBvoid disorder_play_track(const char *const *parameters,
358                          int nparameters,
359                          const char *path,
360                          const char *track,
361                          void *data);
362 .fi
363 .IP
364 Play a track.
365 .IP
366 \fBpath\fR is the path name as originally encoded in the filesystem.
367 This is the value you should ultimately pass to \fBopen\fR(2).
368 .IP
369 \fBtrack\fR is the path name converted to UTF-8.
370 This value (possibly converted to some other encoding) should be used
371 in any logs, etc.
372 .IP
373 If there is no meaningful path, or if the track is a scratch (where no
374 filename encoding information is available), \fBpath\fR will be equal
375 to \fBtrack\fR.
376 .IP
377 The parameters are any additional arguments
378 supplied to the \fBplayer\fR configuration file command.
379 .IP
380 This function is always called inside a fork, and it should not return
381 until playing has finished.
382 .IP
383 DisOrder sends the subprocess a signal if the track is to be scratched
384 (and when \fBdisorderd\fR is shut down).
385 By default this signal is \fBSIGKILL\fR but it can be reconfigured.
386 .PP
387 .nf
388 \fBint disorder_play_pause(long *playedp,
389                         void *data);
390 .fi
391 .IP
392 Pauses the current track, for players that support pausing.
393 This function must never block, as it runs inside the main loop of the
394 server.
395 .IP
396 On success, should return 0 and set \fB*playedp\fR to the number of
397 seconds played so far of this track, or to -1 if this cannot be
398 determined.
399 .IP
400 On error, should return -1.
401 .PP
402 .nf
403 \fBvoid disorder_play_resume(void *data);
404 .fi
405 .IP
406 Resume playing the current track after a pause.
407 This function must never block, as it runs inside the main loop of the server.
408 .SH NOTES
409 There is no special DisOrder library to link against; the symbols are
410 exported by the executables themselves.
411 (You should NOT try to link against \fB-ldisorder\fR.)
412 Plugins must be separately
413 linked against any other libraries they require, even if the DisOrder
414 executables are already linked against them.
415 .PP
416 The easiest approach is probably to develop the plugin inside the
417 DisOrder tree; then you can just use DisOrder's build system.
418 This might also make it easier to submit patches if you write something of
419 general utility.
420 .PP
421 Failing that you can use Libtool, if you make sure to pass the
422 \fB-module\fR option.
423 For current versions of DisOrder you only need the shared object
424 itself, not the \fB.la\fR file.
425 .PP
426 If you know the right runes for your toolchain you could also build
427 the modules more directly.
428 .PP
429 It is possible, up to a point, to implement several plugin interfaces
430 from within a single shared object.
431 If you ever use any of the functions that are listed as only being
432 available in server plugins, though, then you can only use the
433 resulting shared object as a server plugin.
434 .SH "SEE ALSO"
435 .BR disorderd (8),
436 .BR disorder (1),
437 .BR disorder_config (5)
438 .\" Local Variables:
439 .\" mode:nroff
440 .\" End: