chiark / gitweb /
Knock address specifications into order.
[disorder] / lib / speaker-protocol.h
CommitLineData
ea410ba1 1/*
2 * This file is part of DisOrder
3 * Copyright (C) 2005, 2007 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 */
fbf86993 20/** @file lib/speaker-protocol.h
ea410ba1 21 * @brief Speaker/server protocol support
22 *
23 * This file defines the protocol by which the main server and the speaker
24 * process communicate.
25 */
26
cf714d85 27#ifndef SPEAKER_PROTOCOL_H
28#define SPEAKER_PROTOCOL_H
ea410ba1 29
30/** @brief A message from the main server to the speaker, or vica versa */
31struct speaker_message {
32 /** @brief Message type
33 *
34 * Messges from the main server:
35 * - @ref SM_PREPARE
36 * - @ref SM_PLAY
37 * - @ref SM_PAUSE
38 * - @ref SM_RESUME
39 * - @ref SM_CANCEL
40 * - @ref SM_RELOAD
41 *
42 * Messages from the speaker:
43 * - @ref SM_PAUSED
44 * - @ref SM_FINISHED
45 * - @ref SM_PLAYING
46 */
47 int type;
48
49 /** @brief Message-specific data */
50 long data;
51
52 /** @brief Track ID (including 0 terminator) */
53 char id[24]; /* ID including terminator */
54};
55
56/* messages from the main DisOrder server */
57/** @brief Prepare track @c id
58 *
59 * This message will include a file descriptor. The speaker starts buffering
60 * audio data read from this file against the time that it must be played.
61 */
62#define SM_PREPARE 0
63
64/** @brief Play track @c id
65 *
66 * The track must already have been prepared.
67 */
68#define SM_PLAY 1
69
70/** @brief Pause current track */
71#define SM_PAUSE 2
72
73/** @brief Resume current track */
74#define SM_RESUME 3
75
76/** @brief Cancel track @c id */
77#define SM_CANCEL 4
78
79/** @brief Reload configuration */
80#define SM_RELOAD 5
81
82/* messages from the speaker */
83/** @brief Paused track @c id, @c data seconds in
84 *
85 * There is no @c SM_RESUMED, instead @ref SM_PLAYING is sent after the track
86 * starts playing again.
87 */
88#define SM_PAUSED 128
89
90/** @brief Finished playing track @c id */
91#define SM_FINISHED 129
92
93/** @brief Currently track @c id, @c data seconds in
94 *
95 * This is sent from time to time while a track is playing.
96 */
97#define SM_PLAYING 131
98
99void speaker_send(int fd, const struct speaker_message *sm, int datafd);
100/* Send a message. DATAFD is passed too if not -1. Does not close DATAFD. */
101
102int speaker_recv(int fd, struct speaker_message *sm, int *datafd);
103/* Receive a message. If DATAFD is not null then can receive an FD. Return 0
104 * on EOF, +ve if a message is read, -1 on EAGAIN, terminates on any other
105 * error. */
106
cf714d85 107#endif /* SPEAKER_PROTOCOL_H */
ea410ba1 108
109/*
110Local Variables:
111c-basic-offset:2
112comment-column:40
113fill-column:79
114indent-tabs-mode:nil
115End:
116*/