Code

mpdclient: update the "source" documentation
[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          * Tracks idle events.  It is automatically called by
25          * mpdclient_get_connection() and mpdclient_put_connection().
26          */
27         struct mpd_glib_source *source;
29         /**
30          * This attribute is true when the connection is currently in
31          * "idle" mode, and the #mpd_glib_source waits for an event.
32          */
33         bool idle;
35         struct mpd_status *status;
36         const struct mpd_song *song;
38         int volume;
39         unsigned update_id;
41         /**
42          * A bit mask of idle events occurred since the last update.
43          */
44         enum mpd_idle events;
45 };
47 enum {
48         /**
49          * all idle events the version of libmpdclient, ncmpc is compiled
50          * against, supports
51          */
52         MPD_IDLE_ALL = MPD_IDLE_DATABASE
53                 | MPD_IDLE_STORED_PLAYLIST
54                 | MPD_IDLE_QUEUE
55                 | MPD_IDLE_PLAYER
56                 | MPD_IDLE_MIXER
57                 | MPD_IDLE_OUTPUT
58                 | MPD_IDLE_OPTIONS
59                 | MPD_IDLE_UPDATE
60                 | MPD_IDLE_STICKER
61                 | MPD_IDLE_SUBSCRIPTION
62                 | MPD_IDLE_MESSAGE
63 };
65 /** functions ***************************************************************/
67 bool
68 mpdclient_handle_error(struct mpdclient *c);
70 static inline bool
71 mpdclient_finish_command(struct mpdclient *c)
72 {
73         return mpd_response_finish(c->connection)
74                 ? true : mpdclient_handle_error(c);
75 }
77 struct mpdclient *
78 mpdclient_new(void);
80 void mpdclient_free(struct mpdclient *c);
82 gcc_pure
83 static inline bool
84 mpdclient_is_connected(const struct mpdclient *c)
85 {
86         return c->connection != NULL;
87 }
89 gcc_pure
90 static inline bool
91 mpdclient_is_playing(const struct mpdclient *c)
92 {
93         return c->status != NULL &&
94                 (mpd_status_get_state(c->status) == MPD_STATE_PLAY ||
95                  mpd_status_get_state(c->status) == MPD_STATE_PAUSE);
96 }
98 gcc_pure
99 static inline const struct mpd_song *
100 mpdclient_get_current_song(const struct mpdclient *c)
102         return c->song != NULL && mpdclient_is_playing(c)
103                 ? c->song
104                 : NULL;
107 bool
108 mpdclient_connect(struct mpdclient *c, const gchar *host, gint port,
109                   unsigned timeout_ms, const gchar *password);
111 void
112 mpdclient_disconnect(struct mpdclient *c);
114 bool
115 mpdclient_update(struct mpdclient *c);
117 struct mpd_connection *
118 mpdclient_get_connection(struct mpdclient *c);
120 void
121 mpdclient_put_connection(struct mpdclient *c);
123 /*** MPD Commands  **********************************************************/
125 bool
126 mpdclient_cmd_crop(struct mpdclient *c);
128 bool
129 mpdclient_cmd_clear(struct mpdclient *c);
131 bool
132 mpdclient_cmd_volume(struct mpdclient *c, gint value);
134 bool
135 mpdclient_cmd_volume_up(struct mpdclient *c);
137 bool
138 mpdclient_cmd_volume_down(struct mpdclient *c);
140 bool
141 mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
143 bool
144 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
146 bool
147 mpdclient_cmd_delete(struct mpdclient *c, gint index);
149 bool
150 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
152 bool
153 mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src);
155 bool
156 mpdclient_cmd_subscribe(struct mpdclient *c, const char *channel);
158 bool
159 mpdclient_cmd_unsubscribe(struct mpdclient *c, const char *channel);
161 bool
162 mpdclient_cmd_send_message(struct mpdclient *c, const char *channel,
163                            const char *text);
165 bool
166 mpdclient_send_read_messages(struct mpdclient *c);
168 struct mpd_message *
169 mpdclient_recv_message(struct mpdclient *c);
171 /*** playlist functions  **************************************************/
173 /* update the complete playlist */
174 bool
175 mpdclient_playlist_update(struct mpdclient *c);
177 /* get playlist changes */
178 bool
179 mpdclient_playlist_update_changes(struct mpdclient *c);
181 /* add all songs in filelist to the playlist */
182 bool
183 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
185 #endif