2 * This file is part of DisOrder.
3 * Copyright (C) 2004, 2005, 2006 Richard Kettlewell
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
30 /* memory allocation **********************************************************/
32 void *disorder_malloc(size_t);
33 void *disorder_realloc(void *, size_t);
34 /* As malloc/realloc, but
35 * 1) succeed or call fatal
36 * 2) always clear (the unused part of) the new allocation
37 * 3) are garbage-collected
40 void *disorder_malloc_noptr(size_t);
41 void *disorder_realloc_noptr(void *, size_t);
42 char *disorder_strdup(const char *);
43 char *disorder_strndup(const char *, size_t);
44 /* As malloc/realloc/strdup, but
45 * 1) succeed or call fatal
46 * 2) are garbage-collected
47 * 3) allocated space must not contain any pointers
49 * {xmalloc,xrealloc}_noptr don't promise to clear the new space
54 int disorder_snprintf(char buffer[], size_t bufsize, const char *fmt, ...)
55 __attribute__((format (printf, 3, 4)));
58 int disorder_asprintf(char **rp, const char *fmt, ...)
59 __attribute__((format (printf, 2, 3)));
60 /* like asprintf but uses xmalloc_noptr() */
64 int disorder_snprintf(char buffer[], size_t bufsize, const char *fmt, ...);
67 int disorder_asprintf(char **rp, const char *fmt, ...);
68 /* like asprintf but uses xmalloc_noptr() */
73 /* logging ********************************************************************/
75 void disorder_error(int errno_value, const char *fmt, ...);
76 /* report an error. If errno_value is nonzero then the errno string
79 void disorder_fatal(int errno_value, const char *fmt, ...);
80 /* report an error and terminate. If errno_value is nonzero then the
81 * errno string is included. This is the only safe way to terminate
84 void disorder_info(const char *fmt, ...);
87 /* track database *************************************************************/
89 int disorder_track_exists(const char *track);
90 /* return true if the track exists. */
92 const char *disorder_track_get_data(const char *track, const char *key);
93 /* get the value for @key@ (xstrdup'd) */
95 int disorder_track_set_data(const char *track,
96 const char *key, const char *value);
97 /* set the value of @key@ to @value@, or remove it if @value@ is a null
98 * pointer. Return 0 on success, -1 on error. */
100 const char *disorder_track_random(void); /* server plugins only */
101 /* return the name of a random track */
103 /* plugin interfaces **********************************************************/
105 long disorder_tracklength(const char *track, const char *path);
106 /* compute the length of the track. @track@ is the UTF-8 name of the
107 * track, @path@ is the file system name (or 0 for tracks that don't
108 * exist in the filesystem). The return value should be a positive
109 * number of seconds, 0 for unknown or -1 if an error occurred. */
111 void disorder_scan(const char *root);
112 /* write a list of path names below @root@ to standard output. */
114 int disorder_check(const char *root, const char *path);
115 /* Recheck a track, given its root and path name. Return 1 if it
116 * exists, 0 if it does not exist and -1 if an error occurred. */
118 void disorder_notify_play(const char *track,
119 const char *submitter);
120 /* we're going to play @track@. It was submitted by @submitter@
121 * (might be a null pointer) */
123 void disorder_notify_scratch(const char *track,
124 const char *submitter,
125 const char *scratcher,
127 /* @scratcher@ scratched @track@ after @seconds@. It was submitted by
128 * @submitter@ (might be a null pointer) */
130 void disorder_notify_not_scratched(const char *track,
131 const char *submitter);
132 /* @track@ (submitted by @submitter@, which might be a null pointer)
133 * was not scratched. */
135 void disorder_notify_queue(const char *track,
136 const char *submitter);
137 /* @track@ added to the queue by @submitter@ (never a null pointer) */
139 void disorder_notify_queue_remove(const char *track,
140 const char *remover);
141 /* @track@ removed from the queue by @remover@ (never a null pointer) */
143 void disorder_notify_queue_move(const char *track,
145 /* @track@ moved in the queue by @mover@ (never a null pointer) */
147 void disorder_notify_pause(const char *track,
149 /* TRACK was paused by PAUSER (might be a null pointer) */
151 void disorder_notify_resume(const char *track,
152 const char *resumer);
153 /* TRACK was resumed by PAUSER (might be a null pointer) */
155 /* player plugin interface ****************************************************/
157 extern const unsigned long disorder_player_type;
159 #define DISORDER_PLAYER_STANDALONE 0x00000000
160 /* this player plays sound directly */
162 #define DISORDER_PLAYER_RAW 0x00000001
163 /* player that sends raw samples to $DISORDER_RAW_FD */
165 #define DISORDER_PLAYER_TYPEMASK 0x000000ff
166 /* mask for player types */
168 #define DISORDER_PLAYER_PREFORK 0x00000100
169 /* call prefork function */
171 #define DISORDER_PLAYER_PAUSES 0x00000200
172 /* supports pausing */
174 void *disorder_play_prefork(const char *track);
175 /* Called outside the fork. Should not block. Returns a null pointer
178 * If _play_prefork is called then its return value is used as the
179 * DATA argument to the following functions. Otherwise the value of
180 * DATA argument is indeterminate and must not be used. */
182 void disorder_play_track(const char *const *parameters,
187 /* Called to play a track. Should either exec or only return when the
188 * track has finished. Should not call exit() (except after a
189 * succesful exec). Allowed to call _Exit(). */
191 int disorder_play_pause(long *playedp, void *data);
192 /* Pauses the playing track. If the track can be paused returns 0 and
193 * stores the number of seconds so far played via PLAYEDP, or sets it
194 * to -1 if this is not known. If the track cannot be paused then
195 * returns -1. Should not block.
198 void disorder_play_resume(void *data);
199 /* Restarts play after a pause. PLAYED is the value returned from the
200 * original pause operation. Should not block. */
202 void disorder_play_cleanup(void *data);
203 /* called to clean up DATA. Should not block. */
209 #endif /* DISORDER_H */