diff --git a/src/mpdclient.c b/src/mpdclient.c
index 59b0ad45ff504c8c47959e708220747b2b50b907..e55c1362482ece91917b22875f9dc9f671c339d3 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
/* ncmpc (Ncurses MPD Client)
* (c) 2004-2010 The Music Player Daemon Project
* Project homepage: http://musicpd.org
-
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
-
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-
+ *
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
+ */
#include "mpdclient.h"
#include "filelist.h"
return false;
}
-static bool
-mpdclient_finish_command(struct mpdclient *c)
-{
- return mpd_response_finish(c->connection)
- ? true : mpdclient_handle_error(c);
-}
-
struct mpdclient *
mpdclient_new(void)
{
c->idle = false;
}
- if (c->connection)
+ if (c->connection) {
mpd_connection_free(c->connection);
+ ++c->connection_id;
+ }
c->connection = NULL;
if (c->status)
c->song = NULL;
/* everything has changed after a disconnect */
- c->events |= MPD_IDLE_DATABASE|MPD_IDLE_STORED_PLAYLIST|
- MPD_IDLE_QUEUE|MPD_IDLE_PLAYER|MPD_IDLE_MIXER|MPD_IDLE_OUTPUT|
- MPD_IDLE_OPTIONS|MPD_IDLE_UPDATE;
+ c->events |= MPD_IDLE_ALL;
}
bool
mpdclient_connect(struct mpdclient *c,
const gchar *host,
gint port,
- gfloat _timeout,
+ unsigned timeout_ms,
const gchar *password)
{
/* close any open connection */
- if( c->connection )
+ if (c->connection)
mpdclient_disconnect(c);
/* connect to MPD */
- c->connection = mpd_connection_new(host, port, _timeout * 1000);
+ c->connection = mpd_connection_new(host, port, timeout_ms);
if (c->connection == NULL)
g_error("Out of memory");
return false;
}
+ ++c->connection_id;
+
return true;
}
if (connection == NULL)
return false;
- mpd_send_add(connection, path_utf8);
- return mpdclient_finish_command(c);
+ return mpd_send_add(connection, path_utf8)?
+ mpdclient_finish_command(c) : false;
}
bool
return true;
}
+#if LIBMPDCLIENT_CHECK_VERSION(2,5,0)
+/* The client-to-client protocol (MPD 0.17.0) */
+
+bool
+mpdclient_cmd_subscribe(struct mpdclient *c, const char *channel)
+{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
+
+ if (connection == NULL)
+ return false;
+
+ if (!mpd_send_subscribe(connection, channel))
+ return mpdclient_handle_error(c);
+
+ return mpdclient_finish_command(c);
+}
+
+bool
+mpdclient_cmd_unsubscribe(struct mpdclient *c, const char *channel)
+{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ return false;
+
+ if (!mpd_send_unsubscribe(connection, channel))
+ return mpdclient_handle_error(c);
+
+ return mpdclient_finish_command(c);
+}
+
+bool
+mpdclient_cmd_send_message(struct mpdclient *c, const char *channel,
+ const char *text)
+{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ return false;
+
+ if (!mpd_send_send_message(connection, channel, text))
+ return mpdclient_handle_error(c);
+
+ return mpdclient_finish_command(c);
+}
+
+bool
+mpdclient_send_read_messages(struct mpdclient *c)
+{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ return false;
+
+ return mpd_send_read_messages(connection)?
+ true : mpdclient_handle_error(c);
+}
+
+struct mpd_message *
+mpdclient_recv_message(struct mpdclient *c)
+{
+ struct mpd_connection *connection = mpdclient_get_connection(c);
+ if (connection == NULL)
+ return false;
+
+ struct mpd_message *message = mpd_recv_message(connection);
+ if (message == NULL &&
+ mpd_connection_get_error(connection) != MPD_ERROR_SUCCESS)
+ mpdclient_handle_error(c);
+
+ return message;
+}
+#endif
/****************************************************************************/
/*** Playlist management functions ******************************************/