Code

mpdclient: add client-to-client support
authorJonathan Neuschäfer <j.neuschaefer@gmx.net>
Wed, 4 Jan 2012 17:33:31 +0000 (18:33 +0100)
committerJonathan Neuschäfer <j.neuschaefer@gmx.net>
Wed, 23 May 2012 01:50:38 +0000 (03:50 +0200)
src/mpdclient.c
src/mpdclient.h

index 685d149a3cb5004dbff5d0ad02e66cd022f86c11..e55c1362482ece91917b22875f9dc9f671c339d3 100644 (file)
@@ -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 ******************************************/
index e9234805d6443f88692fb2c689c208cd11b28921..bca739b78ea025dee105c0539369875c690577d1 100644 (file)
@@ -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 */