diff options
author | Max Kellermann <max@duempel.org> | 2012-08-08 22:18:08 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-08-08 22:54:49 +0200 |
commit | d488d796f45a89eb20ef1f8dba6824706e1384d9 (patch) | |
tree | 5c46fe1ed382a6863566c0b1092938c45cfa9d93 /src/player_control.c | |
parent | f794b1e1aac61fd2e6f4758e0cebfcd8d15706be (diff) | |
download | mpd-d488d796f45a89eb20ef1f8dba6824706e1384d9.tar.gz mpd-d488d796f45a89eb20ef1f8dba6824706e1384d9.tar.xz mpd-d488d796f45a89eb20ef1f8dba6824706e1384d9.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | src/player_control.c | 63 |
1 files changed, 27 insertions, 36 deletions
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 |