1 #ifndef PROTOCOL_H 2 #define PROTOCOL_H 3 4 #include "playlist.h" 5 6 #ifdef __cplusplus 7 extern "C" { 8 #endif 9 10 struct event 11 { 12 int type; /* type of the event (one of EV_*) */ 13 void *data; /* optional data associated with the event */ 14 struct event *next; 15 }; 16 17 struct event_queue 18 { 19 struct event *head; 20 struct event *tail; 21 }; 22 23 /* Used as data field in the event queue for EV_FILE_TAGS. */ 24 struct tag_ev_response 25 { 26 char *file; 27 struct file_tags *tags; 28 }; 29 30 /* Used as data field in the event queue for EV_PLIST_MOVE. */ 31 struct move_ev_data 32 { 33 /* Two files that are to be exchanged. */ 34 char *from; 35 char *to; 36 }; 37 38 /* Status of nonblock sending/receiving function. */ 39 enum noblock_io_status 40 { 41 NB_IO_OK, 42 NB_IO_BLOCK, 43 NB_IO_ERR 44 }; 45 46 /* Definition of events sent by server to the client. */ 47 #define EV_STATE 0x01 /* server has changed the state */ 48 #define EV_CTIME 0x02 /* current time of the song has changed */ 49 #define EV_SRV_ERROR 0x04 /* an error occurred */ 50 #define EV_BUSY 0x05 /* another client is connected to the server */ 51 #define EV_DATA 0x06 /* data in response to a request will arrive */ 52 #define EV_BITRATE 0x07 /* the bitrate has changed */ 53 #define EV_RATE 0x08 /* the rate has changed */ 54 #define EV_CHANNELS 0x09 /* the number of channels has changed */ 55 #define EV_EXIT 0x0a /* the server is about to exit */ 56 #define EV_PONG 0x0b /* response for CMD_PING */ 57 #define EV_OPTIONS 0x0c /* the options has changed */ 58 #define EV_SEND_PLIST 0x0d /* request for sending the playlist */ 59 #define EV_TAGS 0x0e /* tags for the current file have changed */ 60 #define EV_STATUS_MSG 0x0f /* followed by a status message */ 61 #define EV_MIXER_CHANGE 0x10 /* the mixer channel was changed */ 62 #define EV_FILE_TAGS 0x11 /* tags in a response for tags request */ 63 #define EV_AVG_BITRATE 0x12 /* average bitrate has changed (new song) */ 64 #define EV_AUDIO_START 0x13 /* playing of audio has started */ 65 #define EV_AUDIO_STOP 0x14 /* playing of audio has stopped */ 66 67 /* Events caused by a client that wants to modify the playlist (see 68 * CMD_CLI_PLIST* commands). */ 69 #define EV_PLIST_ADD 0x50 /* add an item, followed by the file name */ 70 #define EV_PLIST_DEL 0x51 /* delete an item, followed by the file name */ 71 #define EV_PLIST_MOVE 0x52 /* move an item, followed by 2 file names */ 72 #define EV_PLIST_CLEAR 0x53 /* clear the playlist */ 73 74 /* These events, though similar to the four previous are caused by server 75 * which takes care of clients' queue synchronization. */ 76 #define EV_QUEUE_ADD 0x54 77 #define EV_QUEUE_DEL 0x55 78 #define EV_QUEUE_MOVE 0x56 79 #define EV_QUEUE_CLEAR 0x57 80 81 /* State of the server. */ 82 #define STATE_PLAY 0x01 83 #define STATE_STOP 0x02 84 #define STATE_PAUSE 0x03 85 86 /* Definition of server commands. */ 87 #define CMD_PLAY 0x00 /* play the first element on the list */ 88 #define CMD_LIST_CLEAR 0x01 /* clear the list */ 89 #define CMD_LIST_ADD 0x02 /* add an item to the list */ 90 #define CMD_STOP 0x04 /* stop playing */ 91 #define CMD_PAUSE 0x05 /* pause */ 92 #define CMD_UNPAUSE 0x06 /* unpause */ 93 #define CMD_SET_OPTION 0x07 /* set an option */ 94 #define CMD_GET_OPTION 0x08 /* get an option */ 95 #define CMD_GET_CTIME 0x0d /* get the current song time */ 96 #define CMD_GET_SNAME 0x0f /* get the stream file name */ 97 #define CMD_NEXT 0x10 /* start playing next song if available */ 98 #define CMD_QUIT 0x11 /* shutdown the server */ 99 #define CMD_SEEK 0x12 /* seek in the current stream */ 100 #define CMD_GET_STATE 0x13 /* get the state */ 101 #define CMD_DISCONNECT 0x15 /* disconnect from the server */ 102 #define CMD_GET_BITRATE 0x16 /* get the bitrate */ 103 #define CMD_GET_RATE 0x17 /* get the rate */ 104 #define CMD_GET_CHANNELS 0x18 /* get the number of channels */ 105 #define CMD_PING 0x19 /* request for EV_PONG */ 106 #define CMD_GET_MIXER 0x1a /* get the volume level */ 107 #define CMD_SET_MIXER 0x1b /* set the volume level */ 108 #define CMD_DELETE 0x1c /* delete an item from the playlist */ 109 #define CMD_SEND_PLIST_EVENTS 0x1d /* request for playlist events */ 110 #define CMD_PREV 0x20 /* start playing previous song if available */ 111 #define CMD_SEND_PLIST 0x21 /* send the playlist to the requesting client */ 112 #define CMD_GET_PLIST 0x22 /* get the playlist from one of the clients */ 113 #define CMD_CAN_SEND_PLIST 0x23 /* mark the client as able to send 114 playlist */ 115 #define CMD_CLI_PLIST_ADD 0x24 /* add an item to the client's playlist */ 116 #define CMD_CLI_PLIST_DEL 0x25 /* delete an item from the client's 117 playlist */ 118 #define CMD_CLI_PLIST_CLEAR 0x26 /* clear the client's playlist */ 119 #define CMD_GET_SERIAL 0x27 /* get an unique serial number */ 120 #define CMD_PLIST_SET_SERIAL 0x28 /* assign a serial number to the server's 121 playlist */ 122 #define CMD_LOCK 0x29 /* acquire a lock */ 123 #define CMD_UNLOCK 0x2a /* release the lock */ 124 #define CMD_PLIST_GET_SERIAL 0x2b /* get the serial number of the server's 125 playlist */ 126 #define CMD_GET_TAGS 0x2c /* get tags for the currently played file */ 127 #define CMD_TOGGLE_MIXER_CHANNEL 0x2d /* toggle the mixer channel */ 128 #define CMD_GET_MIXER_CHANNEL_NAME 0x2e /* get the mixer channel's name */ 129 #define CMD_GET_FILE_TAGS 0x2f /* get tags for the specified file */ 130 #define CMD_ABORT_TAGS_REQUESTS 0x30 /* abort previous CMD_GET_FILE_TAGS 131 requests up to some file */ 132 #define CMD_CLI_PLIST_MOVE 0x31 /* move an item */ 133 #define CMD_LIST_MOVE 0x32 /* move an item */ 134 #define CMD_GET_AVG_BITRATE 0x33 /* get the average bitrate */ 135 136 #define CMD_TOGGLE_SOFTMIXER 0x34 /* toggle use of softmixer */ 137 #define CMD_TOGGLE_EQUALIZER 0x35 /* toggle use of equalizer */ 138 #define CMD_EQUALIZER_REFRESH 0x36 /* refresh EQ-presets */ 139 #define CMD_EQUALIZER_PREV 0x37 /* select previous eq-preset */ 140 #define CMD_EQUALIZER_NEXT 0x38 /* select next eq-preset */ 141 142 #define CMD_TOGGLE_MAKE_MONO 0x39 /* toggle mono mixing */ 143 #define CMD_JUMP_TO 0x3a /* jumps to a some position in the current stream */ 144 #define CMD_QUEUE_ADD 0x3b /* add an item to the queue */ 145 #define CMD_QUEUE_DEL 0x3c /* delete an item from the queue */ 146 #define CMD_QUEUE_MOVE 0x3d /* move an item in the queue */ 147 #define CMD_QUEUE_CLEAR 0x3e /* clear the queue */ 148 #define CMD_GET_QUEUE 0x3f /* request the queue from the server */ 149 150 char *socket_name (); 151 int get_int (int sock, int *i); 152 enum noblock_io_status get_int_noblock (int sock, int *i); 153 int send_int (int sock, int i); 154 char *get_str (int sock); 155 int send_str (int sock, const char *str); 156 int get_time (int sock, time_t *i); 157 int send_time (int sock, time_t i); 158 int send_item (int sock, const struct plist_item *item); 159 struct plist_item *recv_item (int sock); 160 struct file_tags *recv_tags (int sock); 161 int send_tags (int sock, const struct file_tags *tags); 162 163 void event_queue_init (struct event_queue *q); 164 void event_queue_free (struct event_queue *q); 165 void free_event_data (const int type, void *data); 166 struct event *event_get_first (struct event_queue *q); 167 void event_pop (struct event_queue *q); 168 void event_push (struct event_queue *q, const int event, void *data); 169 int event_queue_empty (const struct event_queue *q); 170 enum noblock_io_status event_send_noblock (int sock, struct event_queue *q); 171 void free_tag_ev_data (struct tag_ev_response *d); 172 void free_move_ev_data (struct move_ev_data *m); 173 struct move_ev_data *move_ev_data_dup (const struct move_ev_data *m); 174 struct move_ev_data *recv_move_ev_data (int sock); 175 176 #ifdef __cplusplus 177 } 178 #endif 179 180 #endif 181