From 4510f23ef3a628c23fdacb860751e2bd6b3ace04 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonathan=20Neusch=C3=A4fer?= Date: Wed, 4 Jan 2012 18:33:31 +0100 Subject: [PATCH] mpdclient: add client-to-client support --- src/mpdclient.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ src/mpdclient.h | 18 +++++++++++++ 2 files changed, 88 insertions(+) diff --git a/src/mpdclient.c b/src/mpdclient.c index 685d149..e55c136 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -654,6 +654,76 @@ mpdclient_cmd_move(struct mpdclient *c, unsigned dest_pos, unsigned src_pos) 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 ******************************************/ diff --git a/src/mpdclient.h b/src/mpdclient.h index e923480..bca739b 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -165,6 +165,24 @@ mpdclient_cmd_delete_range(struct mpdclient *c, unsigned start, unsigned end); bool mpdclient_cmd_move(struct mpdclient *c, unsigned dest, unsigned src); +#if LIBMPDCLIENT_CHECK_VERSION(2,5,0) +bool +mpdclient_cmd_subscribe(struct mpdclient *c, const char *channel); + +bool +mpdclient_cmd_unsubscribe(struct mpdclient *c, const char *channel); + +bool +mpdclient_cmd_send_message(struct mpdclient *c, const char *channel, + const char *text); + +bool +mpdclient_send_read_messages(struct mpdclient *c); + +struct mpd_message * +mpdclient_recv_message(struct mpdclient *c); +#endif + /*** playlist functions **************************************************/ /* update the complete playlist */ -- 2.30.2