chiark / gitweb /
Remove extraneous logging.
[disorder] / lib / eclient.h
CommitLineData
460b9539 1/*
2 * This file is part of DisOrder.
5c102112 3 * Copyright (C) 2006-2008 Richard Kettlewell
460b9539 4 *
e7eb3a27 5 * This program is free software: you can redistribute it and/or modify
460b9539 6 * it under the terms of the GNU General Public License as published by
e7eb3a27 7 * the Free Software Foundation, either version 3 of the License, or
460b9539 8 * (at your option) any later version.
e7eb3a27
RK
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 *
460b9539 15 * You should have received a copy of the GNU General Public License
e7eb3a27 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
460b9539 17 */
0e4472a0 18/** @file lib/eclient.h
19 * @brief Client code for event-driven programs
20 */
460b9539 21
22#ifndef ECLIENT_H
23#define ECLIENT_H
24
ad492e00
RK
25#include "rights.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);
58d2aad2
RK
96
97 /** @brief Called when @p track finished playing successfully */
460b9539 98 void (*completed)(void *v, const char *track);
58d2aad2
RK
99
100 /** @brief Called when @p track fails for some reason */
460b9539 101 void (*failed)(void *v, const char *track, const char *status);
58d2aad2
RK
102
103 /** @brief Called when @p user moves some track or tracks in the queue
104 *
105 * Fetch the queue again to find out what the new order is - the
106 * rearrangement could in principle be arbitrarily complicated.
107 */
460b9539 108 void (*moved)(void *v, const char *user);
58d2aad2
RK
109
110 /** @brief Called when @p track starts playing
111 *
112 * @p user might be 0.
113 */
460b9539 114 void (*playing)(void *v, const char *track, const char *user/*maybe 0*/);
58d2aad2
RK
115
116 /** @brief Called when @p q is added to the queue
117 *
118 * Fetch the queue again to find out where the in the queue it was added.
119 */
460b9539 120 void (*queue)(void *v, struct queue_entry *q);
58d2aad2
RK
121
122 /** @brief Called when @p q is added to the recent list */
460b9539 123 void (*recent_added)(void *v, struct queue_entry *q);
58d2aad2
RK
124
125 /** @brief Called when @p id is removed from the recent list */
460b9539 126 void (*recent_removed)(void *v, const char *id);
58d2aad2 127
59cf25c4 128 /** @brief Called when @p id is removed from the queue
58d2aad2
RK
129 *
130 * @p user might be 0.
131 */
460b9539 132 void (*removed)(void *v, const char *id, const char *user/*maybe 0*/);
58d2aad2
RK
133
134 /** @brief Called when @p track is scratched */
460b9539 135 void (*scratched)(void *v, const char *track, const char *user);
58d2aad2
RK
136
137 /** @brief Called with the current state whenever it changes
138 *
139 * State bits are:
140 * - @ref DISORDER_PLAYING_ENABLED
141 * - @ref DISORDER_RANDOM_ENABLED
142 * - @ref DISORDER_TRACK_PAUSED
143 * - @ref DISORDER_PLAYING
144 * - @ref DISORDER_CONNECTED
145 */
460b9539 146 void (*state)(void *v, unsigned long state);
58d2aad2
RK
147
148 /** @brief Called when the volume changes */
460b9539 149 void (*volume)(void *v, int left, int right);
58d2aad2
RK
150
151 /** @brief Called when a rescan completes */
e025abff 152 void (*rescanned)(void *v);
58d2aad2
RK
153
154 /** @brief Called when a user is created (admins only) */
155 void (*user_add)(void *v, const char *user);
156
157 /** @brief Called when a user is confirmed (admins only) */
158 void (*user_confirm)(void *v, const char *user);
159
160 /** @brief Called when a user is deleted (admins only) */
161 void (*user_delete)(void *v, const char *user);
162
163 /** @brief Called when a user is edited (admins only) */
164 void (*user_edit)(void *v, const char *user, const char *property);
ad492e00
RK
165
166 /** @brief Called when your rights change */
167 void (*rights_changed)(void *v, rights_type new_rights);
9433fabf
RK
168
169 /** @brief Called when a track is adopted */
170 void (*adopted)(void *v, const char *id, const char *who);
812b526d 171
5c102112
RK
172 /** @brief Called when a new playlist is created */
173 void (*playlist_created)(void *v, const char *playlist, const char *sharing);
174
175 /** @brief Called when a playlist is modified */
176 void (*playlist_modified)(void *v, const char *playlist, const char *sharing);
177
178 /** @brief Called when a new playlist is deleted */
179 void (*playlist_deleted)(void *v, const char *playlist);
460b9539 180} disorder_eclient_log_callbacks;
181
182/* State bits */
0e4472a0 183
184/** @brief Play is enabled */
185#define DISORDER_PLAYING_ENABLED 0x00000001
186
187/** @brief Random play is enabled */
188#define DISORDER_RANDOM_ENABLED 0x00000002
189
8f763f1b
RK
190/** @brief Track is paused
191 *
192 * This is only meaningful if @ref DISORDER_PLAYING is set
193 */
0e4472a0 194#define DISORDER_TRACK_PAUSED 0x00000004
460b9539 195
8f763f1b
RK
196/** @brief Track is playing
197 *
198 * This can be set even if the current track is paused (in which case @ref
199 * DISORDER_TRACK_PAUSED) will also be set.
200 */
201#define DISORDER_PLAYING 0x00000008
202
203/** @brief Connected to server
204 *
205 * By connected it is meant that commands have a reasonable chance of being
206 * processed soon, not merely that a TCP connection exists - for instance if
207 * the client is still authenticating then that does not count as connected.
208 */
209#define DISORDER_CONNECTED 0x00000010
210
00959300
RK
211char *disorder_eclient_interpret_state(unsigned long statebits);
212
460b9539 213struct queue_entry;
214struct kvp;
215struct sink;
216
217/* Completion callbacks. These provide the result of operations to the caller.
699517af 218 * Unlike in earlier releases, these are not allowed to be NULL. */
460b9539 219
53fa91bb
RK
220/** @brief Trivial completion callback
221 * @param v User data
e2717131 222 * @param err Error string or NULL on succes
53fa91bb
RK
223 */
224typedef void disorder_eclient_no_response(void *v,
e2717131 225 const char *err);
460b9539 226
1bd1b63c
RK
227/** @brief String result completion callback
228 * @param v User data
e2717131 229 * @param err Error string or NULL on succes
658c8a35 230 * @param value Result or NULL
1bd1b63c 231 *
06bfbba4
RK
232 * @p error will be NULL on success. In this case @p value will be the result
233 * (which might be NULL for disorder_eclient_get(),
53740beb
RK
234 * disorder_eclient_get_global(), disorder_eclient_userinfo() and
235 * disorder_eclient_playlist_get_share()).
06bfbba4
RK
236 *
237 * @p error will be non-NULL on failure. In this case @p value is always NULL.
1bd1b63c 238 */
06bfbba4 239typedef void disorder_eclient_string_response(void *v,
e2717131 240 const char *err,
06bfbba4 241 const char *value);
460b9539 242
658c8a35
RK
243/** @brief String result completion callback
244 * @param v User data
e2717131 245 * @param err Error string or NULL on succes
658c8a35
RK
246 * @param value Result or 0
247 *
248 * @p error will be NULL on success. In this case @p value will be the result.
249 *
250 * @p error will be non-NULL on failure. In this case @p value is always 0.
251 */
252typedef void disorder_eclient_integer_response(void *v,
e2717131 253 const char *err,
658c8a35 254 long value);
699517af
RK
255/** @brief Volume completion callback
256 * @param v User data
e2717131 257 * @param err Error string or NULL on success
699517af
RK
258 * @param l Left channel volume
259 * @param r Right channel volume
260 *
261 * @p error will be NULL on success. In this case @p l and @p r will be the
262 * result.
263 *
264 * @p error will be non-NULL on failure. In this case @p l and @p r are always
265 * 0.
266 */
267typedef void disorder_eclient_volume_response(void *v,
e2717131 268 const char *err,
699517af 269 int l, int r);
460b9539 270
3035257f
RK
271/** @brief Queue request completion callback
272 * @param v User data
e2717131 273 * @param err Error string or NULL on success
3035257f
RK
274 * @param q Head of queue data list
275 *
4190a4d9
RK
276 * @p error will be NULL on success. In this case @p q will be the (head of
277 * the) result.
3035257f
RK
278 *
279 * @p error will be non-NULL on failure. In this case @p q may be NULL but
280 * MIGHT also be some subset of the queue. For consistent behavior it should
281 * be ignored in the error case.
282 */
283typedef void disorder_eclient_queue_response(void *v,
e2717131 284 const char *err,
3035257f 285 struct queue_entry *q);
460b9539 286
4190a4d9
RK
287/** @brief List request completion callback
288 * @param v User data
e2717131 289 * @param err Error string or NULL on success
4190a4d9
RK
290 * @param nvec Number of elements in response list
291 * @param vec Pointer to response list
292 *
293 * @p error will be NULL on success. In this case @p nvec and @p vec will give
53740beb
RK
294 * the result, or be -1 and NULL respectively e.g. from
295 * disorder_eclient_playlist_get() if there is no such playlist.
4190a4d9
RK
296 *
297 * @p error will be non-NULL on failure. In this case @p nvec and @p vec will
298 * be 0 and NULL.
299 */
300typedef void disorder_eclient_list_response(void *v,
e2717131 301 const char *err,
4190a4d9 302 int nvec, char **vec);
460b9539 303
304disorder_eclient *disorder_eclient_new(const disorder_eclient_callbacks *cb,
305 void *u);
306/* Create a new client */
307
308void disorder_eclient_close(disorder_eclient *c);
309/* Close C */
310
8f763f1b 311unsigned long disorder_eclient_state(const disorder_eclient *c);
ad58ebcc 312
460b9539 313void disorder_eclient_polled(disorder_eclient *c, unsigned mode);
314/* Should be called when c's FD is readable and/or writable, and in any case
315 * from time to time (so that retries work). */
316
317int disorder_eclient_version(disorder_eclient *c,
318 disorder_eclient_string_response *completed,
319 void *v);
320/* fetch the server version */
321
322int disorder_eclient_play(disorder_eclient *c,
323 const char *track,
324 disorder_eclient_no_response *completed,
325 void *v);
326/* add a track to the queue */
327
328int disorder_eclient_pause(disorder_eclient *c,
329 disorder_eclient_no_response *completed,
330 void *v);
331/* add a track to the queue */
332
333int disorder_eclient_resume(disorder_eclient *c,
334 disorder_eclient_no_response *completed,
335 void *v);
336/* add a track to the queue */
337
338int disorder_eclient_scratch(disorder_eclient *c,
339 const char *id,
340 disorder_eclient_no_response *completed,
341 void *v);
342/* scratch a track by ID */
343
344int disorder_eclient_scratch_playing(disorder_eclient *c,
345 disorder_eclient_no_response *completed,
346 void *v);
347/* scratch the playing track whatever it is */
348
349int disorder_eclient_remove(disorder_eclient *c,
350 const char *id,
351 disorder_eclient_no_response *completed,
352 void *v);
353/* remove a track from the queue */
354
355int disorder_eclient_moveafter(disorder_eclient *c,
356 const char *target,
357 int nids,
358 const char **ids,
359 disorder_eclient_no_response *completed,
360 void *v);
361/* move tracks within the queue */
362
363int disorder_eclient_playing(disorder_eclient *c,
364 disorder_eclient_queue_response *completed,
365 void *v);
366/* find the currently playing track (0 for none) */
367
368int disorder_eclient_queue(disorder_eclient *c,
369 disorder_eclient_queue_response *completed,
370 void *v);
371/* list recently played tracks */
372
373int disorder_eclient_recent(disorder_eclient *c,
374 disorder_eclient_queue_response *completed,
375 void *v);
376/* list recently played tracks */
377
378int disorder_eclient_files(disorder_eclient *c,
379 disorder_eclient_list_response *completed,
380 const char *dir,
381 const char *re,
382 void *v);
383/* list files in a directory, matching RE if not a null pointer */
384
385int disorder_eclient_dirs(disorder_eclient *c,
386 disorder_eclient_list_response *completed,
387 const char *dir,
388 const char *re,
389 void *v);
390/* list directories in a directory, matching RE if not a null pointer */
391
392int disorder_eclient_namepart(disorder_eclient *c,
393 disorder_eclient_string_response *completed,
394 const char *track,
395 const char *context,
396 const char *part,
397 void *v);
398/* look up a track name part */
399
400int disorder_eclient_length(disorder_eclient *c,
401 disorder_eclient_integer_response *completed,
402 const char *track,
403 void *v);
404/* look up a track name length */
405
406int disorder_eclient_volume(disorder_eclient *c,
407 disorder_eclient_volume_response *callback,
408 int l, int r,
409 void *v);
410/* If L and R are both -ve gets the volume.
411 * If neither are -ve then sets the volume.
412 * Otherwise asserts!
413 */
414
415int disorder_eclient_enable(disorder_eclient *c,
416 disorder_eclient_no_response *callback,
417 void *v);
418int disorder_eclient_disable(disorder_eclient *c,
419 disorder_eclient_no_response *callback,
420 void *v);
421int disorder_eclient_random_enable(disorder_eclient *c,
422 disorder_eclient_no_response *callback,
423 void *v);
424int disorder_eclient_random_disable(disorder_eclient *c,
425 disorder_eclient_no_response *callback,
426 void *v);
427/* Enable/disable play/random play */
428
429int disorder_eclient_resolve(disorder_eclient *c,
430 disorder_eclient_string_response *completed,
431 const char *track,
432 void *v);
433/* Resolve aliases */
434
435int disorder_eclient_log(disorder_eclient *c,
436 const disorder_eclient_log_callbacks *callbacks,
437 void *v);
438/* Make this a log client (forever - it automatically becomes one again upon
439 * reconnection) */
440
441int disorder_eclient_get(disorder_eclient *c,
442 disorder_eclient_string_response *completed,
443 const char *track, const char *pref,
444 void *v);
445int disorder_eclient_set(disorder_eclient *c,
446 disorder_eclient_no_response *completed,
447 const char *track, const char *pref,
448 const char *value,
449 void *v);
450int disorder_eclient_unset(disorder_eclient *c,
451 disorder_eclient_no_response *completed,
452 const char *track, const char *pref,
453 void *v);
454/* Get/set preference values */
455
456int disorder_eclient_search(disorder_eclient *c,
457 disorder_eclient_list_response *completed,
458 const char *terms,
459 void *v);
460
7858930d 461int disorder_eclient_nop(disorder_eclient *c,
462 disorder_eclient_no_response *completed,
463 void *v);
464
2a10b70b
RK
465int disorder_eclient_new_tracks(disorder_eclient *c,
466 disorder_eclient_list_response *completed,
467 int max,
468 void *v);
a99c4e9a
RK
469
470int disorder_eclient_rtp_address(disorder_eclient *c,
471 disorder_eclient_list_response *completed,
472 void *v);
473
ffc4dbaf
RK
474int disorder_eclient_users(disorder_eclient *c,
475 disorder_eclient_list_response *completed,
476 void *v);
4aa8a0a4
RK
477int disorder_eclient_deluser(disorder_eclient *c,
478 disorder_eclient_no_response *completed,
479 const char *user,
480 void *v);
e61aef23
RK
481int disorder_eclient_userinfo(disorder_eclient *c,
482 disorder_eclient_string_response *completed,
483 const char *user,
484 const char *property,
485 void *v);
486int disorder_eclient_edituser(disorder_eclient *c,
487 disorder_eclient_no_response *completed,
488 const char *user,
489 const char *property,
490 const char *value,
491 void *v);
0d719587
RK
492int disorder_eclient_adduser(disorder_eclient *c,
493 disorder_eclient_no_response *completed,
494 const char *user,
495 const char *password,
496 const char *rights,
497 void *v);
68210888
RK
498void disorder_eclient_enable_connect(disorder_eclient *c);
499void disorder_eclient_disable_connect(disorder_eclient *c);
d42e98ca
RK
500int disorder_eclient_adopt(disorder_eclient *c,
501 disorder_eclient_no_response *completed,
502 const char *id,
503 void *v);
53740beb
RK
504int disorder_eclient_playlists(disorder_eclient *c,
505 disorder_eclient_list_response *completed,
506 void *v);
507int disorder_eclient_playlist_delete(disorder_eclient *c,
508 disorder_eclient_no_response *completed,
509 const char *playlist,
510 void *v);
511int disorder_eclient_playlist_lock(disorder_eclient *c,
512 disorder_eclient_no_response *completed,
513 const char *playlist,
514 void *v);
515int disorder_eclient_playlist_unlock(disorder_eclient *c,
516 disorder_eclient_no_response *completed,
517 void *v);
518int disorder_eclient_playlist_set_share(disorder_eclient *c,
519 disorder_eclient_no_response *completed,
520 const char *playlist,
521 const char *sharing,
522 void *v);
523int disorder_eclient_playlist_get_share(disorder_eclient *c,
524 disorder_eclient_string_response *completed,
525 const char *playlist,
526 void *v);
527int disorder_eclient_playlist_set(disorder_eclient *c,
528 disorder_eclient_no_response *completed,
529 const char *playlist,
530 char **tracks,
531 int ntracks,
532 void *v);
533int disorder_eclient_playlist_get(disorder_eclient *c,
534 disorder_eclient_list_response *completed,
535 const char *playlist,
536 void *v);
537
460b9539 538#endif
539
540/*
541Local Variables:
542c-basic-offset:2
543comment-column:40
544fill-column:79
545indent-tabs-mode:nil
546End:
547*/