Code

mpdclient: add G_GNUC_PURE to _is_connected()/_get_current_song()
[ncmpc.git] / src / mpdclient.h
1 #ifndef MPDCLIENT_H
2 #define MPDCLIENT_H
4 #include "playlist.h"
5 #include "mpdclient.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          * If this object is non-NULL, it tracks idle events.  It is
19          * automatically called by mpdclient_get_connection() and
20          * mpdclient_put_connection().  It is not created by the
21          * mpdclient library; the user of this library has to
22          * initialize it.  However, it is freed when the MPD
23          * connection is closed.
24          */
25         struct mpd_glib_source *source;
27         /**
28          * This attribute is true when the connection is currently in
29          * "idle" mode, and the #mpd_glib_source waits for an event.
30          */
31         bool idle;
33         struct mpd_status *status;
34         const struct mpd_song *song;
36         int volume;
37         unsigned update_id;
39         /**
40          * A bit mask of idle events occurred since the last update.
41          */
42         enum mpd_idle events;
43 };
45 enum {
46         /**
47          * all idle events the version of libmpdclient, ncmpc is compiled
48          * against, supports
49          */
50         MPD_IDLE_ALL = MPD_IDLE_DATABASE
51                 | MPD_IDLE_STORED_PLAYLIST
52                 | MPD_IDLE_QUEUE
53                 | MPD_IDLE_PLAYER
54                 | MPD_IDLE_MIXER
55                 | MPD_IDLE_OUTPUT
56                 | MPD_IDLE_OPTIONS
57                 | MPD_IDLE_UPDATE
58 #if LIBMPDCLIENT_CHECK_VERSION(2,5,0)
59                 | MPD_IDLE_STICKER
60                 | MPD_IDLE_SUBSCRIPTION
61                 | MPD_IDLE_MESSAGE
62 #endif
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 G_GNUC_PURE
83 static inline bool
84 mpdclient_is_connected(const struct mpdclient *c)
85 {
86         return c->connection != NULL;
87 }
89 G_GNUC_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 G_GNUC_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 /**
124  * To be implemented by the application: mpdclient.c calls this to
125  * display an error message.
126  */
127 void
128 mpdclient_ui_error(const char *message);
130 /*** MPD Commands  **********************************************************/
132 bool
133 mpdclient_cmd_crop(struct mpdclient *c);
135 bool
136 mpdclient_cmd_clear(struct mpdclient *c);
138 bool
139 mpdclient_cmd_volume(struct mpdclient *c, gint value);
141 bool
142 mpdclient_cmd_volume_up(struct mpdclient *c);
144 bool
145 mpdclient_cmd_volume_down(struct mpdclient *c);
147 bool
148 mpdclient_cmd_add_path(struct mpdclient *c, const gchar *path);
150 bool
151 mpdclient_cmd_add(struct mpdclient *c, const struct mpd_song *song);
153 bool
154 mpdclient_cmd_delete(struct mpdclient *c, gint index);
156 bool
157 mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end);
159 bool
160 mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src);
162 /*** playlist functions  **************************************************/
164 /* update the complete playlist */
165 bool
166 mpdclient_playlist_update(struct mpdclient *c);
168 /* get playlist changes */
169 bool
170 mpdclient_playlist_update_changes(struct mpdclient *c);
172 /* add all songs in filelist to the playlist */
173 bool
174 mpdclient_filelist_add_all(struct mpdclient *c, struct filelist *fl);
176 /* sort by list-format */
177 gint compare_filelistentry_format(gconstpointer filelist_entry1, gconstpointer filelist_entry2);
179 #endif