summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 67a0cef)
raw | patch | inline | side by side (parent: 67a0cef)
author | Max Kellermann <max.kellermann@gmail.com> | |
Sun, 19 Mar 2017 11:20:23 +0000 (12:20 +0100) | ||
committer | Max Kellermann <max.kellermann@gmail.com> | |
Sun, 19 Mar 2017 11:20:23 +0000 (12:20 +0100) |
src/main.c | patch | blob | history | |
src/mpdclient.c | patch | blob | history | |
src/mpdclient.h | patch | blob | history | |
src/player_command.c | patch | blob | history |
diff --git a/src/main.c b/src/main.c
index 8d07b426725ef90420611309e47ceac7e07469c1..8ade659e69ddc0f997fa2bfe46a74a6754568998 100644 (file)
--- a/src/main.c
+++ b/src/main.c
screen_update(mpd);
mpd->events = 0;
- mpdclient_put_connection(mpd);
check_reconnect();
}
screen_update(mpd);
mpd->events = 0;
- mpdclient_put_connection(mpd);
check_reconnect();
auto_update_timer();
}
diff --git a/src/mpdclient.c b/src/mpdclient.c
index c1c4a31e6143cfb9ae200d3514d23e61c524c64e..1a059d517e1a3571a66c7c193b2c108bf8695bb7 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
#include <assert.h>
+static gboolean
+mpdclient_enter_idle_callback(gpointer user_data)
+{
+ struct mpdclient *c = user_data;
+ assert(c->enter_idle_source_id != 0);
+ assert(c->source != NULL);
+ assert(!c->idle);
+
+ c->enter_idle_source_id = 0;
+ c->idle = mpd_glib_enter(c->source);
+ return false;
+}
+
+static void
+mpdclient_schedule_enter_idle(struct mpdclient *c)
+{
+ assert(c != NULL);
+ assert(c->source != NULL);
+
+ if (c->enter_idle_source_id == 0)
+ /* automatically re-enter MPD "idle" mode */
+ c->enter_idle_source_id =
+ g_idle_add(mpdclient_enter_idle_callback, c);
+}
+
+static void
+mpdclient_cancel_enter_idle(struct mpdclient *c)
+{
+ if (c->enter_idle_source_id != 0) {
+ g_source_remove(c->enter_idle_source_id);
+ c->enter_idle_source_id = 0;
+ }
+}
+
static void
mpdclient_invoke_error_callback(enum mpd_error error,
const char *message)
c->events = 0;
- mpdclient_put_connection(c);
+ if (c->source != NULL)
+ mpdclient_schedule_enter_idle(c);
}
/****************************************************************************/
void
mpdclient_disconnect(struct mpdclient *c)
{
+ mpdclient_cancel_enter_idle(c);
+
if (c->source != NULL) {
mpd_glib_free(c->source);
c->source = NULL;
c->source = mpd_glib_new(c->connection,
mpdclient_gidle_callback, c);
+ mpdclient_schedule_enter_idle(c);
++c->connection_id;
if (c->source != NULL && c->idle) {
c->idle = false;
mpd_glib_leave(c->source);
+
+ mpdclient_schedule_enter_idle(c);
}
return c->connection;
}
-void
-mpdclient_put_connection(struct mpdclient *c)
-{
- assert(c->source == NULL || c->connection != NULL);
-
- if (c->source != NULL && !c->idle) {
- c->idle = mpd_glib_enter(c->source);
- }
-}
-
static struct mpd_status *
mpdclient_recv_status(struct mpdclient *c)
{
diff --git a/src/mpdclient.h b/src/mpdclient.h
index 371d42935ecff3374fe9646162b4274c0eb98fc6..bac33383ab1bc33ccb34a614b5091fda8080f2cf 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
/**
* Tracks idle events. It is automatically called by
- * mpdclient_get_connection() and mpdclient_put_connection().
+ * mpdclient_get_connection().
*/
struct mpd_glib_source *source;
struct mpd_status *status;
const struct mpd_song *song;
+ /**
+ * The GLib source id which re-enters MPD idle mode before the
+ * next main loop interation.
+ */
+ unsigned enter_idle_source_id;
+
/**
* This attribute is incremented whenever the connection changes
* (i.e. on disconnection and (re-)connection).
struct mpd_connection *
mpdclient_get_connection(struct mpdclient *c);
-void
-mpdclient_put_connection(struct mpdclient *c);
-
/*** MPD Commands **********************************************************/
bool
diff --git a/src/player_command.c b/src/player_command.c
index f2353f7cf695646bf5dae66ac167674fb03884bf..1a06bfabcb1b9b1bf465f883b9a02fd927bffba4 100644 (file)
--- a/src/player_command.c
+++ b/src/player_command.c
seek_source_id = 0;
commit_seek(c);
- mpdclient_put_connection(c);
return false;
}