460b9539 |
1 | /* |
2 | * This file is part of DisOrder. |
3 | * Copyright (C) 2004, 2005, 2006 Richard Kettlewell |
4 | * |
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. |
9 | * |
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. |
14 | * |
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 |
18 | * USA |
19 | */ |
20 | |
21 | #ifndef QUEUE_H |
22 | #define QUEUE_H |
23 | |
24 | enum playing_state { |
25 | playing_failed, /* failed to play */ |
26 | playing_isscratch, /* this is a scratch track */ |
27 | playing_no_player, /* couldn't find a player */ |
28 | playing_ok, /* played OK */ |
29 | playing_paused, /* started but paused */ |
30 | playing_quitting, /* interrupt because server quit */ |
31 | playing_random, /* unplayed randomly chosen track */ |
32 | playing_scratched, /* was scratched */ |
33 | playing_started, /* started to play */ |
34 | playing_unplayed /* haven't played this track yet */ |
35 | }; |
36 | |
37 | extern const char *playing_states[]; |
38 | |
39 | /* queue entries form a circular doubly-linked list */ |
40 | struct queue_entry { |
41 | struct queue_entry *next; /* next entry */ |
42 | struct queue_entry *prev; /* previous entry */ |
43 | const char *track; /* path to track */ |
44 | const char *submitter; /* name of submitter */ |
45 | time_t when; /* time submitted */ |
46 | time_t played; /* when played */ |
47 | enum playing_state state; /* state */ |
48 | long wstat; /* wait status */ |
49 | const char *scratched; /* scratched by */ |
50 | const char *id; /* queue entry ID */ |
51 | time_t expected; /* expected started time */ |
52 | /* for playing or soon-to-be-played tracks only: */ |
53 | unsigned long type; /* type word from plugin */ |
54 | const struct plugin *pl; /* plugin that's playing this track */ |
55 | void *data; /* player data */ |
56 | long sofar; /* how much played so far */ |
57 | /* For DISORDER_PLAYER_PAUSES only: */ |
58 | time_t lastpaused, lastresumed; /* when last paused/resumed, or 0 */ |
59 | long uptopause; /* how much played up to last pause */ |
60 | /* For Disobedience */ |
61 | struct queuelike *ql; /* owning queue */ |
62 | }; |
63 | |
64 | extern struct queue_entry qhead; |
65 | /* queue of things yet to be played. the head will be played |
66 | * soonest. */ |
67 | |
68 | extern struct queue_entry phead; |
69 | /* things that have been played in the past. the head is the oldest. */ |
70 | |
71 | void queue_read(void); |
72 | /* read the queue in. Calls @fatal@ on error. */ |
73 | |
74 | void queue_write(void); |
75 | /* write the queue out. Calls @fatal@ on error. */ |
76 | |
77 | void recent_read(void); |
78 | /* read the recently played list in. Calls @fatal@ on error. */ |
79 | |
80 | void recent_write(void); |
81 | /* write the recently played list out. Calls @fatal@ on error. */ |
82 | |
83 | struct queue_entry *queue_add(const char *track, const char *submitter, |
84 | int where); |
85 | #define WHERE_START 0 /* Add to head of queue */ |
86 | #define WHERE_END 1 /* Add to end of queue */ |
87 | #define WHERE_BEFORE_RANDOM 2 /* End, or before random track */ |
88 | /* add an entry to the queue. Return a pointer to the new entry. */ |
89 | |
90 | void queue_remove(struct queue_entry *q, const char *who); |
91 | /* remove an from the queue */ |
92 | |
93 | struct queue_entry *queue_find(const char *key); |
94 | /* find a track in the queue by name or ID */ |
95 | |
96 | void queue_played(struct queue_entry *q); |
97 | /* add @q@ to the played list */ |
98 | |
99 | int queue_unmarshall(struct queue_entry *q, const char *s, |
100 | void (*error_handler)(const char *, void *), |
101 | void *u); |
102 | /* unmarshall UTF-8 string @s@ into @q@ */ |
103 | |
104 | int queue_unmarshall_vec(struct queue_entry *q, int nvec, char **vec, |
105 | void (*error_handler)(const char *, void *), |
106 | void *u); |
107 | /* unmarshall pre-split string @vec@ into @q@ */ |
108 | |
109 | char *queue_marshall(const struct queue_entry *q); |
110 | /* marshall @q@ into a UTF-8 string */ |
111 | |
112 | void queue_id(struct queue_entry *q); |
113 | /* give @q@ an ID */ |
114 | |
115 | int queue_move(struct queue_entry *q, int delta, const char *who); |
116 | /* move element @q@ in the queue towards the front (@delta@ > 0) or towards the |
117 | * back (@delta@ < 0). The return value is the leftover delta once we've hit |
118 | * the end in whichever direction we were going. */ |
119 | |
120 | void queue_moveafter(struct queue_entry *target, |
121 | int nqs, struct queue_entry **qs, const char *who); |
122 | /* Move all the elements QS to just after TARGET, or to the head if |
123 | * TARGET=0. */ |
124 | |
125 | void queue_fix_sofar(struct queue_entry *q); |
126 | /* Fix up the sofar field for standalone players */ |
127 | |
128 | #endif /* QUEUE_H */ |
129 | |
130 | /* |
131 | Local Variables: |
132 | c-basic-offset:2 |
133 | comment-column:40 |
134 | fill-column:79 |
135 | End: |
136 | */ |