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