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/>.
29 # define DISORDER_IFGNUC(x) x
31 # define DISORDER_IFGNUC(x)
34 /* memory allocation **********************************************************/
36 void *disorder_malloc(size_t);
37 void *disorder_realloc(void *, size_t);
38 /* As malloc/realloc, but
39 * 1) succeed or call fatal
40 * 2) always clear (the unused part of) the new allocation
41 * 3) are garbage-collected
44 void *disorder_malloc_noptr(size_t);
45 void *disorder_realloc_noptr(void *, size_t);
46 char *disorder_strdup(const char *);
47 char *disorder_strndup(const char *, size_t);
48 /* As malloc/realloc/strdup, but
49 * 1) succeed or call fatal
50 * 2) are garbage-collected
51 * 3) allocated space must not contain any pointers
53 * {xmalloc,xrealloc}_noptr don't promise to clear the new space
56 int disorder_snprintf(char buffer[], size_t bufsize, const char *fmt, ...)
57 DISORDER_IFGNUC(__attribute__((format (printf, 3, 4))));
60 int disorder_asprintf(char **rp, const char *fmt, ...)
61 DISORDER_IFGNUC(__attribute__((format (printf, 2, 3))));
62 /* like asprintf but uses xmalloc_noptr() */
64 /* logging ********************************************************************/
66 void disorder_error(int errno_value, const char *fmt, ...)
67 DISORDER_IFGNUC(__attribute__((format (printf, 2, 3))));
68 /* report an error. If errno_value is nonzero then the errno string
71 void disorder_fatal(int errno_value, const char *fmt, ...)
72 DISORDER_IFGNUC(__attribute__((noreturn))
73 __attribute__((format (printf, 2, 3))));
74 /* report an error and terminate. If errno_value is nonzero then the
75 * errno string is included. This is the only safe way to terminate
78 void disorder_info(const char *fmt, ...);
81 /* track database *************************************************************/
83 int disorder_track_exists(const char *track);
84 /* return true if the track exists. */
86 const char *disorder_track_get_data(const char *track, const char *key);
87 /* get the value for @key@ (xstrdup'd) */
89 int disorder_track_set_data(const char *track,
90 const char *key, const char *value);
91 /* set the value of @key@ to @value@, or remove it if @value@ is a null
92 * pointer. Return 0 on success, -1 on error. */
94 const char *disorder_track_random(void); /* server plugins only */
95 /* return the name of a random track */
97 /* plugin interfaces **********************************************************/
99 long disorder_tracklength(const char *track, const char *path);
100 /* compute the length of the track. @track@ is the UTF-8 name of the
101 * track, @path@ is the file system name (or 0 for tracks that don't
102 * exist in the filesystem). The return value should be a positive
103 * number of seconds, 0 for unknown or -1 if an error occurred. */
105 void disorder_scan(const char *root);
106 /* write a list of path names below @root@ to standard output. */
108 int disorder_check(const char *root, const char *path);
109 /* Recheck a track, given its root and path name. Return 1 if it
110 * exists, 0 if it does not exist and -1 if an error occurred. */
112 void disorder_notify_play(const char *track,
113 const char *submitter);
114 /* we're going to play @track@. It was submitted by @submitter@
115 * (might be a null pointer) */
117 void disorder_notify_scratch(const char *track,
118 const char *submitter,
119 const char *scratcher,
121 /* @scratcher@ scratched @track@ after @seconds@. It was submitted by
122 * @submitter@ (might be a null pointer) */
124 void disorder_notify_not_scratched(const char *track,
125 const char *submitter);
126 /* @track@ (submitted by @submitter@, which might be a null pointer)
127 * was not scratched. */
129 void disorder_notify_queue(const char *track,
130 const char *submitter);
131 /* @track@ added to the queue by @submitter@ (never a null pointer) */
133 void disorder_notify_queue_remove(const char *track,
134 const char *remover);
135 /* @track@ removed from the queue by @remover@ (never a null pointer) */
137 void disorder_notify_queue_move(const char *track,
139 /* @track@ moved in the queue by @mover@ (never a null pointer) */
141 void disorder_notify_pause(const char *track,
143 /* TRACK was paused by PAUSER (might be a null pointer) */
145 void disorder_notify_resume(const char *track,
146 const char *resumer);
147 /* TRACK was resumed by PAUSER (might be a null pointer) */
149 /* player plugin interface ****************************************************/
151 extern const unsigned long disorder_player_type;
153 #define DISORDER_PLAYER_STANDALONE 0x00000000
154 /* this player plays sound directly */
156 #define DISORDER_PLAYER_RAW 0x00000001
157 /* player that sends raw samples to $DISORDER_RAW_FD */
159 #define DISORDER_PLAYER_TYPEMASK 0x000000ff
160 /* mask for player types */
162 #define DISORDER_PLAYER_PREFORK 0x00000100
163 /* call prefork function */
165 #define DISORDER_PLAYER_PAUSES 0x00000200
166 /* supports pausing */
168 void *disorder_play_prefork(const char *track);
169 /* Called outside the fork. Should not block. Returns a null pointer
172 * If _play_prefork is called then its return value is used as the
173 * DATA argument to the following functions. Otherwise the value of
174 * DATA argument is indeterminate and must not be used. */
176 void disorder_play_track(const char *const *parameters,
181 /* Called to play a track. Should either exec or only return when the
182 * track has finished. Should not call exit() (except after a
183 * succesful exec). Allowed to call _Exit(). */
185 int disorder_play_pause(long *playedp, void *data);
186 /* Pauses the playing track. If the track can be paused returns 0 and
187 * stores the number of seconds so far played via PLAYEDP, or sets it
188 * to -1 if this is not known. If the track cannot be paused then
189 * returns -1. Should not block.
192 void disorder_play_resume(void *data);
193 /* Restarts play after a pause. PLAYED is the value returned from the
194 * original pause operation. Should not block. */
196 void disorder_play_cleanup(void *data);
197 /* called to clean up DATA. Should not block. */
203 #endif /* DISORDER_H */