ncmpc  0.29
mpdclient.h
Go to the documentation of this file.
1 #ifndef MPDCLIENT_H
2 #define MPDCLIENT_H
3 
4 #include "config.h"
5 #include "playlist.h"
6 #include "Compiler.h"
7 
8 #include <mpd/client.h>
9 
10 struct filelist;
11 
12 struct mpdclient {
13 #ifdef ENABLE_ASYNC_CONNECT
14 
17  struct mpd_settings *settings;
18 
19 #ifndef WIN32
20 
26  struct mpd_settings *settings2;
27 #endif
28 
29 #else
30  const char *host;
31  unsigned port;
32 #endif
33 
34  unsigned timeout_ms;
35 
36  const char *password;
37 
38  /* playlist */
40 
41 #ifdef ENABLE_ASYNC_CONNECT
42  struct aconnect *async_connect;
43 #endif
44 
45  struct mpd_connection *connection;
46 
51  struct mpd_glib_source *source;
52 
53  struct mpd_status *status;
54  const struct mpd_song *song;
55 
61 
66  unsigned connection_id;
67 
68  int volume;
69 
73  enum mpd_idle events;
74 
75 #if defined(ENABLE_ASYNC_CONNECT) && !defined(WIN32)
76  bool connecting2;
77 #endif
78 
83  bool idle;
84 
88  bool playing;
89 };
90 
91 enum {
96  MPD_IDLE_ALL = MPD_IDLE_DATABASE
97  | MPD_IDLE_STORED_PLAYLIST
98  | MPD_IDLE_QUEUE
99  | MPD_IDLE_PLAYER
100  | MPD_IDLE_MIXER
101  | MPD_IDLE_OUTPUT
102  | MPD_IDLE_OPTIONS
103  | MPD_IDLE_UPDATE
104  | MPD_IDLE_STICKER
105  | MPD_IDLE_SUBSCRIPTION
106  | MPD_IDLE_MESSAGE
107 };
108 
111 bool
113 
114 static inline bool
115 mpdclient_finish_command(struct mpdclient *c)
116 {
117  return mpd_response_finish(c->connection)
118  ? true : mpdclient_handle_error(c);
119 }
120 
121 struct mpdclient *
122 mpdclient_new(const gchar *host, unsigned port,
123  unsigned timeout_ms, const gchar *password);
124 
125 void mpdclient_free(struct mpdclient *c);
126 
134 char *
135 mpdclient_settings_name(const struct mpdclient *c);
136 
137 gcc_pure
138 static inline bool
139 mpdclient_is_connected(const struct mpdclient *c)
140 {
141  return c->connection != NULL;
142 }
143 
148 gcc_pure
149 static inline bool
150 mpdclient_is_dead(const struct mpdclient *c)
151 {
152  return c->connection == NULL
153 #ifdef ENABLE_ASYNC_CONNECT
154  && c->async_connect == NULL
155 #endif
156  ;
157 }
158 
159 gcc_pure
160 static inline bool
161 mpdclient_is_playing(const struct mpdclient *c)
162 {
163  return c->status != NULL &&
164  (mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
165  mpd_status_get_state(c->status) == MPD_STATE_PAUSE);
166 }
167 
168 gcc_pure
169 static inline const struct mpd_song *
170 mpdclient_get_current_song(const struct mpdclient *c)
171 {
172  return c->song != NULL && mpdclient_is_playing(c)
173  ? c->song
174  : NULL;
175 }
176 
177 void
178 mpdclient_connect(struct mpdclient *c);
179 
180 void
182 
183 bool
184 mpdclient_update(struct mpdclient *c);
185 
186 struct mpd_connection *
188 
189 /*** MPD Commands **********************************************************/
190 
191 bool
192 mpdclient_cmd_crop(struct mpdclient *c);
193 
194 bool
195 mpdclient_cmd_clear(struct mpdclient *c);
196 
197 bool
198 mpdclient_cmd_volume(struct mpdclient *c, gint value);
199 
200 bool
202 
203 bool
205 
206 bool
207 mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
208 
209 bool
210 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
211 
212 bool
213 mpdclient_cmd_delete(struct mpdclient *c, gint index);
214 
215 bool
216 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
217 
218 bool
219 mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src);
220 
221 bool
222 mpdclient_cmd_subscribe(struct mpdclient *c, const char *channel);
223 
224 bool
225 mpdclient_cmd_unsubscribe(struct mpdclient *c, const char *channel);
226 
227 bool
228 mpdclient_cmd_send_message(struct mpdclient *c, const char *channel,
229  const char *text);
230 
231 bool
233 
234 struct mpd_message *
236 
237 /*** playlist functions **************************************************/
238 
239 /* update the complete playlist */
240 bool
242 
243 /* get playlist changes */
244 bool
246 
247 /* add all songs in filelist to the playlist */
248 bool
249 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
250 
251 #endif
unsigned timeout_ms
Definition: mpdclient.h:34
const char * host
Definition: mpdclient.h:30
bool mpdclient_playlist_update(struct mpdclient *c)
enum mpd_idle events
Definition: mpdclient.h:73
struct mpdclient * mpdclient_new(const gchar *host, unsigned port, unsigned timeout_ms, const gchar *password)
bool mpdclient_send_read_messages(struct mpdclient *c)
bool idle
Definition: mpdclient.h:83
bool mpdclient_cmd_unsubscribe(struct mpdclient *c, const char *channel)
bool mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end)
bool playing
Definition: mpdclient.h:88
unsigned enter_idle_source_id
Definition: mpdclient.h:60
Definition: filelist.h:35
void mpdclient_free(struct mpdclient *c)
bool mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path)
bool mpdclient_cmd_volume(struct mpdclient *c, gint value)
const char * password
Definition: mpdclient.h:36
Definition: mpdclient.h:96
unsigned connection_id
Definition: mpdclient.h:66
bool mpdclient_cmd_delete(struct mpdclient *c, gint index)
Definition: mpdclient.h:12
struct mpd_status * status
Definition: mpdclient.h:53
struct mpdclient_playlist playlist
Definition: mpdclient.h:39
void mpdclient_disconnect(struct mpdclient *c)
void mpdclient_connect(struct mpdclient *c)
struct mpd_glib_source * source
Definition: mpdclient.h:51
bool mpdclient_handle_error(struct mpdclient *c)
char * mpdclient_settings_name(const struct mpdclient *c)
bool mpdclient_update(struct mpdclient *c)
unsigned port
Definition: mpdclient.h:31
bool mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl)
struct mpd_message * mpdclient_recv_message(struct mpdclient *c)
bool mpdclient_cmd_crop(struct mpdclient *c)
bool mpdclient_playlist_update_changes(struct mpdclient *c)
bool mpdclient_cmd_volume_down(struct mpdclient *c)
const struct mpd_song * song
Definition: mpdclient.h:54
bool mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src)
struct mpd_connection * mpdclient_get_connection(struct mpdclient *c)
int volume
Definition: mpdclient.h:68
bool mpdclient_cmd_send_message(struct mpdclient *c, const char *channel, const char *text)
bool mpdclient_cmd_subscribe(struct mpdclient *c, const char *channel)
#define gcc_pure
Definition: Compiler.h:100
struct mpd_connection * connection
Definition: mpdclient.h:45
bool mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song)
bool mpdclient_cmd_volume_up(struct mpdclient *c)
bool mpdclient_cmd_clear(struct mpdclient *c)
Definition: playlist.h:30