From dfc94ef4288f85cfe87a928ddc0a9fa6e5a2a7d0 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 29 Sep 2009 18:20:26 +0200 Subject: [PATCH] mpdclient: added mpdclient_is_connected() This allows us to remove the global "connected" variable from main.c. --- src/main.c | 8 ++------ src/mpdclient.h | 7 +++++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index 058c84a..398a46f 100644 --- a/src/main.c +++ b/src/main.c @@ -59,7 +59,6 @@ static const guint update_interval = 500; #define BUFSIZE 1024 static struct mpdclient *mpd = NULL; -static gboolean connected = FALSE; static GMainLoop *main_loop; static guint reconnect_source_id, update_source_id; @@ -97,7 +96,6 @@ error_callback(G_GNUC_UNUSED struct mpdclient *c, gint error, const gchar *_msg) screen_status_printf("%s", msg); screen_bell(); doupdate(); - connected = FALSE; } g_free(msg); @@ -203,7 +201,7 @@ timer_reconnect(G_GNUC_UNUSED gpointer data) { int ret; - assert(!connected); + assert(!mpdclient_is_connected(mpd)); screen_status_printf(_("Connecting to %s... [Press %s to abort]"), options.host, get_key_names(CMD_QUIT,0) ); @@ -242,8 +240,6 @@ timer_reconnect(G_GNUC_UNUSED gpointer data) ? options.host : "localhost"); doupdate(); - connected = TRUE; - /* update immediately */ g_timeout_add(1, timer_mpd_update, GINT_TO_POINTER(FALSE)); @@ -255,7 +251,7 @@ timer_reconnect(G_GNUC_UNUSED gpointer data) static gboolean timer_mpd_update(gpointer data) { - if (connected) + if (mpdclient_is_connected(mpd)) mpdclient_update(mpd); else if (reconnect_source_id == 0) reconnect_source_id = g_timeout_add(1000, timer_reconnect, diff --git a/src/mpdclient.h b/src/mpdclient.h index e1b7476..37c3681 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -35,6 +35,13 @@ struct mpdclient * mpdclient_new(void); void mpdclient_free(struct mpdclient *c); + +static inline bool +mpdclient_is_connected(const struct mpdclient *c) +{ + return c->connection != NULL; +} + gint mpdclient_connect(struct mpdclient *c, const gchar *host, gint port, gfloat timeout_, const gchar *password); gint mpdclient_disconnect(struct mpdclient *c); -- 2.30.2