main: check for strfsong() failure, add fallback
[ncmpc.git] / src / mpdclient.h
blobb00709748eff7d99436d46d6675feb10a8535dd4
1 #ifndef MPDCLIENT_H
2 #define MPDCLIENT_H
4 #include "config.h"
5 #include "playlist.h"
6 #include "Compiler.h"
8 #include <mpd/client.h>
10 struct filelist;
12 struct mpdclient {
13 #ifdef ENABLE_ASYNC_CONNECT
14 struct mpd_settings *settings;
15 #else
16 const char *host;
17 unsigned port;
18 #endif
20 unsigned timeout_ms;
22 const char *password;
24 /* playlist */
25 struct mpdclient_playlist playlist;
27 #ifdef ENABLE_ASYNC_CONNECT
28 struct aconnect *async_connect;
29 #endif
31 struct mpd_connection *connection;
33 /**
34 * Tracks idle events. It is automatically called by
35 * mpdclient_get_connection().
37 struct mpd_glib_source *source;
39 struct mpd_status *status;
40 const struct mpd_song *song;
42 /**
43 * The GLib source id which re-enters MPD idle mode before the
44 * next main loop interation.
46 unsigned enter_idle_source_id;
48 /**
49 * This attribute is incremented whenever the connection changes
50 * (i.e. on disconnection and (re-)connection).
52 unsigned connection_id;
54 int volume;
56 /**
57 * A bit mask of idle events occurred since the last update.
59 enum mpd_idle events;
61 /**
62 * This attribute is true when the connection is currently in
63 * "idle" mode, and the #mpd_glib_source waits for an event.
65 bool idle;
67 /**
68 * Is MPD currently playing?
70 bool playing;
73 enum {
74 /**
75 * all idle events the version of libmpdclient, ncmpc is compiled
76 * against, supports
78 MPD_IDLE_ALL = MPD_IDLE_DATABASE
79 | MPD_IDLE_STORED_PLAYLIST
80 | MPD_IDLE_QUEUE
81 | MPD_IDLE_PLAYER
82 | MPD_IDLE_MIXER
83 | MPD_IDLE_OUTPUT
84 | MPD_IDLE_OPTIONS
85 | MPD_IDLE_UPDATE
86 | MPD_IDLE_STICKER
87 | MPD_IDLE_SUBSCRIPTION
88 | MPD_IDLE_MESSAGE
91 /** functions ***************************************************************/
93 bool
94 mpdclient_handle_error(struct mpdclient *c);
96 static inline bool
97 mpdclient_finish_command(struct mpdclient *c)
99 return mpd_response_finish(c->connection)
100 ? true : mpdclient_handle_error(c);
103 struct mpdclient *
104 mpdclient_new(const gchar *host, unsigned port,
105 unsigned timeout_ms, const gchar *password);
107 void mpdclient_free(struct mpdclient *c);
109 gcc_pure
110 static inline bool
111 mpdclient_is_connected(const struct mpdclient *c)
113 return c->connection != NULL;
117 * Is this object "dead"? i.e. not connected and not currently doing
118 * anything to connect.
120 gcc_pure
121 static inline bool
122 mpdclient_is_dead(const struct mpdclient *c)
124 return c->connection == NULL
125 #ifdef ENABLE_ASYNC_CONNECT
126 && c->async_connect == NULL
127 #endif
131 gcc_pure
132 static inline bool
133 mpdclient_is_playing(const struct mpdclient *c)
135 return c->status != NULL &&
136 (mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
137 mpd_status_get_state(c->status) == MPD_STATE_PAUSE);
140 gcc_pure
141 static inline const struct mpd_song *
142 mpdclient_get_current_song(const struct mpdclient *c)
144 return c->song != NULL && mpdclient_is_playing(c)
145 ? c->song
146 : NULL;
149 void
150 mpdclient_connect(struct mpdclient *c);
152 void
153 mpdclient_disconnect(struct mpdclient *c);
155 bool
156 mpdclient_update(struct mpdclient *c);
158 struct mpd_connection *
159 mpdclient_get_connection(struct mpdclient *c);
161 /*** MPD Commands **********************************************************/
163 bool
164 mpdclient_cmd_crop(struct mpdclient *c);
166 bool
167 mpdclient_cmd_clear(struct mpdclient *c);
169 bool
170 mpdclient_cmd_volume(struct mpdclient *c, gint value);
172 bool
173 mpdclient_cmd_volume_up(struct mpdclient *c);
175 bool
176 mpdclient_cmd_volume_down(struct mpdclient *c);
178 bool
179 mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
181 bool
182 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
184 bool
185 mpdclient_cmd_delete(struct mpdclient *c, gint index);
187 bool
188 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
190 bool
191 mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src);
193 bool
194 mpdclient_cmd_subscribe(struct mpdclient *c, const char *channel);
196 bool
197 mpdclient_cmd_unsubscribe(struct mpdclient *c, const char *channel);
199 bool
200 mpdclient_cmd_send_message(struct mpdclient *c, const char *channel,
201 const char *text);
203 bool
204 mpdclient_send_read_messages(struct mpdclient *c);
206 struct mpd_message *
207 mpdclient_recv_message(struct mpdclient *c);
209 /*** playlist functions **************************************************/
211 /* update the complete playlist */
212 bool
213 mpdclient_playlist_update(struct mpdclient *c);
215 /* get playlist changes */
216 bool
217 mpdclient_playlist_update_changes(struct mpdclient *c);
219 /* add all songs in filelist to the playlist */
220 bool
221 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
223 #endif