chiark / gitweb /
7ca9b4fdc47f6e664c05d66bb132bbfb184b1f67
[disorder] / lib / queue.h
1 /*
2  * This file is part of DisOrder.
3  * Copyright (C) 2004-2008 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 3 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,
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.
14  * 
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/>.
17  */
18 /** @file lib/queue.h
19  * @brief Track queues
20  *
21  * Used for the queue, the recently played list and the currently playing
22  * track, both in the server and in clients.
23  */
24 #ifndef QUEUE_H
25 #define QUEUE_H
26
27 #include <time.h>
28
29
30 enum playing_state {
31   playing_failed,                       /* failed to play */
32   playing_isscratch,                    /* this is a scratch track */
33   playing_no_player,                    /* couldn't find a player */
34   playing_ok,                           /* played OK */
35   playing_paused,                       /* started but paused */
36   playing_quitting,                     /* interrupt because server quit */
37   playing_random,                       /* unplayed randomly chosen track */
38   playing_scratched,                    /* was scratched */
39   playing_started,                      /* started to play */
40   playing_unplayed                      /* haven't played this track yet */
41 };
42
43 extern const char *const playing_states[];
44
45 /** @brief Possible track origins
46  *
47  * This is a newly introduced field.  The aim is ultimately to separate the
48  * concepts of the track origin and its current state.  NB that both are
49  * potentially mutable!
50  */
51 enum track_origin {
52   /** @brief Track was picked at random and then adopted by a user
53    *
54    * @c submitter identifies who adopted it.  This isn't implemented
55    * yet.
56    */
57   origin_adopted,
58
59   /** @brief Track was picked by a user
60    *
61    * @c submitter identifies who picked it
62    */
63   origin_picked,
64
65   /** @brief Track was picked at random
66    *
67    * @c submitter will be NULL
68    */
69   origin_random,
70
71   /** @brief Track was scheduled by a user
72    *
73    * @c submitter identifies who picked it
74    */
75   origin_scheduled,
76
77   /** @brief Track is a scratch
78    *
79    * @c submitter identifies who did the scratching
80    */
81   origin_scratch
82 };
83
84 extern const char *const track_origins[];
85
86 /* queue entries form a circular doubly-linked list */
87 struct queue_entry {
88   struct queue_entry *next;             /* next entry */
89   struct queue_entry *prev;             /* previous entry */
90   const char *track;                    /* path to track */
91   const char *submitter;                /* name of submitter */
92   time_t when;                          /* time submitted */
93   time_t played;                        /* when played */
94   enum playing_state state;             /* state */
95   enum track_origin origin;             /* where track came from */
96   long wstat;                           /* wait status */
97   const char *scratched;                /* scratched by */
98   const char *id;                       /* queue entry ID */
99   time_t expected;                      /* expected started time */
100   /* for playing or soon-to-be-played tracks only: */
101   unsigned long type;                   /* type word from plugin */
102   const struct plugin *pl;              /* plugin that's playing this track */
103   void *data;                           /* player data */
104   long sofar;                           /* how much played so far */
105   int prepared;                         /* true when connected to speaker */
106   /* For DISORDER_PLAYER_PAUSES only: */
107   time_t lastpaused, lastresumed;       /* when last paused/resumed, or 0 */
108   long uptopause;                       /* how much played up to last pause */
109   /* For Disobedience */
110   struct queuelike *ql;                 /* owning queue */
111 };
112
113 void queue_insert_entry(struct queue_entry *b, struct queue_entry *n);
114 void queue_delete_entry(struct queue_entry *node);
115
116 int queue_unmarshall(struct queue_entry *q, const char *s,
117                      void (*error_handler)(const char *, void *),
118                      void *u);
119 /* unmarshall UTF-8 string @s@ into @q@ */
120
121 int queue_unmarshall_vec(struct queue_entry *q, int nvec, char **vec,
122                      void (*error_handler)(const char *, void *),
123                      void *u);
124 /* unmarshall pre-split string @vec@ into @q@ */
125
126 char *queue_marshall(const struct queue_entry *q);
127 /* marshall @q@ into a UTF-8 string */
128
129 #endif /* QUEUE_H */
130
131 /*
132 Local Variables:
133 c-basic-offset:2
134 comment-column:40
135 fill-column:79
136 End:
137 */