1 /* libmpd (high level libmpdclient library) 2 * Copyright (C) 2004-2009 Qball Cow <qball@sarine.nl> 3 * Project homepage: http://gmpcwiki.sarine.nl/ 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, 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 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 */ 19 20 #ifndef __MPD_INTERNAL_LIB_ 21 #define __MPD_INTERNAL_LIB_ 22 23 #include "libmpdclient.h" 24 struct _MpdData_real; 25 26 typedef struct _MpdData_real { 27 /* MpdDataType */ 28 MpdDataType type; 29 30 union { 31 struct { 32 int tag_type; 33 char *tag; 34 }; 35 char *directory; 36 mpd_PlaylistFile *playlist; 37 mpd_Song *song; 38 mpd_OutputEntity *output_dev; /* from devices */ 39 }; 40 void *userdata; 41 void (*freefunc)(void *userdata); 42 43 struct _MpdData_real *next; 44 /* Previous MpdData in the list */ 45 struct _MpdData_real *prev; 46 struct _MpdData_real *first; 47 }MpdData_real; 48 49 50 /* queue struct */ 51 typedef struct _MpdQueue MpdQueue; 52 typedef struct _MpdServerState { 53 /* information needed to detect changes on mpd's side */ 54 long long playlistid; 55 long long storedplaylistid; 56 int songid; 57 int songpos; 58 int nextsongpos; 59 int nextsongid; 60 int state; 61 unsigned long dbUpdateTime; 62 int updatingDb; 63 int random; 64 int repeat; 65 int volume; 66 int xfade; 67 int totaltime; 68 int elapsedtime; 69 int bitrate; 70 unsigned int samplerate; 71 int bits; 72 int channels; 73 unsigned long playlistLength; 74 char error[512]; 75 int single; 76 int consume; 77 } MpdServerState; 78 79 80 /* command struct */ 81 /* internal use only */ 82 typedef struct _MpdCommand { 83 char *command_name; 84 int enabled; 85 } MpdCommand; 86 87 88 89 typedef struct _MpdObj { 90 /* defines if we are connected */ 91 /* This should be made true if and only if the connection is up and running */ 92 short int connected; 93 /* information needed to connect to mpd */ 94 char *hostname; 95 int port; 96 char *password; 97 float connection_timeout; 98 99 /* mpd's structures */ 100 mpd_Connection *connection; 101 mpd_Status *status; 102 mpd_Stats *stats; 103 mpd_Song *CurrentSong; 104 105 /* used to store/detect serverside status changes */ 106 MpdServerState CurrentState; 107 MpdServerState OldState; 108 109 /* new style signals */ 110 /* error signal */ 111 ErrorCallback the_error_callback; 112 void *the_error_signal_userdata; 113 /* song status changed */ 114 StatusChangedCallback the_status_changed_callback; 115 void *the_status_changed_signal_userdata; 116 /* (dis)connect signal */ 117 ConnectionChangedCallback the_connection_changed_callback; 118 void *the_connection_changed_signal_userdata; 119 120 /* error message */ 121 int error; 122 int error_mpd_code; 123 char *error_msg; 124 125 /* internal values */ 126 /* this "locks" the connections. so we can't have to commands competing with eachother */ 127 short int connection_lock; 128 129 /* queue */ 130 MpdQueue *queue; 131 /* commands */ 132 /* TODO: this is a temporary implementation, I want something nice with commands that are and aren't allowed to use. 133 * so use commands and notcommands functions 134 *TODO: Make a callback when a commando isn't allowed, so the client application can actually offer the user to enter password 135 */ 136 MpdCommand * commands; 137 /** 138 * tag type for a search 139 */ 140 int search_type; 141 int search_field; 142 143 /** 144 * For tracking changed outputs. 145 * A hack for retarted mpd 146 */ 147 int num_outputs; 148 int *output_states; 149 /** 150 * Supported url handlers 151 */ 152 char **url_handlers; 153 /** 154 * For testing supported tags 155 */ 156 int supported_tags[MPD_TAG_NUM_OF_ITEM_TYPES]; 157 158 int has_idle; 159 }_MpdObj; 160 161 162 typedef enum MpdQueueType { 163 MPD_QUEUE_ADD, 164 MPD_QUEUE_LOAD, 165 MPD_QUEUE_DELETE_ID, 166 MPD_QUEUE_DELETE_POS, 167 MPD_QUEUE_COMMAND /* abuse!!! */ 168 } MpdQueueType; 169 170 typedef struct _MpdQueue { 171 struct _MpdQueue *next; 172 struct _MpdQueue *prev; 173 struct _MpdQueue *first; 174 175 /* what item to queue, (add/load/remove)*/ 176 int type; 177 /* for adding files/load playlist/adding streams */ 178 char *path; 179 /* for removing */ 180 int id; 181 }_MpdQueue; 182 183 /* Internal Queue struct functions */ 184 MpdQueue * mpd_new_queue_struct (); 185 void mpd_queue_get_next (MpdObj *mi); 186 187 /* Internal Data struct functions */ 188 MpdData * mpd_new_data_struct (void); 189 MpdData * mpd_new_data_struct_append (MpdData * data); 190 MpdData * mpd_data_concatenate (MpdData * const first, MpdData * const second); 191 MpdData * mpd_data_get_next_real (MpdData * const data, int kill_list); 192 /* more internal stuff*/ 193 194 /** 195 * @param mi a #MpdObj 196 * 197 * Checks if mpd_stats is available, and updates when needed. 198 * 199 * @returns a #MpdError 200 */ 201 int mpd_stats_check(MpdObj *mi); 202 203 int mpd_lock_conn(MpdObj *mi); 204 int mpd_unlock_conn(MpdObj *mi); 205 /*MpdData * mpd_playlist_sort_artist_list(MpdData *data);*/ 206 MpdData * mpd_misc_sort_tag_list(MpdData *data); 207 208 209 #ifndef HAVE_STRNDUP 210 char * strndup (const char *s, size_t n); 211 #endif 212 213 int mpd_server_get_allowed_commands(MpdObj *mi); 214 typedef enum _MpdSearchType { 215 MPD_SEARCH_TYPE_NONE, 216 MPD_SEARCH_TYPE_FIND, 217 MPD_SEARCH_TYPE_SEARCH, 218 MPD_SEARCH_TYPE_LIST, 219 MPD_SEARCH_TYPE_PLAYLIST_FIND, 220 MPD_SEARCH_TYPE_PLAYLIST_SEARCH, 221 MPD_SEARCH_TYPE_STATS 222 }MpdSearchType; 223 int mpd_server_update_outputs(MpdObj *mi); 224 #endif 225