chiark / gitweb /
eclient no_response calls all now have errors reported to the per-call
[disorder] / lib / eclient.h
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder.
1020001c 3 * Copyright (C) 2006, 2007 Richard Kettlewell
460b9539 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 {
1f3ce240 45 /** @brief Called when a communication error occurs.
0e4472a0 46 * @param u from disorder_eclient_new()
47 * @param msg error message
1f3ce240
RK
48 *
49 * This might be called at any time, and indicates a low-level error,
50 * e.g. connection refused by the server. It does not mean that any requests
51 * made of the owning eclient will not be fulfilled at some point.
0e4472a0 52 */
460b9539 53 void (*comms_error)(void *u, const char *msg);
460b9539 54
0e4472a0 55 /** @brief Called when a command fails (including initial authorization).
56 * @param u from disorder_eclient_new()
57 * @param v from failed command, or NULL if during setup
58 * @param msg error message
1f3ce240
RK
59 *
60 * This call is obsolete at least in its current form, in which it is used to
61 * report most errors from most requests. Ultimately requests-specific
62 * errors will be reported in a request-specific way rather than via this
63 * generic callback.
0e4472a0 64 */
460b9539 65 void (*protocol_error)(void *u, void *v, int code, const char *msg);
0e4472a0 66
67 /** @brief Set poll/select flags
68 * @param u from disorder_eclient_new()
69 * @param c handle
70 * @param fd file descriptor
71 * @param mode bitmap (@ref DISORDER_POLL_READ and/or @ref DISORDER_POLL_WRITE)
72 *
73 * Before @p fd is closed you will always get a call with @p mode = 0.
74 */
460b9539 75 void (*poll)(void *u, disorder_eclient *c, int fd, unsigned mode);
460b9539 76
0e4472a0 77 /** @brief Report current activity
78 * @param u from disorder_eclient_new()
79 * @param msg Current activity or NULL
80 *
81 * Called with @p msg = NULL when there's nothing going on.
82 */
460b9539 83 void (*report)(void *u, const char *msg);
460b9539 84} disorder_eclient_callbacks;
85
0e4472a0 86/** @brief Callbacks for log clients
87 *
88 * All of these are allowed to be a null pointers in which case you don't get
89 * told about that log event.
90 *
91 * See disorder_protocol(5) for full documentation.
92 */
460b9539 93typedef struct disorder_eclient_log_callbacks {
0e4472a0 94 /** @brief Called on (re-)connection */
460b9539 95 void (*connected)(void *v);
460b9539 96
97 void (*completed)(void *v, const char *track);
98 void (*failed)(void *v, const char *track, const char *status);
99 void (*moved)(void *v, const char *user);
100 void (*playing)(void *v, const char *track, const char *user/*maybe 0*/);
101 void (*queue)(void *v, struct queue_entry *q);
102 void (*recent_added)(void *v, struct queue_entry *q);
103 void (*recent_removed)(void *v, const char *id);
104 void (*removed)(void *v, const char *id, const char *user/*maybe 0*/);
105 void (*scratched)(void *v, const char *track, const char *user);
106 void (*state)(void *v, unsigned long state);
107 void (*volume)(void *v, int left, int right);
e025abff 108 void (*rescanned)(void *v);
460b9539 109} disorder_eclient_log_callbacks;
110
111/* State bits */
0e4472a0 112
113/** @brief Play is enabled */
114#define DISORDER_PLAYING_ENABLED 0x00000001
115
116/** @brief Random play is enabled */
117#define DISORDER_RANDOM_ENABLED 0x00000002
118
8f763f1b
RK
119/** @brief Track is paused
120 *
121 * This is only meaningful if @ref DISORDER_PLAYING is set
122 */
0e4472a0 123#define DISORDER_TRACK_PAUSED 0x00000004
460b9539 124
8f763f1b
RK
125/** @brief Track is playing
126 *
127 * This can be set even if the current track is paused (in which case @ref
128 * DISORDER_TRACK_PAUSED) will also be set.
129 */
130#define DISORDER_PLAYING 0x00000008
131
132/** @brief Connected to server
133 *
134 * By connected it is meant that commands have a reasonable chance of being
135 * processed soon, not merely that a TCP connection exists - for instance if
136 * the client is still authenticating then that does not count as connected.
137 */
138#define DISORDER_CONNECTED 0x00000010
139
00959300
RK
140char *disorder_eclient_interpret_state(unsigned long statebits);
141
460b9539 142struct queue_entry;
143struct kvp;
144struct sink;
145
146/* Completion callbacks. These provide the result of operations to the caller.
147 * It is always allowed for these to be null pointers if you don't care about
148 * the result. */
149
53fa91bb
RK
150/** @brief Trivial completion callback
151 * @param v User data
152 * @param error Error string or NULL on succes
153 */
154typedef void disorder_eclient_no_response(void *v,
155 const char *error);
460b9539 156
1bd1b63c
RK
157/** @brief String result completion callback
158 * @param v User data
06bfbba4
RK
159 * @param error Error string or NULL on succes
160 * @param value or NULL if not found
1bd1b63c 161 *
06bfbba4
RK
162 * @p error will be NULL on success. In this case @p value will be the result
163 * (which might be NULL for disorder_eclient_get(),
164 * disorder_eclient_get_global() and disorder_eclient_userinfo()).
165 *
166 * @p error will be non-NULL on failure. In this case @p value is always NULL.
1bd1b63c 167 */
06bfbba4
RK
168typedef void disorder_eclient_string_response(void *v,
169 const char *error,
170 const char *value);
460b9539 171
172typedef void disorder_eclient_integer_response(void *v, long value);
173/* completion callback with a integer result */
174
175typedef void disorder_eclient_volume_response(void *v, int l, int r);
176/* completion callback with a pair of integer results */
177
178typedef void disorder_eclient_queue_response(void *v, struct queue_entry *q);
179/* completion callback for queue/recent listing */
180
181typedef void disorder_eclient_list_response(void *v, int nvec, char **vec);
182/* completion callback for file listing etc */
183
184disorder_eclient *disorder_eclient_new(const disorder_eclient_callbacks *cb,
185 void *u);
186/* Create a new client */
187
188void disorder_eclient_close(disorder_eclient *c);
189/* Close C */
190
8f763f1b 191unsigned long disorder_eclient_state(const disorder_eclient *c);
ad58ebcc 192
460b9539 193void disorder_eclient_polled(disorder_eclient *c, unsigned mode);
194/* Should be called when c's FD is readable and/or writable, and in any case
195 * from time to time (so that retries work). */
196
197int disorder_eclient_version(disorder_eclient *c,
198 disorder_eclient_string_response *completed,
199 void *v);
200/* fetch the server version */
201
202int disorder_eclient_play(disorder_eclient *c,
203 const char *track,
204 disorder_eclient_no_response *completed,
205 void *v);
206/* add a track to the queue */
207
208int disorder_eclient_pause(disorder_eclient *c,
209 disorder_eclient_no_response *completed,
210 void *v);
211/* add a track to the queue */
212
213int disorder_eclient_resume(disorder_eclient *c,
214 disorder_eclient_no_response *completed,
215 void *v);
216/* add a track to the queue */
217
218int disorder_eclient_scratch(disorder_eclient *c,
219 const char *id,
220 disorder_eclient_no_response *completed,
221 void *v);
222/* scratch a track by ID */
223
224int disorder_eclient_scratch_playing(disorder_eclient *c,
225 disorder_eclient_no_response *completed,
226 void *v);
227/* scratch the playing track whatever it is */
228
229int disorder_eclient_remove(disorder_eclient *c,
230 const char *id,
231 disorder_eclient_no_response *completed,
232 void *v);
233/* remove a track from the queue */
234
235int disorder_eclient_moveafter(disorder_eclient *c,
236 const char *target,
237 int nids,
238 const char **ids,
239 disorder_eclient_no_response *completed,
240 void *v);
241/* move tracks within the queue */
242
243int disorder_eclient_playing(disorder_eclient *c,
244 disorder_eclient_queue_response *completed,
245 void *v);
246/* find the currently playing track (0 for none) */
247
248int disorder_eclient_queue(disorder_eclient *c,
249 disorder_eclient_queue_response *completed,
250 void *v);
251/* list recently played tracks */
252
253int disorder_eclient_recent(disorder_eclient *c,
254 disorder_eclient_queue_response *completed,
255 void *v);
256/* list recently played tracks */
257
258int disorder_eclient_files(disorder_eclient *c,
259 disorder_eclient_list_response *completed,
260 const char *dir,
261 const char *re,
262 void *v);
263/* list files in a directory, matching RE if not a null pointer */
264
265int disorder_eclient_dirs(disorder_eclient *c,
266 disorder_eclient_list_response *completed,
267 const char *dir,
268 const char *re,
269 void *v);
270/* list directories in a directory, matching RE if not a null pointer */
271
272int disorder_eclient_namepart(disorder_eclient *c,
273 disorder_eclient_string_response *completed,
274 const char *track,
275 const char *context,
276 const char *part,
277 void *v);
278/* look up a track name part */
279
280int disorder_eclient_length(disorder_eclient *c,
281 disorder_eclient_integer_response *completed,
282 const char *track,
283 void *v);
284/* look up a track name length */
285
286int disorder_eclient_volume(disorder_eclient *c,
287 disorder_eclient_volume_response *callback,
288 int l, int r,
289 void *v);
290/* If L and R are both -ve gets the volume.
291 * If neither are -ve then sets the volume.
292 * Otherwise asserts!
293 */
294
295int disorder_eclient_enable(disorder_eclient *c,
296 disorder_eclient_no_response *callback,
297 void *v);
298int disorder_eclient_disable(disorder_eclient *c,
299 disorder_eclient_no_response *callback,
300 void *v);
301int disorder_eclient_random_enable(disorder_eclient *c,
302 disorder_eclient_no_response *callback,
303 void *v);
304int disorder_eclient_random_disable(disorder_eclient *c,
305 disorder_eclient_no_response *callback,
306 void *v);
307/* Enable/disable play/random play */
308
309int disorder_eclient_resolve(disorder_eclient *c,
310 disorder_eclient_string_response *completed,
311 const char *track,
312 void *v);
313/* Resolve aliases */
314
315int disorder_eclient_log(disorder_eclient *c,
316 const disorder_eclient_log_callbacks *callbacks,
317 void *v);
318/* Make this a log client (forever - it automatically becomes one again upon
319 * reconnection) */
320
321int disorder_eclient_get(disorder_eclient *c,
322 disorder_eclient_string_response *completed,
323 const char *track, const char *pref,
324 void *v);
325int disorder_eclient_set(disorder_eclient *c,
326 disorder_eclient_no_response *completed,
327 const char *track, const char *pref,
328 const char *value,
329 void *v);
330int disorder_eclient_unset(disorder_eclient *c,
331 disorder_eclient_no_response *completed,
332 const char *track, const char *pref,
333 void *v);
334/* Get/set preference values */
335
336int disorder_eclient_search(disorder_eclient *c,
337 disorder_eclient_list_response *completed,
338 const char *terms,
339 void *v);
340
7858930d 341int disorder_eclient_nop(disorder_eclient *c,
342 disorder_eclient_no_response *completed,
343 void *v);
344
2a10b70b
RK
345int disorder_eclient_new_tracks(disorder_eclient *c,
346 disorder_eclient_list_response *completed,
347 int max,
348 void *v);
a99c4e9a
RK
349
350int disorder_eclient_rtp_address(disorder_eclient *c,
351 disorder_eclient_list_response *completed,
352 void *v);
353
ffc4dbaf
RK
354int disorder_eclient_users(disorder_eclient *c,
355 disorder_eclient_list_response *completed,
356 void *v);
4aa8a0a4
RK
357int disorder_eclient_deluser(disorder_eclient *c,
358 disorder_eclient_no_response *completed,
359 const char *user,
360 void *v);
e61aef23
RK
361int disorder_eclient_userinfo(disorder_eclient *c,
362 disorder_eclient_string_response *completed,
363 const char *user,
364 const char *property,
365 void *v);
366int disorder_eclient_edituser(disorder_eclient *c,
367 disorder_eclient_no_response *completed,
368 const char *user,
369 const char *property,
370 const char *value,
371 void *v);
0d719587
RK
372int disorder_eclient_adduser(disorder_eclient *c,
373 disorder_eclient_no_response *completed,
374 const char *user,
375 const char *password,
376 const char *rights,
377 void *v);
ffc4dbaf 378
460b9539 379#endif
380
381/*
382Local Variables:
383c-basic-offset:2
384comment-column:40
385fill-column:79
386indent-tabs-mode:nil
387End:
388*/