Code

Compiler.h: add macro CLANG_OR_GCC_VERSION()
[ncmpc.git] / src / mpdclient.h
1 #ifndef MPDCLIENT_H
2 #define MPDCLIENT_H
4 #include "playlist.h"
5 #include "Compiler.h"
7 #include <mpd/client.h>
9 struct filelist;
11 struct mpdclient {
12         /* playlist */
13         struct mpdclient_playlist playlist;
15         struct mpd_connection *connection;
17         /**
18          * This attribute is incremented whenever the connection changes
19          * (i.e. on disconnection and (re-)connection).
20          */
21         unsigned connection_id;
23         /**
24          * If this object is non-NULL, it tracks idle events.  It is
25          * automatically called by mpdclient_get_connection() and
26          * mpdclient_put_connection().  It is not created by the
27          * mpdclient library; the user of this library has to
28          * initialize it.  However, it is freed when the MPD
29          * connection is closed.
30          */
31         struct mpd_glib_source *source;
33         /**
34          * This attribute is true when the connection is currently in
35          * "idle" mode, and the #mpd_glib_source waits for an event.
36          */
37         bool idle;
39         struct mpd_status *status;
40         const struct mpd_song *song;
42         int volume;
43         unsigned update_id;
45         /**
46          * A bit mask of idle events occurred since the last update.
47          */
48         enum mpd_idle events;
49 };
51 enum {
52         /**
53          * all idle events the version of libmpdclient, ncmpc is compiled
54          * against, supports
55          */
56         MPD_IDLE_ALL = MPD_IDLE_DATABASE
57                 | MPD_IDLE_STORED_PLAYLIST
58                 | MPD_IDLE_QUEUE
59                 | MPD_IDLE_PLAYER
60                 | MPD_IDLE_MIXER
61                 | MPD_IDLE_OUTPUT
62                 | MPD_IDLE_OPTIONS
63                 | MPD_IDLE_UPDATE
64                 | MPD_IDLE_STICKER
65                 | MPD_IDLE_SUBSCRIPTION
66                 | MPD_IDLE_MESSAGE
67 };
69 /** functions ***************************************************************/
71 bool
72 mpdclient_handle_error(struct mpdclient *c);
74 static inline bool
75 mpdclient_finish_command(struct mpdclient *c)
76 {
77         return mpd_response_finish(c->connection)
78                 ? true : mpdclient_handle_error(c);
79 }
81 struct mpdclient *
82 mpdclient_new(void);
84 void mpdclient_free(struct mpdclient *c);
86 gcc_pure
87 static inline bool
88 mpdclient_is_connected(const struct mpdclient *c)
89 {
90         return c->connection != NULL;
91 }
93 gcc_pure
94 static inline bool
95 mpdclient_is_playing(const struct mpdclient *c)
96 {
97         return c->status != NULL &&
98                 (mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
99                  mpd_status_get_state(c->status) == MPD_STATE_PAUSE);
102 gcc_pure
103 static inline const struct mpd_song *
104 mpdclient_get_current_song(const struct mpdclient *c)
106         return c->song != NULL && mpdclient_is_playing(c)
107                 ? c->song
108                 : NULL;
111 bool
112 mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
113                   unsigned timeout_ms, const gchar *password);
115 void
116 mpdclient_disconnect(struct mpdclient *c);
118 bool
119 mpdclient_update(struct mpdclient *c);
121 struct mpd_connection *
122 mpdclient_get_connection(struct mpdclient *c);
124 void
125 mpdclient_put_connection(struct mpdclient *c);
127 /**
128  * To be implemented by the application: mpdclient.c calls this to
129  * display an error message.
130  */
131 void
132 mpdclient_ui_error(const char *message);
134 /*** MPD Commands  **********************************************************/
136 bool
137 mpdclient_cmd_crop(struct mpdclient *c);
139 bool
140 mpdclient_cmd_clear(struct mpdclient *c);
142 bool
143 mpdclient_cmd_volume(struct mpdclient *c, gint value);
145 bool
146 mpdclient_cmd_volume_up(struct mpdclient *c);
148 bool
149 mpdclient_cmd_volume_down(struct mpdclient *c);
151 bool
152 mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
154 bool
155 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
157 bool
158 mpdclient_cmd_delete(struct mpdclient *c, gint index);
160 bool
161 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
163 bool
164 mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src);
166 bool
167 mpdclient_cmd_subscribe(struct mpdclient *c, const char *channel);
169 bool
170 mpdclient_cmd_unsubscribe(struct mpdclient *c, const char *channel);
172 bool
173 mpdclient_cmd_send_message(struct mpdclient *c, const char *channel,
174                            const char *text);
176 bool
177 mpdclient_send_read_messages(struct mpdclient *c);
179 struct mpd_message *
180 mpdclient_recv_message(struct mpdclient *c);
182 /*** playlist functions  **************************************************/
184 /* update the complete playlist */
185 bool
186 mpdclient_playlist_update(struct mpdclient *c);
188 /* get playlist changes */
189 bool
190 mpdclient_playlist_update_changes(struct mpdclient *c);
192 /* add all songs in filelist to the playlist */
193 bool
194 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
196 /* sort by song format */
197 gcc_pure
198 gint compare_filelistentry_format(gconstpointer filelist_entry1,
199                                   gconstpointer filelist_entry2,
200                                   const char *song_format);
202 #endif