From d488d796f45a89eb20ef1f8dba6824706e1384d9 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 8 Aug 2012 22:18:08 +0200 Subject: player_control: add GError attribute Rewrite of the pc_get_error_message() function, now using a GError object instead of the complicated "errored_song" attribute. --- src/player_control.c | 63 ++++++++++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 36 deletions(-) (limited to 'src/player_control.c') diff --git a/src/player_control.c b/src/player_control.c index 32ceedbe2..69357bf26 100644 --- a/src/player_control.c +++ b/src/player_control.c @@ -76,15 +76,6 @@ player_wait_decoder(struct player_control *pc, struct decoder_control *dc) g_cond_wait(pc->cond, dc->mutex); } -void -pc_song_deleted(struct player_control *pc, const struct song *song) -{ - if (pc->errored_song == song) { - pc->error_type = PLAYER_ERROR_NONE; - pc->errored_song = NULL; - } -} - static void player_command_wait_locked(struct player_control *pc) { @@ -229,42 +220,42 @@ pc_get_status(struct player_control *pc, struct player_status *status) } void -pc_clear_error(struct player_control *pc) +pc_set_error(struct player_control *pc, enum player_error type, + GError *error) { - player_lock(pc); - pc->error_type = PLAYER_ERROR_NONE; - pc->errored_song = NULL; - player_unlock(pc); + assert(pc != NULL); + assert(type != PLAYER_ERROR_NONE); + assert(error != NULL); + + if (pc->error_type != PLAYER_ERROR_NONE) + g_error_free(pc->error); + + pc->error_type = type; + pc->error = error; } -static char * -pc_errored_song_uri(struct player_control *pc) +void +pc_clear_error(struct player_control *pc) { - return song_get_uri(pc->errored_song); + player_lock(pc); + + if (pc->error_type != PLAYER_ERROR_NONE) { + pc->error_type = PLAYER_ERROR_NONE; + g_error_free(pc->error); + } + + player_unlock(pc); } char * pc_get_error_message(struct player_control *pc) { - char *error; - char *uri; - - switch (pc->error_type) { - case PLAYER_ERROR_NONE: - return NULL; - - case PLAYER_ERROR_DECODER: - uri = pc_errored_song_uri(pc); - error = g_strdup_printf("problems decoding \"%s\"", uri); - g_free(uri); - return error; - - case PLAYER_ERROR_OUTPUT: - return g_strdup("problems opening audio device"); - } - - assert(false); - return NULL; + player_lock(pc); + char *message = pc->error_type != PLAYER_ERROR_NONE + ? g_strdup(pc->error->message) + : NULL; + player_unlock(pc); + return message; } static void -- cgit v1.2.3