summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b59430b)
raw | patch | inline | side by side (parent: b59430b)
author | Max Kellermann <max.kellermann@gmail.com> | |
Sun, 19 Mar 2017 10:55:54 +0000 (11:55 +0100) | ||
committer | Max Kellermann <max.kellermann@gmail.com> | |
Sun, 19 Mar 2017 10:55:54 +0000 (11:55 +0100) |
src/main.c | patch | blob | history | |
src/mpdclient.c | patch | blob | history | |
src/mpdclient.h | patch | blob | history |
diff --git a/src/main.c b/src/main.c
index c242da922e97e715ac88a27856f51d04e042c1a9..d9c3ddb0d28c48e7dbf7663068b9c0aabe9e3908 100644 (file)
--- a/src/main.c
+++ b/src/main.c
doupdate();
mpdclient_disconnect(mpd);
- mpdclient_connect(mpd, options.host, options.port,
- options.timeout_ms,
- options.password);
+ mpdclient_connect(mpd);
return FALSE;
}
#endif
/* create mpdclient instance */
- mpd = mpdclient_new();
+ mpd = mpdclient_new(options.host, options.port,
+ options.timeout_ms,
+ options.password);
/* initialize curses */
screen_init(mpd);
diff --git a/src/mpdclient.c b/src/mpdclient.c
index 31e8a721fa517ce220486d87c8fce6612d6c4dfe..c1c4a31e6143cfb9ae200d3514d23e61c524c64e 100644 (file)
--- a/src/mpdclient.c
+++ b/src/mpdclient.c
}
struct mpdclient *
-mpdclient_new(void)
+mpdclient_new(const gchar *host, unsigned port,
+ unsigned timeout_ms, const gchar *password)
{
struct mpdclient *c = g_new0(struct mpdclient, 1);
+
+ c->host = host;
+ c->port = port;
+ c->timeout_ms = timeout_ms;
+ c->password = password;
+
playlist_init(&c->playlist);
c->volume = -1;
c->events = 0;
}
bool
-mpdclient_connect(struct mpdclient *c,
- const gchar *host,
- unsigned port,
- unsigned timeout_ms,
- const gchar *password)
+mpdclient_connect(struct mpdclient *c)
{
/* close any open connection */
mpdclient_disconnect(c);
/* connect to MPD */
- c->connection = mpd_connection_new(host, port, timeout_ms);
+ c->connection = mpd_connection_new(c->host, c->port, c->timeout_ms);
if (c->connection == NULL)
g_error("Out of memory");
}
/* send password */
- if (password != NULL && !mpd_run_password(c->connection, password)) {
+ if (c->password != NULL &&
+ !mpd_run_password(c->connection, c->password)) {
mpdclient_handle_error(c);
mpdclient_disconnect(c);
mpdclient_failed_callback();
diff --git a/src/mpdclient.h b/src/mpdclient.h
index b959f5c426d9e36cd70138510354a7739c3ee7e3..371d42935ecff3374fe9646162b4274c0eb98fc6 100644 (file)
--- a/src/mpdclient.h
+++ b/src/mpdclient.h
struct filelist;
struct mpdclient {
+ const char *host;
+ unsigned port;
+
+ unsigned timeout_ms;
+
+ const char *password;
+
/* playlist */
struct mpdclient_playlist playlist;
}
struct mpdclient *
-mpdclient_new(void);
+mpdclient_new(const gchar *host, unsigned port,
+ unsigned timeout_ms, const gchar *password);
void mpdclient_free(struct mpdclient *c);
}
bool
-mpdclient_connect(struct mpdclient *c, const gchar *host, unsigned port,
- unsigned timeout_ms, const gchar *password);
+mpdclient_connect(struct mpdclient *c);
void
mpdclient_disconnect(struct mpdclient *c);