Adding some support for using "idle" to get changed events.
[libmpd.git] / src / libmpd-internal.h
blob8962011019b7f2fcd5cd14ce61c8084a3535d392
1 #ifndef __MPD_INTERNAL_LIB_
2 #define __MPD_INTERNAL_LIB_
4 #include "libmpdclient.h"
5 struct _MpdData_real;
7 typedef struct _MpdData_real {
8 /* MpdDataType */
9 MpdDataType type;
11 union {
12 struct {
13 int tag_type;
14 char *tag;
16 char *directory;
17 char *playlist; /*is a path*/
18 mpd_Song *song;
19 mpd_OutputEntity *output_dev; /* from devices */
21 void *userdata;
22 void (*freefunc)(void *userdata);
24 struct _MpdData_real *next;
25 /* Previous MpdData in the list */
26 struct _MpdData_real *prev;
27 struct _MpdData_real *first;
28 }MpdData_real;
31 /* queue struct */
32 typedef struct _MpdQueue MpdQueue;
33 typedef struct _MpdServerState {
34 /* information needed to detect changes on mpd's side */
35 long long playlistid;
36 long long storedplaylistid;
37 int songid;
38 int songpos;
39 int state;
40 unsigned long dbUpdateTime;
41 int updatingDb;
42 int random;
43 int repeat;
44 int volume;
45 int xfade;
46 int totaltime;
47 int elapsedtime;
48 int bitrate;
49 unsigned int samplerate;
50 int bits;
51 int channels;
52 unsigned long playlistLength;
53 char error[512];
54 } MpdServerState;
57 /* command struct */
58 /* internal use only */
59 typedef struct _MpdCommand {
60 char *command_name;
61 int enabled;
62 } MpdCommand;
66 typedef struct _MpdObj {
67 /* defines if we are connected */
68 /* This should be made true if and only if the connection is up and running */
69 short int connected;
70 /* information needed to connect to mpd */
71 char *hostname;
72 int port;
73 char *password;
74 float connection_timeout;
76 /* mpd's structures */
77 mpd_Connection *connection;
78 mpd_Status *status;
79 mpd_Stats *stats;
80 mpd_Song *CurrentSong;
82 /* used to store/detect serverside status changes */
83 MpdServerState CurrentState;
84 MpdServerState OldState;
86 /* new style signals */
87 /* error signal */
88 ErrorCallback the_error_callback;
89 void *the_error_signal_userdata;
90 /* song status changed */
91 StatusChangedCallback the_status_changed_callback;
92 void *the_status_changed_signal_userdata;
93 /* (dis)connect signal */
94 ConnectionChangedCallback the_connection_changed_callback;
95 void *the_connection_changed_signal_userdata;
97 /* error message */
98 int error;
99 int error_mpd_code;
100 char *error_msg;
102 /* internal values */
103 /* this "locks" the connections. so we can't have to commands competing with eachother */
104 short int connection_lock;
106 /* queue */
107 MpdQueue *queue;
108 /* commands */
109 /* TODO: this is a temporary implementation, I want something nice with commands that are and aren't allowed to use.
110 * so use commands and notcommands functions
111 *TODO: Make a callback when a commando isn't allowed, so the client application can actually offer the user to enter password
113 MpdCommand * commands;
115 * tag type for a search
117 int search_type;
118 int search_field;
121 * For tracking changed outputs.
122 * A hack for retarted mpd
124 int num_outputs;
125 int *output_states;
127 int has_idle;
128 }_MpdObj;
131 typedef enum MpdQueueType {
132 MPD_QUEUE_ADD,
133 MPD_QUEUE_LOAD,
134 MPD_QUEUE_DELETE_ID,
135 MPD_QUEUE_DELETE_POS,
136 MPD_QUEUE_COMMAND /* abuse!!! */
137 } MpdQueueType;
139 typedef struct _MpdQueue {
140 struct _MpdQueue *next;
141 struct _MpdQueue *prev;
142 struct _MpdQueue *first;
144 /* what item to queue, (add/load/remove)*/
145 int type;
146 /* for adding files/load playlist/adding streams */
147 char *path;
148 /* for removing */
149 int id;
150 }_MpdQueue;
152 /* Internal Queue struct functions */
153 MpdQueue * mpd_new_queue_struct ();
154 void mpd_queue_get_next (MpdObj *mi);
156 /* Internal Data struct functions */
157 MpdData * mpd_new_data_struct (void);
158 MpdData * mpd_new_data_struct_append (MpdData * data);
159 MpdData * mpd_data_concatenate (MpdData * const first, MpdData * const second);
160 MpdData * mpd_data_get_next_real (MpdData * const data, int kill_list);
161 /* more internal stuff*/
164 * @param mi a #MpdObj
166 * Checks if mpd_stats is availible, and updates when needed.
168 * @returns a #MpdError
170 int mpd_stats_check(MpdObj *mi);
172 int mpd_lock_conn(MpdObj *mi);
173 int mpd_unlock_conn(MpdObj *mi);
174 /*MpdData * mpd_playlist_sort_artist_list(MpdData *data);*/
175 MpdData * mpd_misc_sort_tag_list(MpdData *data);
178 #ifndef HAVE_STRNDUP
179 char * strndup (const char *s, size_t n);
180 #endif
182 int mpd_server_get_allowed_commands(MpdObj *mi);
183 typedef enum _MpdSearchType {
184 MPD_SEARCH_TYPE_NONE,
185 MPD_SEARCH_TYPE_FIND,
186 MPD_SEARCH_TYPE_SEARCH,
187 MPD_SEARCH_TYPE_LIST,
188 MPD_SEARCH_TYPE_PLAYLIST_FIND,
189 MPD_SEARCH_TYPE_PLAYLIST_SEARCH,
190 MPD_SEARCH_TYPE_STATS
191 }MpdSearchType;
192 int mpd_server_update_outputs(MpdObj *mi);
193 #endif