From f0e91f27fc28df9216b3dfa82f8093362a538ed6 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 17 Mar 2017 22:26:37 +0100 Subject: [PATCH] main: move mpd_glib_new() call to mpdclient.c --- src/callbacks.h | 8 ++++++++ src/main.c | 24 +++++++----------------- src/mpdclient.c | 3 +++ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/callbacks.h b/src/callbacks.h index 2bc8473..6100508 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -20,6 +20,8 @@ #ifndef NCMPC_CALLBACKS_H #define NCMPC_CALLBACKS_H +#include + #include struct mpdclient; @@ -34,4 +36,10 @@ mpdclient_error_callback(const char *message); bool mpdclient_auth_callback(struct mpdclient *c); +void +mpdclient_idle_callback(enum mpd_error error, + enum mpd_server_error server_error, + const char *message, enum mpd_idle events, + void *ctx); + #endif diff --git a/src/main.c b/src/main.c index 1459df4..31112fb 100644 --- a/src/main.c +++ b/src/main.c @@ -20,7 +20,7 @@ #include "config.h" #include "ncmpc.h" #include "mpdclient.h" -#include "gidle.h" +#include "callbacks.h" #include "charset.h" #include "options.h" #include "command.h" @@ -157,12 +157,6 @@ catch_sigwinch(gcc_unused int sig) } #endif /* WIN32 */ -static void -idle_callback(enum mpd_error error, - gcc_unused enum mpd_server_error server_error, - const char *message, enum mpd_idle events, - gcc_unused void *ctx); - static gboolean timer_mpd_update(gpointer data); @@ -290,10 +284,9 @@ timer_reconnect(gcc_unused gpointer data) return FALSE; } - struct mpd_connection *connection = mpdclient_get_connection(mpd); - #ifndef NCMPC_MINI /* quit if mpd is pre 0.14 - song id not supported by mpd */ + struct mpd_connection *connection = mpdclient_get_connection(mpd); if (mpd_connection_cmp_server_version(connection, 0, 16, 0) < 0) { const unsigned *version = mpd_connection_get_server_version(connection); @@ -310,9 +303,6 @@ timer_reconnect(gcc_unused gpointer data) } #endif - mpd->source = mpd_glib_new(connection, - idle_callback, mpd); - screen_status_clear_message(); doupdate(); @@ -339,11 +329,11 @@ check_reconnect(void) * This function is called by the gidle.c library when MPD sends us an * idle event (or when the connection dies). */ -static void -idle_callback(enum mpd_error error, - gcc_unused enum mpd_server_error server_error, - const char *message, enum mpd_idle events, - void *ctx) +void +mpdclient_idle_callback(enum mpd_error error, + gcc_unused enum mpd_server_error server_error, + const char *message, enum mpd_idle events, + void *ctx) { struct mpdclient *c = ctx; diff --git a/src/mpdclient.c b/src/mpdclient.c index 582d302..f0076b6 100644 --- a/src/mpdclient.c +++ b/src/mpdclient.c @@ -162,6 +162,9 @@ mpdclient_connect(struct mpdclient *c, return false; } + c->source = mpd_glib_new(c->connection, + mpdclient_idle_callback, c); + ++c->connection_id; return true; -- 2.30.2