2 * This file is part of DisOrder
3 * Copyright (C) 2008, 2009 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/>.
18 /** @file server/disorder-server.h
19 * @brief Definitions for server and allied utilities
22 #ifndef DISORDER_SERVER_H
23 #define DISORDER_SERVER_H
35 #include <netinet/in.h>
40 #include <sys/socket.h>
43 #include <sys/types.h>
45 #include <sys/resource.h>
55 #include "configuration.h"
64 #include "inputline.h"
76 #include "speaker-protocol.h"
80 #include "trackdb-int.h"
82 #include "trackname.h"
90 extern const struct uaudio
*api
;
92 void daemonize(const char *tag
, int fac
, const char *pidfile
);
93 /* Go into background. Send stdout/stderr to syslog.
94 * If @pri@ is non-null, it should be "facility.level"
95 * If @tag@ is non-null, it is used as a tag to each message
96 * If @pidfile@ is non-null, the PID is written to that file.
99 void quit(ev_source
*ev
) attribute((noreturn
));
100 /* terminate the daemon */
102 int reconfigure(ev_source
*ev
, int reload
);
103 /* reconfigure. If @reload@ is nonzero, update the configuration. */
105 extern struct queue_entry qhead
;
106 /* queue of things yet to be played. the head will be played
109 extern struct queue_entry phead
;
110 /* things that have been played in the past. the head is the oldest. */
114 void queue_read(void);
115 /* read the queue in. Calls @fatal@ on error. */
117 void queue_write(void);
118 /* write the queue out. Calls @fatal@ on error. */
120 void recent_read(void);
121 /* read the recently played list in. Calls @fatal@ on error. */
123 void recent_write(void);
124 /* write the recently played list out. Calls @fatal@ on error. */
126 struct queue_entry
*queue_add(const char *track
, const char *submitter
,
127 int where
, enum track_origin origin
);
128 #define WHERE_START 0 /* Add to head of queue */
129 #define WHERE_END 1 /* Add to end of queue */
130 #define WHERE_BEFORE_RANDOM 2 /* End, or before random track */
131 /* add an entry to the queue. Return a pointer to the new entry. */
133 void queue_remove(struct queue_entry
*q
, const char *who
);
134 /* remove an from the queue */
136 struct queue_entry
*queue_find(const char *key
);
137 /* find a track in the queue by name or ID */
139 void queue_played(struct queue_entry
*q
);
140 /* add @q@ to the played list */
142 int queue_move(struct queue_entry
*q
, int delta
, const char *who
);
143 /* move element @q@ in the queue towards the front (@delta@ > 0) or towards the
144 * back (@delta@ < 0). The return value is the leftover delta once we've hit
145 * the end in whichever direction we were going. */
147 void queue_moveafter(struct queue_entry
*target
,
148 int nqs
, struct queue_entry
**qs
, const char *who
);
149 /* Move all the elements QS to just after TARGET, or to the head if
152 void queue_fix_sofar(struct queue_entry
*q
);
153 /* Fix up the sofar field for standalone players */
155 void schedule_init(ev_source
*ev
);
156 const char *schedule_add(ev_source
*ev
,
157 struct kvp
*actiondata
);
158 int schedule_del(const char *id
);
159 struct kvp
*schedule_get(const char *id
);
160 char **schedule_list(int *neventsp
);
162 extern struct queue_entry
*playing
; /* playing track or 0 */
163 extern int paused
; /* non-0 if paused */
165 void play(ev_source
*ev
);
166 /* try to play something, if playing is enabled and nothing is playing
169 int playing_is_enabled(void);
170 /* return true iff playing is enabled */
172 void enable_playing(const char *who
, ev_source
*ev
);
175 void disable_playing(const char *who
);
176 /* disable playing. */
178 int random_is_enabled(void);
179 /* return true iff random play is enabled */
181 void enable_random(const char *who
, ev_source
*ev
);
182 /* enable random play */
184 void disable_random(const char *who
);
185 /* disable random play */
187 void scratch(const char *who
, const char *id
);
188 /* scratch the playing track. @who@ identifies the scratcher. @id@ is
189 * the ID or a null pointer. */
191 void quitting(ev_source
*ev
);
192 /* called to terminate current track and shut down speaker process
195 void speaker_setup(ev_source
*ev
);
196 /* set up the speaker subprocess */
198 void speaker_reload(void);
199 /* Tell the speaker process to reload its configuration. */
201 int pause_playing(const char *who
);
202 /* Pause the current track. Return 0 on success, -1 on error. WHO
205 void resume_playing(const char *who
);
206 /* Resume after a pause. WHO can be 0. */
208 int prepare(ev_source
*ev
,
209 struct queue_entry
*q
);
210 /* Prepare to play Q */
212 void abandon(ev_source
*ev
,
213 struct queue_entry
*q
);
214 /* Abandon a possibly-prepared track. */
216 void add_random_track(ev_source
*ev
);
217 /* If random play is enabled then try to add a track to the queue. */
219 int server_start(ev_source
*ev
, int pf
,
220 size_t socklen
, const struct sockaddr
*sa
,
222 /* start listening. Return the fd. */
224 int server_stop(ev_source
*ev
, int fd
);
225 /* Stop listening on @fd@ */
227 extern int volume_left
, volume_right
; /* last known volume */
229 extern int wideopen
; /* blindly accept all logins */
235 typedef void *plugin_handle
;
236 typedef void function_t(void);
238 const struct plugin
*open_plugin(const char *name
,
240 #define PLUGIN_FATAL 0x0001 /* fatal() on error */
241 /* Open a plugin. Returns a null pointer on error or a handle to it
244 function_t
*get_plugin_function(const struct plugin
*handle
,
246 const void *get_plugin_object(const struct plugin
*handle
,
248 /* Look up a function or an object in a plugin */
250 /* track length computation ***************************************************/
252 long tracklength(const char *plugin
, const char *track
, const char *path
);
254 /* collection interface *******************************************************/
256 void scan(const char *module
, const char *root
);
257 /* write a list of path names below @root@ to standard output. */
259 int check(const char *module
, const char *root
, const char *path
);
260 /* Recheck a track, given its root and path name. Return 1 if it
261 * exists, 0 if it does not exist and -1 if an error occurred. */
263 /* notification interface *****************************************************/
265 void notify_play(const char *track
,
266 const char *submitter
);
267 /* we're going to play @track@. It was submitted by @submitter@
268 * (might be a null pointer) */
270 void notify_scratch(const char *track
,
271 const char *submitter
,
272 const char *scratcher
,
274 /* @scratcher@ scratched @track@ after @seconds@. It was submitted by
275 * @submitter@ (might be a null pointer) */
277 void notify_not_scratched(const char *track
,
278 const char *submitter
);
279 /* @track@ (submitted by @submitter@, which might be a null pointer)
280 * was not scratched. */
282 void notify_queue(const char *track
,
283 const char *submitter
);
284 /* @track@ was queued by @submitter@ */
286 void notify_queue_remove(const char *track
,
287 const char *remover
);
288 /* @track@ removed from the queue by @remover@ (never a null pointer) */
290 void notify_queue_move(const char *track
,
292 /* @track@ moved in the queue by @mover@ (never a null pointer) */
294 void notify_pause(const char *track
,
296 /* TRACK was paused by PAUSER (might be a null pointer) */
298 void notify_resume(const char *track
,
299 const char *resumer
);
300 /* TRACK was resumed by PAUSER (might be a null pointer) */
302 /* track playing **************************************************************/
304 unsigned long play_get_type(const struct plugin
*pl
);
305 /* Get the type word for this plugin */
307 void *play_prefork(const struct plugin
*pl
,
309 /* Call the prefork function for PL and return the user data */
311 void play_track(const struct plugin
*pl
,
312 const char *const *parameters
,
316 /* play a track. Called inside a fork. */
318 void play_cleanup(const struct plugin
*pl
, void *data
);
319 /* Call the cleanup function for PL if necessary */
321 int play_pause(const struct plugin
*pl
, long *playedp
, void *data
);
324 void play_resume(const struct plugin
*pl
, void *data
);
327 #endif /* DISORDER_SERVER_H */