summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 480e564)
raw | patch | inline | side by side (parent: 480e564)
author | Max Kellermann <max@duempel.org> | |
Tue, 29 Sep 2009 16:20:26 +0000 (18:20 +0200) | ||
committer | Max Kellermann <max@duempel.org> | |
Tue, 29 Sep 2009 16:20:26 +0000 (18:20 +0200) |
This allows us to remove the global "connected" variable from main.c.
src/main.c | patch | blob | history | |
src/mpdclient.h | patch | blob | history |
diff --git a/src/main.c b/src/main.c
index 058c84a21b54765e5eb6d01fdbdfef64396436da..398a46f78af3239b6a5f6c61190401433c66d056 100644 (file)
--- a/src/main.c
+++ b/src/main.c
#define BUFSIZE 1024
static struct mpdclient *mpd = NULL;
-static gboolean connected = FALSE;
static GMainLoop *main_loop;
static guint reconnect_source_id, update_source_id;
screen_status_printf("%s", msg);
screen_bell();
doupdate();
- connected = FALSE;
}
g_free(msg);
{
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) );
? options.host : "localhost");
doupdate();
- connected = TRUE;
-
/* update immediately */
g_timeout_add(1, timer_mpd_update, GINT_TO_POINTER(FALSE));
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 e1b747661f493daa6bb5e61d8eec955398f0c3be..37c368148ea14965f85e73a38909628b14577dbf 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
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);