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