chiark / gitweb /
send "playing" at start of log; document log state updates
[disorder] / lib / eclient.h
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder.
3 * Copyright (C) 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 */
0e4472a0 20/** @file lib/eclient.h
21 * @brief Client code for event-driven programs
22 */
460b9539 23
24#ifndef ECLIENT_H
25#define ECLIENT_H
26
5626f6d2 27/* Asynchronous client interface */
460b9539 28
0e4472a0 29/** @brief Handle type */
460b9539 30typedef struct disorder_eclient disorder_eclient;
31
32struct queue_entry;
33
0e4472a0 34/** @brief Set to read from the FD */
35#define DISORDER_POLL_READ 1u
36
37/** @brief Set to write to the FD */
38#define DISORDER_POLL_WRITE 2u
460b9539 39
0e4472a0 40/** @brief Callbacks for all clients
41 *
42 * These must all be valid.
43 */
460b9539 44typedef struct disorder_eclient_callbacks {
0e4472a0 45 /** @brief Called when a communication error (e.g. connected refused) occurs.
46 * @param u from disorder_eclient_new()
47 * @param msg error message
48 */
460b9539 49 void (*comms_error)(void *u, const char *msg);
460b9539 50
0e4472a0 51 /** @brief Called when a command fails (including initial authorization).
52 * @param u from disorder_eclient_new()
53 * @param v from failed command, or NULL if during setup
54 * @param msg error message
55 */
460b9539 56 void (*protocol_error)(void *u, void *v, int code, const char *msg);
0e4472a0 57
58 /** @brief Set poll/select flags
59 * @param u from disorder_eclient_new()
60 * @param c handle
61 * @param fd file descriptor
62 * @param mode bitmap (@ref DISORDER_POLL_READ and/or @ref DISORDER_POLL_WRITE)
63 *
64 * Before @p fd is closed you will always get a call with @p mode = 0.
65 */
460b9539 66 void (*poll)(void *u, disorder_eclient *c, int fd, unsigned mode);
460b9539 67
0e4472a0 68 /** @brief Report current activity
69 * @param u from disorder_eclient_new()
70 * @param msg Current activity or NULL
71 *
72 * Called with @p msg = NULL when there's nothing going on.
73 */
460b9539 74 void (*report)(void *u, const char *msg);
460b9539 75} disorder_eclient_callbacks;
76
0e4472a0 77/** @brief Callbacks for log clients
78 *
79 * All of these are allowed to be a null pointers in which case you don't get
80 * told about that log event.
81 *
82 * See disorder_protocol(5) for full documentation.
83 */
460b9539 84typedef struct disorder_eclient_log_callbacks {
0e4472a0 85 /** @brief Called on (re-)connection */
460b9539 86 void (*connected)(void *v);
460b9539 87
88 void (*completed)(void *v, const char *track);
89 void (*failed)(void *v, const char *track, const char *status);
90 void (*moved)(void *v, const char *user);
91 void (*playing)(void *v, const char *track, const char *user/*maybe 0*/);
92 void (*queue)(void *v, struct queue_entry *q);
93 void (*recent_added)(void *v, struct queue_entry *q);
94 void (*recent_removed)(void *v, const char *id);
95 void (*removed)(void *v, const char *id, const char *user/*maybe 0*/);
96 void (*scratched)(void *v, const char *track, const char *user);
97 void (*state)(void *v, unsigned long state);
98 void (*volume)(void *v, int left, int right);
99} disorder_eclient_log_callbacks;
100
101/* State bits */
0e4472a0 102
103/** @brief Play is enabled */
104#define DISORDER_PLAYING_ENABLED 0x00000001
105
106/** @brief Random play is enabled */
107#define DISORDER_RANDOM_ENABLED 0x00000002
108
8f763f1b
RK
109/** @brief Track is paused
110 *
111 * This is only meaningful if @ref DISORDER_PLAYING is set
112 */
0e4472a0 113#define DISORDER_TRACK_PAUSED 0x00000004
460b9539 114
8f763f1b
RK
115/** @brief Track is playing
116 *
117 * This can be set even if the current track is paused (in which case @ref
118 * DISORDER_TRACK_PAUSED) will also be set.
119 */
120#define DISORDER_PLAYING 0x00000008
121
122/** @brief Connected to server
123 *
124 * By connected it is meant that commands have a reasonable chance of being
125 * processed soon, not merely that a TCP connection exists - for instance if
126 * the client is still authenticating then that does not count as connected.
127 */
128#define DISORDER_CONNECTED 0x00000010
129
460b9539 130struct queue_entry;
131struct kvp;
132struct sink;
133
134/* Completion callbacks. These provide the result of operations to the caller.
135 * It is always allowed for these to be null pointers if you don't care about
136 * the result. */
137
138typedef void disorder_eclient_no_response(void *v);
139/* completion callback with no data */
140
141typedef void disorder_eclient_string_response(void *v, const char *value);
142/* completion callback with a string result */
143
144typedef void disorder_eclient_integer_response(void *v, long value);
145/* completion callback with a integer result */
146
147typedef void disorder_eclient_volume_response(void *v, int l, int r);
148/* completion callback with a pair of integer results */
149
150typedef void disorder_eclient_queue_response(void *v, struct queue_entry *q);
151/* completion callback for queue/recent listing */
152
153typedef void disorder_eclient_list_response(void *v, int nvec, char **vec);
154/* completion callback for file listing etc */
155
156disorder_eclient *disorder_eclient_new(const disorder_eclient_callbacks *cb,
157 void *u);
158/* Create a new client */
159
160void disorder_eclient_close(disorder_eclient *c);
161/* Close C */
162
8f763f1b 163unsigned long disorder_eclient_state(const disorder_eclient *c);
ad58ebcc 164
460b9539 165void disorder_eclient_polled(disorder_eclient *c, unsigned mode);
166/* Should be called when c's FD is readable and/or writable, and in any case
167 * from time to time (so that retries work). */
168
169int disorder_eclient_version(disorder_eclient *c,
170 disorder_eclient_string_response *completed,
171 void *v);
172/* fetch the server version */
173
174int disorder_eclient_play(disorder_eclient *c,
175 const char *track,
176 disorder_eclient_no_response *completed,
177 void *v);
178/* add a track to the queue */
179
180int disorder_eclient_pause(disorder_eclient *c,
181 disorder_eclient_no_response *completed,
182 void *v);
183/* add a track to the queue */
184
185int disorder_eclient_resume(disorder_eclient *c,
186 disorder_eclient_no_response *completed,
187 void *v);
188/* add a track to the queue */
189
190int disorder_eclient_scratch(disorder_eclient *c,
191 const char *id,
192 disorder_eclient_no_response *completed,
193 void *v);
194/* scratch a track by ID */
195
196int disorder_eclient_scratch_playing(disorder_eclient *c,
197 disorder_eclient_no_response *completed,
198 void *v);
199/* scratch the playing track whatever it is */
200
201int disorder_eclient_remove(disorder_eclient *c,
202 const char *id,
203 disorder_eclient_no_response *completed,
204 void *v);
205/* remove a track from the queue */
206
207int disorder_eclient_moveafter(disorder_eclient *c,
208 const char *target,
209 int nids,
210 const char **ids,
211 disorder_eclient_no_response *completed,
212 void *v);
213/* move tracks within the queue */
214
215int disorder_eclient_playing(disorder_eclient *c,
216 disorder_eclient_queue_response *completed,
217 void *v);
218/* find the currently playing track (0 for none) */
219
220int disorder_eclient_queue(disorder_eclient *c,
221 disorder_eclient_queue_response *completed,
222 void *v);
223/* list recently played tracks */
224
225int disorder_eclient_recent(disorder_eclient *c,
226 disorder_eclient_queue_response *completed,
227 void *v);
228/* list recently played tracks */
229
230int disorder_eclient_files(disorder_eclient *c,
231 disorder_eclient_list_response *completed,
232 const char *dir,
233 const char *re,
234 void *v);
235/* list files in a directory, matching RE if not a null pointer */
236
237int disorder_eclient_dirs(disorder_eclient *c,
238 disorder_eclient_list_response *completed,
239 const char *dir,
240 const char *re,
241 void *v);
242/* list directories in a directory, matching RE if not a null pointer */
243
244int disorder_eclient_namepart(disorder_eclient *c,
245 disorder_eclient_string_response *completed,
246 const char *track,
247 const char *context,
248 const char *part,
249 void *v);
250/* look up a track name part */
251
252int disorder_eclient_length(disorder_eclient *c,
253 disorder_eclient_integer_response *completed,
254 const char *track,
255 void *v);
256/* look up a track name length */
257
258int disorder_eclient_volume(disorder_eclient *c,
259 disorder_eclient_volume_response *callback,
260 int l, int r,
261 void *v);
262/* If L and R are both -ve gets the volume.
263 * If neither are -ve then sets the volume.
264 * Otherwise asserts!
265 */
266
267int disorder_eclient_enable(disorder_eclient *c,
268 disorder_eclient_no_response *callback,
269 void *v);
270int disorder_eclient_disable(disorder_eclient *c,
271 disorder_eclient_no_response *callback,
272 void *v);
273int disorder_eclient_random_enable(disorder_eclient *c,
274 disorder_eclient_no_response *callback,
275 void *v);
276int disorder_eclient_random_disable(disorder_eclient *c,
277 disorder_eclient_no_response *callback,
278 void *v);
279/* Enable/disable play/random play */
280
281int disorder_eclient_resolve(disorder_eclient *c,
282 disorder_eclient_string_response *completed,
283 const char *track,
284 void *v);
285/* Resolve aliases */
286
287int disorder_eclient_log(disorder_eclient *c,
288 const disorder_eclient_log_callbacks *callbacks,
289 void *v);
290/* Make this a log client (forever - it automatically becomes one again upon
291 * reconnection) */
292
293int disorder_eclient_get(disorder_eclient *c,
294 disorder_eclient_string_response *completed,
295 const char *track, const char *pref,
296 void *v);
297int disorder_eclient_set(disorder_eclient *c,
298 disorder_eclient_no_response *completed,
299 const char *track, const char *pref,
300 const char *value,
301 void *v);
302int disorder_eclient_unset(disorder_eclient *c,
303 disorder_eclient_no_response *completed,
304 const char *track, const char *pref,
305 void *v);
306/* Get/set preference values */
307
308int disorder_eclient_search(disorder_eclient *c,
309 disorder_eclient_list_response *completed,
310 const char *terms,
311 void *v);
312
7858930d 313int disorder_eclient_nop(disorder_eclient *c,
314 disorder_eclient_no_response *completed,
315 void *v);
316
460b9539 317#endif
318
319/*
320Local Variables:
321c-basic-offset:2
322comment-column:40
323fill-column:79
324indent-tabs-mode:nil
325End:
326*/