player/Control: use class Error as C++ exception, throw it

This commit is contained in:
Max Kellermann
2016-09-08 10:29:49 +02:00
parent 3da4648112
commit 6e52ab285a
9 changed files with 150 additions and 141 deletions

View File

@@ -49,20 +49,18 @@ PlayerControl::~PlayerControl()
delete tagged_song;
}
bool
PlayerControl::Play(DetachedSong *song, Error &error_r)
void
PlayerControl::Play(DetachedSong *song)
{
assert(song != nullptr);
const ScopeLock protect(mutex);
bool success = SeekLocked(song, SongTime::zero(), error_r);
SeekLocked(song, SongTime::zero());
if (success && state == PlayerState::PAUSE)
if (state == PlayerState::PAUSE)
/* if the player was paused previously, we need to
unpause it */
PauseLocked();
return success;
}
void
@@ -203,8 +201,8 @@ PlayerControl::LockEnqueueSong(DetachedSong *song)
EnqueueSongLocked(song);
}
bool
PlayerControl::SeekLocked(DetachedSong *song, SongTime t, Error &error_r)
void
PlayerControl::SeekLocked(DetachedSong *song, SongTime t)
{
assert(song != nullptr);
@@ -226,28 +224,23 @@ PlayerControl::SeekLocked(DetachedSong *song, SongTime t, Error &error_r)
if (error_type != PlayerError::NONE) {
assert(error.IsDefined());
error_r.Set(error);
return false;
throw error;
}
assert(!error.IsDefined());
return true;
}
bool
PlayerControl::LockSeek(DetachedSong *song, SongTime t, Error &error_r)
void
PlayerControl::LockSeek(DetachedSong *song, SongTime t)
{
assert(song != nullptr);
{
const ScopeLock protect(mutex);
if (!SeekLocked(song, t, error_r))
return false;
SeekLocked(song, t);
}
idle_add(IDLE_PLAYER);
return true;
}
void

View File

@@ -308,10 +308,12 @@ private:
public:
/**
* Throws std::runtime_error or #Error on error.
*
* @param song the song to be queued; the given instance will
* be owned and freed by the player
*/
bool Play(DetachedSong *song, Error &error);
void Play(DetachedSong *song);
/**
* see PlayerCommand::CANCEL
@@ -425,7 +427,10 @@ private:
SynchronousCommand(PlayerCommand::QUEUE);
}
bool SeekLocked(DetachedSong *song, SongTime t, Error &error_r);
/**
* Throws std::runtime_error or #Error on error.
*/
void SeekLocked(DetachedSong *song, SongTime t);
public:
/**
@@ -437,12 +442,12 @@ public:
/**
* Makes the player thread seek the specified song to a position.
*
* Throws std::runtime_error or #Error on error.
*
* @param song the song to be queued; the given instance will be owned
* and freed by the player
* @return true on success, false on failure (e.g. if MPD isn't
* playing currently)
*/
bool LockSeek(DetachedSong *song, SongTime t, Error &error_r);
void LockSeek(DetachedSong *song, SongTime t);
void SetCrossFade(float cross_fade_seconds);