2 * This file is part of DisOrder
3 * Copyright (C) 2008-2012 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
, unsigned flags
);
105 void reset_sockets(ev_source
*ev
);
107 /** @brief Set when starting server */
108 #define RECONFIGURE_FIRST 0x0001
110 /** @brief Set when reloading after SIGHUP etc */
111 #define RECONFIGURE_RELOADING 0x0002
113 void dbparams_check(void);
115 extern struct queue_entry qhead
;
116 /* queue of things yet to be played. the head will be played
119 extern struct queue_entry phead
;
120 /* things that have been played in the past. the head is the oldest. */
124 void queue_read(void);
125 /* read the queue in. Calls @fatal@ on error. */
127 void queue_write(void);
128 /* write the queue out. Calls @fatal@ on error. */
130 void recent_read(void);
131 /* read the recently played list in. Calls @fatal@ on error. */
133 void recent_write(void);
134 /* write the recently played list out. Calls @fatal@ on error. */
136 struct queue_entry
*queue_add(const char *track
, const char *submitter
,
137 int where
, const char *target
,
138 enum track_origin origin
);
139 #define WHERE_START 0 /* Add to head of queue */
140 #define WHERE_END 1 /* Add to end of queue */
141 #define WHERE_BEFORE_RANDOM 2 /* End, or before random track */
142 #define WHERE_AFTER 3 /* After the target */
143 #define WHERE_NOWHERE 4 /* Don't add to queue at all */
144 /* add an entry to the queue. Return a pointer to the new entry. */
146 void queue_remove(struct queue_entry
*q
, const char *who
);
147 /* remove an from the queue */
149 struct queue_entry
*queue_find(const char *key
);
150 /* find a track in the queue by name or ID */
152 void queue_played(struct queue_entry
*q
);
153 /* add @q@ to the played list */
155 int queue_move(struct queue_entry
*q
, int delta
, const char *who
);
156 /* move element @q@ in the queue towards the front (@delta@ > 0) or towards the
157 * back (@delta@ < 0). The return value is the leftover delta once we've hit
158 * the end in whichever direction we were going. */
160 void queue_moveafter(struct queue_entry
*target
,
161 int nqs
, struct queue_entry
**qs
, const char *who
);
162 /* Move all the elements QS to just after TARGET, or to the head if
165 void queue_fix_sofar(struct queue_entry
*q
);
166 /* Fix up the sofar field for standalone players */
168 void schedule_init(ev_source
*ev
);
169 const char *schedule_add(ev_source
*ev
,
170 struct kvp
*actiondata
);
171 int schedule_del(const char *id
);
172 struct kvp
*schedule_get(const char *id
);
173 char **schedule_list(int *neventsp
);
175 extern struct queue_entry
*playing
; /* playing track or 0 */
176 extern int paused
; /* non-0 if paused */
178 void play(ev_source
*ev
);
179 /* try to play something, if playing is enabled and nothing is playing
182 /** @brief Return true if @p represents a true flag */
183 int flag_enabled(const char *s
);
185 int playing_is_enabled(void);
186 /* return true iff playing is enabled */
188 void enable_playing(const char *who
, ev_source
*ev
);
191 void disable_playing(const char *who
, ev_source
*ev
);
192 /* disable playing. */
194 int random_is_enabled(void);
195 /* return true iff random play is enabled */
197 void enable_random(const char *who
, ev_source
*ev
);
198 /* enable random play */
200 void disable_random(const char *who
, ev_source
*ev
);
201 /* disable random play */
203 void scratch(const char *who
, const char *id
);
204 /* scratch the playing track. @who@ identifies the scratcher. @id@ is
205 * the ID or a null pointer. */
207 void quitting(ev_source
*ev
);
208 /* called to terminate current track and shut down speaker process
211 void speaker_setup(ev_source
*ev
);
212 /* set up the speaker subprocess */
214 void speaker_reload(void);
215 /* Tell the speaker process to reload its configuration. */
217 int pause_playing(const char *who
);
218 /* Pause the current track. Return 0 on success, -1 on error. WHO
221 void resume_playing(const char *who
);
222 /* Resume after a pause. WHO can be 0. */
224 int prepare(ev_source
*ev
,
225 struct queue_entry
*q
);
226 /* Prepare to play Q */
228 void abandon(ev_source
*ev
,
229 struct queue_entry
*q
);
230 /* Abandon a possibly-prepared track. */
232 void add_random_track(ev_source
*ev
);
233 /* If random play is enabled then try to add a track to the queue. */
235 int server_start(ev_source
*ev
, int pf
,
236 size_t socklen
, const struct sockaddr
*sa
,
239 /* start listening. Return the fd. */
241 int server_stop(ev_source
*ev
, int fd
);
242 /* Stop listening on @fd@ */
244 void rtp_request(const struct sockaddr_storage
*sa
);
245 void rtp_request_cancel(const struct sockaddr_storage
*sa
);
247 extern int volume_left
, volume_right
; /* last known volume */
249 extern int wideopen
; /* blindly accept all logins */
255 typedef void *plugin_handle
;
256 typedef void function_t(void);
258 const struct plugin
*open_plugin(const char *name
,
260 #define PLUGIN_FATAL 0x0001 /* fatal() on error */
261 /* Open a plugin. Returns a null pointer on error or a handle to it
264 function_t
*get_plugin_function(const struct plugin
*handle
,
266 const void *get_plugin_object(const struct plugin
*handle
,
268 /* Look up a function or an object in a plugin */
270 /* track length computation ***************************************************/
272 long tracklength(const char *plugin
, const char *track
, const char *path
);
274 /* collection interface *******************************************************/
276 void scan(const char *module
, const char *root
);
277 /* write a list of path names below @root@ to standard output. */
279 int check(const char *module
, const char *root
, const char *path
);
280 /* Recheck a track, given its root and path name. Return 1 if it
281 * exists, 0 if it does not exist and -1 if an error occurred. */
283 /* notification interface *****************************************************/
285 void notify_play(const char *track
,
286 const char *submitter
);
287 /* we're going to play @track@. It was submitted by @submitter@
288 * (might be a null pointer) */
290 void notify_scratch(const char *track
,
291 const char *submitter
,
292 const char *scratcher
,
294 /* @scratcher@ scratched @track@ after @seconds@. It was submitted by
295 * @submitter@ (might be a null pointer) */
297 void notify_not_scratched(const char *track
,
298 const char *submitter
);
299 /* @track@ (submitted by @submitter@, which might be a null pointer)
300 * was not scratched. */
302 void notify_queue(const char *track
,
303 const char *submitter
);
304 /* @track@ was queued by @submitter@ */
306 void notify_queue_remove(const char *track
,
307 const char *remover
);
308 /* @track@ removed from the queue by @remover@ (never a null pointer) */
310 void notify_queue_move(const char *track
,
312 /* @track@ moved in the queue by @mover@ (never a null pointer) */
314 void notify_pause(const char *track
,
316 /* TRACK was paused by PAUSER (might be a null pointer) */
318 void notify_resume(const char *track
,
319 const char *resumer
);
320 /* TRACK was resumed by PAUSER (might be a null pointer) */
322 /* track playing **************************************************************/
324 unsigned long play_get_type(const struct plugin
*pl
);
325 /* Get the type word for this plugin */
327 void *play_prefork(const struct plugin
*pl
,
329 /* Call the prefork function for PL and return the user data */
331 void play_track(const struct plugin
*pl
,
332 const char *const *parameters
,
336 /* play a track. Called inside a fork. */
338 void play_cleanup(const struct plugin
*pl
, void *data
);
339 /* Call the cleanup function for PL if necessary */
341 int play_pause(const struct plugin
*pl
, long *playedp
, void *data
);
344 void play_resume(const struct plugin
*pl
, void *data
);
347 /* background process support *************************************************/
349 /** @brief Child process parameters */
351 /** @brief Length of player command */
353 /** @brief Player command */
355 /** @brief Raw track name */
359 /** @brief Callback to play or prepare a track
360 * @param q Track to play or decode
361 * @param bgdata User data pointer
364 typedef int play_background_child_fn(struct queue_entry
*q
,
365 const struct pbgc_params
*params
,
368 int play_background(ev_source
*ev
,
369 const struct stringlist
*player
,
370 struct queue_entry
*q
,
371 play_background_child_fn
*child
,
374 /* Return values from start(), prepare() and play_background() */
376 #define START_OK 0 /**< @brief Succeeded. */
377 #define START_HARDFAIL 1 /**< @brief Track is broken. */
378 #define START_SOFTFAIL 2 /**< @brief Track OK, system (temporarily?) broken */
380 void periodic_mount_check(ev_source
*ev_
);
382 /** @brief How often to check for new (or old) filesystems */
383 # define MOUNT_CHECK_INTERVAL 5 /* seconds */
385 #endif /* DISORDER_SERVER_H */