Example #1
0
static gboolean
lmc_idle(G_GNUC_UNUSED GIOChannel *source,
	 G_GNUC_UNUSED GIOCondition condition,
	 G_GNUC_UNUSED gpointer data)
{
	bool success;
	enum mpd_idle idle;

	assert(idle_source_id != 0);
	assert(g_mpd != NULL);
	assert(mpd_connection_get_error(g_mpd) == MPD_ERROR_SUCCESS);

	idle_source_id = 0;

	idle = mpd_recv_idle(g_mpd, false);
	success = mpd_response_finish(g_mpd);

	if (!success && mpd_connection_get_error(g_mpd) == MPD_ERROR_SERVER &&
	    mpd_connection_get_server_error(g_mpd) == MPD_SERVER_ERROR_UNKNOWN_CMD &&
	    mpd_connection_clear_error(g_mpd)) {
		/* MPD does not recognize the "idle" command - disable
		   it for this connection */

		g_message("MPD does not support the 'idle' command - "
			  "falling back to polling\n");

		idle_supported = false;
		lmc_schedule_update();
		return false;
	}

	if (!success) {
		lmc_failure();
		lmc_schedule_reconnect();
		return false;
	}

#if LIBMPDCLIENT_CHECK_VERSION(2,5,0)
	if (subscribed && (idle & MPD_IDLE_MESSAGE) != 0 &&
	    !lmc_read_messages()) {
		lmc_failure();
		lmc_schedule_reconnect();
		return false;
	}
#endif

	if (idle & MPD_IDLE_PLAYER)
		/* there was a change: query MPD */
		lmc_schedule_update();
	else
		/* nothing interesting: re-enter idle */
		lmc_schedule_idle();

	return false;
}
Example #2
0
int Connection::noidle()
{
	checkConnection();
	int flags = 0;
	if (m_idle && mpd_send_noidle(m_connection.get()))
	{
		m_idle = false;
		flags = mpd_recv_idle(m_connection.get(), true);
		mpd_response_finish(m_connection.get());
		checkErrors();
	}
	return flags;
}
Example #3
0
File: mpd.c Project: cmende/mpd2irc
static gboolean mpd_parse(G_GNUC_UNUSED GIOChannel *channel,
		G_GNUC_UNUSED GIOCondition condition,
		G_GNUC_UNUSED gboolean user_data)
{
	mpd_recv_idle(mpd.conn, FALSE);

	if (!mpd_response_finish(mpd.conn)) {
		mpd_report_error();
		return FALSE;
	}

	mpd_update();

	mpd_send_idle_mask(mpd.conn, MPD_IDLE_PLAYER);
	return TRUE;
}