PlayerControl: GetError() returns an Error, not a char*

This commit is contained in:
Max Kellermann 2013-10-17 19:34:59 +02:00
parent 8e676db633
commit ffea268d2e
3 changed files with 26 additions and 25 deletions

View File

@ -32,8 +32,6 @@
#include "AudioFormat.hxx" #include "AudioFormat.hxx"
#include "ReplayGainConfig.hxx" #include "ReplayGainConfig.hxx"
#include <glib.h>
#define COMMAND_STATUS_STATE "state" #define COMMAND_STATUS_STATE "state"
#define COMMAND_STATUS_REPEAT "repeat" #define COMMAND_STATUS_REPEAT "repeat"
#define COMMAND_STATUS_SINGLE "single" #define COMMAND_STATUS_SINGLE "single"
@ -190,13 +188,11 @@ handle_status(Client *client,
updateJobId); updateJobId);
} }
char *error = client->player_control->GetErrorMessage(); Error error = client->player_control->LockGetError();
if (error != NULL) { if (error.IsDefined())
client_printf(client, client_printf(client,
COMMAND_STATUS_ERROR ": %s\n", COMMAND_STATUS_ERROR ": %s\n",
error); error.GetMessage());
g_free(error);
}
song = playlist.GetNextPosition(); song = playlist.GetNextPosition();
if (song >= 0) { if (song >= 0) {

View File

@ -23,8 +23,6 @@
#include "Song.hxx" #include "Song.hxx"
#include "DecoderControl.hxx" #include "DecoderControl.hxx"
#include <glib.h>
#include <cmath> #include <cmath>
#include <assert.h> #include <assert.h>
@ -202,17 +200,6 @@ player_control::ClearError()
Unlock(); Unlock();
} }
char *
player_control::GetErrorMessage() const
{
Lock();
char *message = error_type != PlayerError::NONE
? g_strdup(error.GetMessage())
: NULL;
Unlock();
return message;
}
void void
player_control::EnqueueSong(Song *song) player_control::EnqueueSong(Song *song)
{ {

View File

@ -325,14 +325,32 @@ public:
*/ */
void SetError(PlayerError type, Error &&error); 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 * Like GetError(), but locks and unlocks the object.
* error during playback, NULL if no error occurred. The
* caller has to free the returned string.
*/ */
char *GetErrorMessage() const; gcc_pure
Error LockGetError() const {
Lock();
Error result = GetError();
Unlock();
return result;
}
void ClearError();
PlayerError GetErrorType() const { PlayerError GetErrorType() const {
return error_type; return error_type;