diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/PlayerCommands.cxx | 10 | ||||
-rw-r--r-- | src/PlayerControl.cxx | 13 | ||||
-rw-r--r-- | src/PlayerControl.hxx | 28 |
3 files changed, 26 insertions, 25 deletions
diff --git a/src/PlayerCommands.cxx b/src/PlayerCommands.cxx index 8b69c6597..9f427d121 100644 --- a/src/PlayerCommands.cxx +++ b/src/PlayerCommands.cxx @@ -32,8 +32,6 @@ #include "AudioFormat.hxx" #include "ReplayGainConfig.hxx" -#include <glib.h> - #define COMMAND_STATUS_STATE "state" #define COMMAND_STATUS_REPEAT "repeat" #define COMMAND_STATUS_SINGLE "single" @@ -190,13 +188,11 @@ handle_status(Client *client, updateJobId); } - char *error = client->player_control->GetErrorMessage(); - if (error != NULL) { + Error error = client->player_control->LockGetError(); + if (error.IsDefined()) client_printf(client, COMMAND_STATUS_ERROR ": %s\n", - error); - g_free(error); - } + error.GetMessage()); song = playlist.GetNextPosition(); if (song >= 0) { diff --git a/src/PlayerControl.cxx b/src/PlayerControl.cxx index cf5789f10..e714429d3 100644 --- a/src/PlayerControl.cxx +++ b/src/PlayerControl.cxx @@ -23,8 +23,6 @@ #include "Song.hxx" #include "DecoderControl.hxx" -#include <glib.h> - #include <cmath> #include <assert.h> @@ -202,17 +200,6 @@ player_control::ClearError() Unlock(); } -char * -player_control::GetErrorMessage() const -{ - Lock(); - char *message = error_type != PlayerError::NONE - ? g_strdup(error.GetMessage()) - : NULL; - Unlock(); - return message; -} - void player_control::EnqueueSong(Song *song) { diff --git a/src/PlayerControl.hxx b/src/PlayerControl.hxx index b33462a5c..b2b2087e2 100644 --- a/src/PlayerControl.hxx +++ b/src/PlayerControl.hxx @@ -325,14 +325,32 @@ public: */ void SetError(PlayerError type, Error &&error); - void ClearError(); + /** + * Checks whether an error has occurred, and if so, returns a + * copy of the #Error object. + * + * Caller must lock the object. + */ + gcc_pure + Error GetError() const { + Error result; + if (error_type != PlayerError::NONE) + result.Set(error); + return result; + } /** - * Returns the human-readable message describing the last - * error during playback, NULL if no error occurred. The - * caller has to free the returned string. + * Like GetError(), but locks and unlocks the object. */ - char *GetErrorMessage() const; + gcc_pure + Error LockGetError() const { + Lock(); + Error result = GetError(); + Unlock(); + return result; + } + + void ClearError(); PlayerError GetErrorType() const { return error_type; |