Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
0ce72cbf
Commit
0ce72cbf
authored
Sep 08, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
player/Control: convert error from Error to std::exception_ptr
Prepare full C++ exception support in the player thread.
parent
6e52ab28
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
23 deletions
+38
-23
PlayerCommands.cxx
src/command/PlayerCommands.cxx
+10
-4
Control.cxx
src/player/Control.cxx
+15
-5
Control.hxx
src/player/Control.hxx
+13
-14
No files found.
src/command/PlayerCommands.cxx
View file @
0ce72cbf
...
...
@@ -32,6 +32,7 @@
#include "AudioFormat.hxx"
#include "ReplayGainConfig.hxx"
#include "util/ScopeExit.hxx"
#include "util/Error.hxx"
#ifdef ENABLE_DATABASE
#include "db/update/Service.hxx"
...
...
@@ -191,10 +192,15 @@ handle_status(Client &client, gcc_unused Request args, Response &r)
}
#endif
Error
error
=
client
.
player_control
.
LockGetError
();
if
(
error
.
IsDefined
())
r
.
Format
(
COMMAND_STATUS_ERROR
": %s
\n
"
,
error
.
GetMessage
());
try
{
client
.
player_control
.
LockCheckRethrowError
();
}
catch
(
const
std
::
exception
&
e
)
{
r
.
Format
(
COMMAND_STATUS_ERROR
": %s
\n
"
,
e
.
what
());
}
catch
(
const
Error
&
error
)
{
r
.
Format
(
COMMAND_STATUS_ERROR
": %s
\n
"
,
error
.
GetMessage
());
}
catch
(...)
{
r
.
Format
(
COMMAND_STATUS_ERROR
": unknown
\n
"
);
}
song
=
playlist
.
GetNextPosition
();
if
(
song
>=
0
)
...
...
src/player/Control.cxx
View file @
0ce72cbf
...
...
@@ -21,6 +21,7 @@
#include "Control.hxx"
#include "Idle.hxx"
#include "DetachedSong.hxx"
#include "util/Error.hxx"
#include <algorithm>
...
...
@@ -161,16 +162,25 @@ PlayerControl::LockGetStatus()
}
void
PlayerControl
::
SetError
(
PlayerError
type
,
Erro
r
&&
_error
)
PlayerControl
::
SetError
(
PlayerError
type
,
std
::
exception_pt
r
&&
_error
)
{
assert
(
type
!=
PlayerError
::
NONE
);
assert
(
_error
.
IsDefined
()
);
assert
(
_error
);
error_type
=
type
;
error
=
std
::
move
(
_error
);
}
void
PlayerControl
::
SetError
(
PlayerError
type
,
Error
&&
_error
)
{
assert
(
type
!=
PlayerError
::
NONE
);
assert
(
_error
.
IsDefined
());
SetError
(
type
,
std
::
make_exception_ptr
(
std
::
move
(
_error
)));
}
void
PlayerControl
::
LockClearError
()
{
const
ScopeLock
protect
(
mutex
);
...
...
@@ -223,11 +233,11 @@ PlayerControl::SeekLocked(DetachedSong *song, SongTime t)
assert
(
next_song
==
nullptr
);
if
(
error_type
!=
PlayerError
::
NONE
)
{
assert
(
error
.
IsDefined
()
);
throw
error
;
assert
(
error
);
std
::
rethrow_exception
(
error
)
;
}
assert
(
!
error
.
IsDefined
()
);
assert
(
!
error
);
}
void
...
...
src/player/Control.hxx
View file @
0ce72cbf
...
...
@@ -24,12 +24,14 @@
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "thread/Thread.hxx"
#include "util/Error.hxx"
#include "CrossFade.hxx"
#include "Chrono.hxx"
#include <exception>
#include <stdint.h>
class
Error
;
class
PlayerListener
;
class
MultipleOutputs
;
class
DetachedSong
;
...
...
@@ -135,7 +137,7 @@ struct PlayerControl {
* #PlayerError::NONE. The object must be freed when this
* object transitions back to #PlayerError::NONE.
*/
Erro
r
error
;
std
::
exception_pt
r
error
;
/**
* A copy of the current #DetachedSong after its tags have
...
...
@@ -327,7 +329,7 @@ private:
void
ClearError
()
{
error_type
=
PlayerError
::
NONE
;
error
.
Clea
r
();
error
=
std
::
exception_pt
r
();
}
public
:
...
...
@@ -356,28 +358,25 @@ public:
* @param error detailed error information; must be defined.
*/
void
SetError
(
PlayerError
type
,
Error
&&
error
);
void
SetError
(
PlayerError
type
,
std
::
exception_ptr
&&
_error
);
/**
* Checks whether an error has occurred, and if so, ret
urns a
*
copy of the #Error objec
t.
* Checks whether an error has occurred, and if so, ret
hrows
*
i
t.
*
* Caller must lock the object.
*/
gcc_pure
Error
GetError
()
const
{
Error
result
;
void
CheckRethrowError
()
const
{
if
(
error_type
!=
PlayerError
::
NONE
)
result
.
Set
(
error
);
return
result
;
std
::
rethrow_exception
(
error
);
}
/**
* Like
Get
Error(), but locks and unlocks the object.
* Like
CheckRethrow
Error(), but locks and unlocks the object.
*/
gcc_pure
Error
LockGetError
()
const
{
void
LockCheckRethrowError
()
const
{
const
ScopeLock
protect
(
mutex
);
return
Get
Error
();
CheckRethrow
Error
();
}
void
LockClearError
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment