2 * This file is part of DisOrder.
3 * Copyright (C) 2004-2008 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 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU 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, see <http://www.gnu.org/licenses/>.
28 /* memory allocation **********************************************************/
30 void *disorder_malloc(size_t);
31 void *disorder_realloc(void *, size_t);
32 /* As malloc/realloc, but
33 * 1) succeed or call fatal
34 * 2) always clear (the unused part of) the new allocation
35 * 3) are garbage-collected
38 void *disorder_malloc_noptr(size_t);
39 void *disorder_realloc_noptr(void *, size_t);
40 char *disorder_strdup(const char *);
41 char *disorder_strndup(const char *, size_t);
42 /* As malloc/realloc/strdup, but
43 * 1) succeed or call fatal
44 * 2) are garbage-collected
45 * 3) allocated space must not contain any pointers
47 * {xmalloc,xrealloc}_noptr don't promise to clear the new space
52 int disorder_snprintf(char buffer[], size_t bufsize, const char *fmt, ...)
53 __attribute__((format (printf, 3, 4)));
56 int disorder_asprintf(char **rp, const char *fmt, ...)
57 __attribute__((format (printf, 2, 3)));
58 /* like asprintf but uses xmalloc_noptr() */
62 int disorder_snprintf(char buffer[], size_t bufsize, const char *fmt, ...);
65 int disorder_asprintf(char **rp, const char *fmt, ...);
66 /* like asprintf but uses xmalloc_noptr() */
71 /* logging ********************************************************************/
73 void disorder_error(int errno_value, const char *fmt, ...);
74 /* report an error. If errno_value is nonzero then the errno string
77 void disorder_fatal(int errno_value, const char *fmt, ...);
78 /* report an error and terminate. If errno_value is nonzero then the
79 * errno string is included. This is the only safe way to terminate
82 void disorder_info(const char *fmt, ...);
85 /* track database *************************************************************/
87 int disorder_track_exists(const char *track);
88 /* return true if the track exists. */
90 const char *disorder_track_get_data(const char *track, const char *key);
91 /* get the value for @key@ (xstrdup'd) */
93 int disorder_track_set_data(const char *track,
94 const char *key, const char *value);
95 /* set the value of @key@ to @value@, or remove it if @value@ is a null
96 * pointer. Return 0 on success, -1 on error. */
98 const char *disorder_track_random(void); /* server plugins only */
99 /* return the name of a random track */
101 /* plugin interfaces **********************************************************/
103 long disorder_tracklength(const char *track, const char *path);
104 /* compute the length of the track. @track@ is the UTF-8 name of the
105 * track, @path@ is the file system name (or 0 for tracks that don't
106 * exist in the filesystem). The return value should be a positive
107 * number of seconds, 0 for unknown or -1 if an error occurred. */
109 void disorder_scan(const char *root);
110 /* write a list of path names below @root@ to standard output. */
112 int disorder_check(const char *root, const char *path);
113 /* Recheck a track, given its root and path name. Return 1 if it
114 * exists, 0 if it does not exist and -1 if an error occurred. */
116 void disorder_notify_play(const char *track,
117 const char *submitter);
118 /* we're going to play @track@. It was submitted by @submitter@
119 * (might be a null pointer) */
121 void disorder_notify_scratch(const char *track,
122 const char *submitter,
123 const char *scratcher,
125 /* @scratcher@ scratched @track@ after @seconds@. It was submitted by
126 * @submitter@ (might be a null pointer) */
128 void disorder_notify_not_scratched(const char *track,
129 const char *submitter);
130 /* @track@ (submitted by @submitter@, which might be a null pointer)
131 * was not scratched. */
133 void disorder_notify_queue(const char *track,
134 const char *submitter);
135 /* @track@ added to the queue by @submitter@ (never a null pointer) */
137 void disorder_notify_queue_remove(const char *track,
138 const char *remover);
139 /* @track@ removed from the queue by @remover@ (never a null pointer) */
141 void disorder_notify_queue_move(const char *track,
143 /* @track@ moved in the queue by @mover@ (never a null pointer) */
145 void disorder_notify_pause(const char *track,
147 /* TRACK was paused by PAUSER (might be a null pointer) */
149 void disorder_notify_resume(const char *track,
150 const char *resumer);
151 /* TRACK was resumed by PAUSER (might be a null pointer) */
153 /* player plugin interface ****************************************************/
155 extern const unsigned long disorder_player_type;
157 #define DISORDER_PLAYER_STANDALONE 0x00000000
158 /* this player plays sound directly */
160 #define DISORDER_PLAYER_RAW 0x00000001
161 /* player that sends raw samples to $DISORDER_RAW_FD */
163 #define DISORDER_PLAYER_TYPEMASK 0x000000ff
164 /* mask for player types */
166 #define DISORDER_PLAYER_PREFORK 0x00000100
167 /* call prefork function */
169 #define DISORDER_PLAYER_PAUSES 0x00000200
170 /* supports pausing */
172 void *disorder_play_prefork(const char *track);
173 /* Called outside the fork. Should not block. Returns a null pointer
176 * If _play_prefork is called then its return value is used as the
177 * DATA argument to the following functions. Otherwise the value of
178 * DATA argument is indeterminate and must not be used. */
180 void disorder_play_track(const char *const *parameters,
185 /* Called to play a track. Should either exec or only return when the
186 * track has finished. Should not call exit() (except after a
187 * succesful exec). Allowed to call _Exit(). */
189 int disorder_play_pause(long *playedp, void *data);
190 /* Pauses the playing track. If the track can be paused returns 0 and
191 * stores the number of seconds so far played via PLAYEDP, or sets it
192 * to -1 if this is not known. If the track cannot be paused then
193 * returns -1. Should not block.
196 void disorder_play_resume(void *data);
197 /* Restarts play after a pause. PLAYED is the value returned from the
198 * original pause operation. Should not block. */
200 void disorder_play_cleanup(void *data);
201 /* called to clean up DATA. Should not block. */
207 #endif /* DISORDER_H */