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
6ed77f2a
Commit
6ed77f2a
authored
Sep 05, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input/Plugin: migrate init() from class Error to C++ exceptions
parent
a73688a2
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
55 additions
and
99 deletions
+55
-99
Main.cxx
src/Main.cxx
+1
-6
Init.cxx
src/input/Init.cxx
+4
-21
Init.hxx
src/input/Init.hxx
+2
-2
InputPlugin.hxx
src/input/InputPlugin.hxx
+3
-15
CdioParanoiaInputPlugin.cxx
src/input/plugins/CdioParanoiaInputPlugin.cxx
+6
-10
CurlInputPlugin.cxx
src/input/plugins/CurlInputPlugin.cxx
+2
-3
FfmpegInputPlugin.cxx
src/input/plugins/FfmpegInputPlugin.cxx
+2
-5
NfsInputPlugin.cxx
src/input/plugins/NfsInputPlugin.cxx
+2
-3
SmbclientInputPlugin.cxx
src/input/plugins/SmbclientInputPlugin.cxx
+2
-4
dump_playlist.cxx
test/dump_playlist.cxx
+1
-5
dump_text_file.cxx
test/dump_text_file.cxx
+7
-5
read_tags.cxx
test/read_tags.cxx
+7
-6
run_decoder.cxx
test/run_decoder.cxx
+1
-4
run_input.cxx
test/run_input.cxx
+7
-5
visit_archive.cxx
test/visit_archive.cxx
+8
-5
No files found.
src/Main.cxx
View file @
6ed77f2a
...
@@ -536,12 +536,7 @@ try {
...
@@ -536,12 +536,7 @@ try {
instance
->
partition
->
pc
);
instance
->
partition
->
pc
);
client_manager_init
();
client_manager_init
();
replay_gain_global_init
();
replay_gain_global_init
();
input_stream_global_init
();
if
(
!
input_stream_global_init
(
error
))
{
LogError
(
error
);
return
EXIT_FAILURE
;
}
playlist_list_global_init
();
playlist_list_global_init
();
#ifdef ENABLE_DAEMON
#ifdef ENABLE_DAEMON
...
...
src/input/Init.cxx
View file @
6ed77f2a
...
@@ -21,7 +21,6 @@
...
@@ -21,7 +21,6 @@
#include "Init.hxx"
#include "Init.hxx"
#include "Registry.hxx"
#include "Registry.hxx"
#include "InputPlugin.hxx"
#include "InputPlugin.hxx"
#include "util/Error.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/ConfigOption.hxx"
#include "config/ConfigOption.hxx"
#include "config/Block.hxx"
#include "config/Block.hxx"
...
@@ -33,8 +32,8 @@
...
@@ -33,8 +32,8 @@
#include <assert.h>
#include <assert.h>
bool
void
input_stream_global_init
(
Error
&
error
)
input_stream_global_init
()
{
{
const
ConfigBlock
empty
;
const
ConfigBlock
empty
;
...
@@ -54,12 +53,9 @@ input_stream_global_init(Error &error)
...
@@ -54,12 +53,9 @@ input_stream_global_init(Error &error)
/* the plugin is disabled in mpd.conf */
/* the plugin is disabled in mpd.conf */
continue
;
continue
;
InputPlugin
::
InitResult
result
;
try
{
try
{
result
=
plugin
->
init
!=
nullptr
if
(
plugin
->
init
!=
nullptr
)
?
plugin
->
init
(
*
block
,
error
)
plugin
->
init
(
*
block
);
:
InputPlugin
::
InitResult
::
SUCCESS
;
}
catch
(
const
PluginUnavailable
&
e
)
{
}
catch
(
const
PluginUnavailable
&
e
)
{
FormatError
(
e
,
FormatError
(
e
,
"Input plugin '%s' is unavailable"
,
"Input plugin '%s' is unavailable"
,
...
@@ -69,20 +65,7 @@ input_stream_global_init(Error &error)
...
@@ -69,20 +65,7 @@ input_stream_global_init(Error &error)
std
::
throw_with_nested
(
FormatRuntimeError
(
"Failed to initialize input plugin '%s'"
,
std
::
throw_with_nested
(
FormatRuntimeError
(
"Failed to initialize input plugin '%s'"
,
plugin
->
name
));
plugin
->
name
));
}
}
switch
(
result
)
{
case
InputPlugin
:
:
InitResult
::
SUCCESS
:
input_plugins_enabled
[
i
]
=
true
;
break
;
case
InputPlugin
:
:
InitResult
::
ERROR
:
error
.
FormatPrefix
(
"Failed to initialize input plugin '%s': "
,
plugin
->
name
);
return
false
;
}
}
}
return
true
;
}
}
void
input_stream_global_finish
(
void
)
void
input_stream_global_finish
(
void
)
...
...
src/input/Init.hxx
View file @
6ed77f2a
...
@@ -25,8 +25,8 @@ class Error;
...
@@ -25,8 +25,8 @@ class Error;
/**
/**
* Initializes this library and all #InputStream implementations.
* Initializes this library and all #InputStream implementations.
*/
*/
bool
void
input_stream_global_init
(
Error
&
error
);
input_stream_global_init
();
/**
/**
* Deinitializes this library and all #InputStream implementations.
* Deinitializes this library and all #InputStream implementations.
...
...
src/input/InputPlugin.hxx
View file @
6ed77f2a
...
@@ -40,20 +40,6 @@ class Error;
...
@@ -40,20 +40,6 @@ class Error;
struct
Tag
;
struct
Tag
;
struct
InputPlugin
{
struct
InputPlugin
{
enum
class
InitResult
{
/**
* A fatal error has occurred (e.g. misconfiguration).
* The #Error has been set.
*/
ERROR
,
/**
* The plugin was initialized successfully and is
* ready to be used.
*/
SUCCESS
,
};
const
char
*
name
;
const
char
*
name
;
/**
/**
...
@@ -61,8 +47,10 @@ struct InputPlugin {
...
@@ -61,8 +47,10 @@ struct InputPlugin {
*
*
* Throws #PluginUnavailable if the plugin is not available
* Throws #PluginUnavailable if the plugin is not available
* and shall be disabled.
* and shall be disabled.
*
* Throws std::runtime_error on (fatal) error.
*/
*/
InitResult
(
*
init
)(
const
ConfigBlock
&
block
,
Error
&
error
);
void
(
*
init
)(
const
ConfigBlock
&
block
);
/**
/**
* Global deinitialization. Called once before MPD shuts
* Global deinitialization. Called once before MPD shuts
...
...
src/input/plugins/CdioParanoiaInputPlugin.cxx
View file @
6ed77f2a
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
#include "../InputPlugin.hxx"
#include "../InputPlugin.hxx"
#include "util/StringUtil.hxx"
#include "util/StringUtil.hxx"
#include "util/StringCompare.hxx"
#include "util/StringCompare.hxx"
#include "util/RuntimeError.hxx"
#include "util/Error.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "util/Domain.hxx"
#include "system/ByteOrder.hxx"
#include "system/ByteOrder.hxx"
...
@@ -105,8 +106,8 @@ static constexpr Domain cdio_domain("cdio");
...
@@ -105,8 +106,8 @@ static constexpr Domain cdio_domain("cdio");
static
bool
default_reverse_endian
;
static
bool
default_reverse_endian
;
static
InputPlugin
::
InitResult
static
void
input_cdio_init
(
const
ConfigBlock
&
block
,
Error
&
error
)
input_cdio_init
(
const
ConfigBlock
&
block
)
{
{
const
char
*
value
=
block
.
GetBlockValue
(
"default_byte_order"
);
const
char
*
value
=
block
.
GetBlockValue
(
"default_byte_order"
);
if
(
value
!=
nullptr
)
{
if
(
value
!=
nullptr
)
{
...
@@ -114,15 +115,10 @@ input_cdio_init(const ConfigBlock &block, Error &error)
...
@@ -114,15 +115,10 @@ input_cdio_init(const ConfigBlock &block, Error &error)
default_reverse_endian
=
IsBigEndian
();
default_reverse_endian
=
IsBigEndian
();
else
if
(
strcmp
(
value
,
"big_endian"
)
==
0
)
else
if
(
strcmp
(
value
,
"big_endian"
)
==
0
)
default_reverse_endian
=
IsLittleEndian
();
default_reverse_endian
=
IsLittleEndian
();
else
{
else
error
.
Format
(
config_domain
,
0
,
throw
FormatRuntimeError
(
"Unrecognized 'default_byte_order' setting: %s"
,
"Unrecognized 'default_byte_order' setting: %s"
,
value
);
value
);
return
InputPlugin
::
InitResult
::
ERROR
;
}
}
}
return
InputPlugin
::
InitResult
::
SUCCESS
;
}
}
struct
cdio_uri
{
struct
cdio_uri
{
...
...
src/input/plugins/CurlInputPlugin.cxx
View file @
6ed77f2a
...
@@ -533,8 +533,8 @@ CurlMulti::OnTimeout()
...
@@ -533,8 +533,8 @@ CurlMulti::OnTimeout()
*
*
*/
*/
static
InputPlugin
::
InitResult
static
void
input_curl_init
(
const
ConfigBlock
&
block
,
gcc_unused
Error
&
error
)
input_curl_init
(
const
ConfigBlock
&
block
)
{
{
CURLcode
code
=
curl_global_init
(
CURL_GLOBAL_ALL
);
CURLcode
code
=
curl_global_init
(
CURL_GLOBAL_ALL
);
if
(
code
!=
CURLE_OK
)
if
(
code
!=
CURLE_OK
)
...
@@ -577,7 +577,6 @@ input_curl_init(const ConfigBlock &block, gcc_unused Error &error)
...
@@ -577,7 +577,6 @@ input_curl_init(const ConfigBlock &block, gcc_unused Error &error)
}
}
curl_multi
=
new
CurlMulti
(
io_thread_get
(),
multi
);
curl_multi
=
new
CurlMulti
(
io_thread_get
(),
multi
);
return
InputPlugin
::
InitResult
::
SUCCESS
;
}
}
static
void
static
void
...
...
src/input/plugins/FfmpegInputPlugin.cxx
View file @
6ed77f2a
...
@@ -72,17 +72,14 @@ input_ffmpeg_supported(void)
...
@@ -72,17 +72,14 @@ input_ffmpeg_supported(void)
return
avio_enum_protocols
(
&
opaque
,
0
)
!=
nullptr
;
return
avio_enum_protocols
(
&
opaque
,
0
)
!=
nullptr
;
}
}
static
InputPlugin
::
InitResult
static
void
input_ffmpeg_init
(
gcc_unused
const
ConfigBlock
&
block
,
input_ffmpeg_init
(
gcc_unused
const
ConfigBlock
&
block
)
gcc_unused
Error
&
error
)
{
{
FfmpegInit
();
FfmpegInit
();
/* disable this plugin if there's no registered protocol */
/* disable this plugin if there's no registered protocol */
if
(
!
input_ffmpeg_supported
())
if
(
!
input_ffmpeg_supported
())
throw
PluginUnavailable
(
"No protocol"
);
throw
PluginUnavailable
(
"No protocol"
);
return
InputPlugin
::
InitResult
::
SUCCESS
;
}
}
static
InputStream
*
static
InputStream
*
...
...
src/input/plugins/NfsInputPlugin.cxx
View file @
6ed77f2a
...
@@ -215,11 +215,10 @@ NfsInputStream::OnNfsFileError(Error &&error)
...
@@ -215,11 +215,10 @@ NfsInputStream::OnNfsFileError(Error &&error)
*
*
*/
*/
static
InputPlugin
::
InitResult
static
void
input_nfs_init
(
const
ConfigBlock
&
,
Error
&
)
input_nfs_init
(
const
ConfigBlock
&
)
{
{
nfs_init
();
nfs_init
();
return
InputPlugin
::
InitResult
::
SUCCESS
;
}
}
static
void
static
void
...
...
src/input/plugins/SmbclientInputPlugin.cxx
View file @
6ed77f2a
...
@@ -68,8 +68,8 @@ public:
...
@@ -68,8 +68,8 @@ public:
*
*
*/
*/
static
InputPlugin
::
InitResult
static
void
input_smbclient_init
(
gcc_unused
const
ConfigBlock
&
block
,
gcc_unused
Error
&
error
)
input_smbclient_init
(
gcc_unused
const
ConfigBlock
&
block
)
{
{
try
{
try
{
SmbclientInit
();
SmbclientInit
();
...
@@ -81,8 +81,6 @@ input_smbclient_init(gcc_unused const ConfigBlock &block, gcc_unused Error &erro
...
@@ -81,8 +81,6 @@ input_smbclient_init(gcc_unused const ConfigBlock &block, gcc_unused Error &erro
// TODO: create one global SMBCCTX here?
// TODO: create one global SMBCCTX here?
// TODO: evaluate ConfigBlock, call smbc_setOption*()
// TODO: evaluate ConfigBlock, call smbc_setOption*()
return
InputPlugin
::
InitResult
::
SUCCESS
;
}
}
static
InputStream
*
static
InputStream
*
...
...
test/dump_playlist.cxx
View file @
6ed77f2a
...
@@ -68,11 +68,7 @@ try {
...
@@ -68,11 +68,7 @@ try {
const
ScopeIOThread
io_thread
;
const
ScopeIOThread
io_thread
;
if
(
!
input_stream_global_init
(
error
))
{
input_stream_global_init
();
LogError
(
error
);
return
EXIT_FAILURE
;
}
playlist_list_global_init
();
playlist_list_global_init
();
decoder_plugin_init_all
();
decoder_plugin_init_all
();
...
...
test/dump_text_file.cxx
View file @
6ed77f2a
...
@@ -31,6 +31,8 @@
...
@@ -31,6 +31,8 @@
#include "archive/ArchiveList.hxx"
#include "archive/ArchiveList.hxx"
#endif
#endif
#include <stdexcept>
#include <unistd.h>
#include <unistd.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
...
@@ -63,7 +65,7 @@ dump_input_stream(InputStreamPtr &&is)
...
@@ -63,7 +65,7 @@ dump_input_stream(InputStreamPtr &&is)
}
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
try
{
int
ret
;
int
ret
;
if
(
argc
!=
2
)
{
if
(
argc
!=
2
)
{
...
@@ -82,10 +84,7 @@ int main(int argc, char **argv)
...
@@ -82,10 +84,7 @@ int main(int argc, char **argv)
#endif
#endif
Error
error
;
Error
error
;
if
(
!
input_stream_global_init
(
error
))
{
input_stream_global_init
();
LogError
(
error
);
return
2
;
}
/* open the stream and dump it */
/* open the stream and dump it */
...
@@ -116,4 +115,7 @@ int main(int argc, char **argv)
...
@@ -116,4 +115,7 @@ int main(int argc, char **argv)
config_global_finish
();
config_global_finish
();
return
ret
;
return
ret
;
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
return
EXIT_FAILURE
;
}
}
test/read_tags.cxx
View file @
6ed77f2a
...
@@ -31,6 +31,8 @@
...
@@ -31,6 +31,8 @@
#include "thread/Cond.hxx"
#include "thread/Cond.hxx"
#include "Log.hxx"
#include "Log.hxx"
#include <stdexcept>
#include <assert.h>
#include <assert.h>
#include <unistd.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdlib.h>
...
@@ -68,7 +70,7 @@ static constexpr TagHandler print_handler = {
...
@@ -68,7 +70,7 @@ static constexpr TagHandler print_handler = {
};
};
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
try
{
const
char
*
decoder_name
;
const
char
*
decoder_name
;
const
struct
DecoderPlugin
*
plugin
;
const
struct
DecoderPlugin
*
plugin
;
...
@@ -88,11 +90,7 @@ int main(int argc, char **argv)
...
@@ -88,11 +90,7 @@ int main(int argc, char **argv)
const
ScopeIOThread
io_thread
;
const
ScopeIOThread
io_thread
;
Error
error
;
Error
error
;
if
(
!
input_stream_global_init
(
error
))
{
input_stream_global_init
();
LogError
(
error
);
return
2
;
}
decoder_plugin_init_all
();
decoder_plugin_init_all
();
plugin
=
decoder_plugin_from_name
(
decoder_name
);
plugin
=
decoder_plugin_from_name
(
decoder_name
);
...
@@ -129,4 +127,7 @@ int main(int argc, char **argv)
...
@@ -129,4 +127,7 @@ int main(int argc, char **argv)
ScanGenericTags
(
path
,
print_handler
,
nullptr
);
ScanGenericTags
(
path
,
print_handler
,
nullptr
);
return
0
;
return
0
;
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
return
EXIT_FAILURE
;
}
}
test/run_decoder.cxx
View file @
6ed77f2a
...
@@ -50,10 +50,7 @@ try {
...
@@ -50,10 +50,7 @@ try {
const
ScopeIOThread
io_thread
;
const
ScopeIOThread
io_thread
;
Error
error
;
Error
error
;
if
(
!
input_stream_global_init
(
error
))
{
input_stream_global_init
();
LogError
(
error
);
return
EXIT_FAILURE
;
}
decoder_plugin_init_all
();
decoder_plugin_init_all
();
...
...
test/run_input.cxx
View file @
6ed77f2a
...
@@ -34,6 +34,8 @@
...
@@ -34,6 +34,8 @@
#include "archive/ArchiveList.hxx"
#include "archive/ArchiveList.hxx"
#endif
#endif
#include <stdexcept>
#include <unistd.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdlib.h>
...
@@ -91,7 +93,7 @@ dump_input_stream(InputStream *is)
...
@@ -91,7 +93,7 @@ dump_input_stream(InputStream *is)
}
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
try
{
if
(
argc
!=
2
)
{
if
(
argc
!=
2
)
{
fprintf
(
stderr
,
"Usage: run_input URI
\n
"
);
fprintf
(
stderr
,
"Usage: run_input URI
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
...
@@ -108,10 +110,7 @@ int main(int argc, char **argv)
...
@@ -108,10 +110,7 @@ int main(int argc, char **argv)
#endif
#endif
Error
error
;
Error
error
;
if
(
!
input_stream_global_init
(
error
))
{
input_stream_global_init
();
LogError
(
error
);
return
2
;
}
/* open the stream and dump it */
/* open the stream and dump it */
...
@@ -142,4 +141,7 @@ int main(int argc, char **argv)
...
@@ -142,4 +141,7 @@ int main(int argc, char **argv)
config_global_finish
();
config_global_finish
();
return
ret
;
return
ret
;
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
return
EXIT_FAILURE
;
}
}
test/visit_archive.cxx
View file @
6ed77f2a
...
@@ -28,6 +28,9 @@
...
@@ -28,6 +28,9 @@
#include "archive/ArchiveVisitor.hxx"
#include "archive/ArchiveVisitor.hxx"
#include "fs/Path.hxx"
#include "fs/Path.hxx"
#include "util/Error.hxx"
#include "util/Error.hxx"
#include "Log.hxx"
#include <stdexcept>
#include <unistd.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdlib.h>
...
@@ -42,7 +45,7 @@ class MyArchiveVisitor final : public ArchiveVisitor {
...
@@ -42,7 +45,7 @@ class MyArchiveVisitor final : public ArchiveVisitor {
int
int
main
(
int
argc
,
char
**
argv
)
main
(
int
argc
,
char
**
argv
)
{
try
{
Error
error
;
Error
error
;
if
(
argc
!=
3
)
{
if
(
argc
!=
3
)
{
...
@@ -61,10 +64,7 @@ main(int argc, char **argv)
...
@@ -61,10 +64,7 @@ main(int argc, char **argv)
archive_plugin_init_all
();
archive_plugin_init_all
();
if
(
!
input_stream_global_init
(
error
))
{
input_stream_global_init
();
fprintf
(
stderr
,
"%s"
,
error
.
GetMessage
());
return
2
;
}
/* open the archive and dump it */
/* open the archive and dump it */
...
@@ -95,4 +95,7 @@ main(int argc, char **argv)
...
@@ -95,4 +95,7 @@ main(int argc, char **argv)
config_global_finish
();
config_global_finish
();
return
result
;
return
result
;
}
catch
(
const
std
::
exception
&
e
)
{
LogError
(
e
);
return
EXIT_FAILURE
;
}
}
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