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
a73688a2
Commit
a73688a2
authored
Sep 09, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
input/Plugin: remove InitResult::UNAVAILABLE, throw PluginUnavailable instead
parent
e7d32722
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
57 additions
and
34 deletions
+57
-34
Makefile.am
Makefile.am
+1
-0
PluginUnavailable.hxx
src/PluginUnavailable.hxx
+36
-0
Init.cxx
src/input/Init.cxx
+6
-10
InputPlugin.hxx
src/input/InputPlugin.hxx
+2
-9
CurlInputPlugin.cxx
src/input/plugins/CurlInputPlugin.cxx
+5
-9
FfmpegInputPlugin.cxx
src/input/plugins/FfmpegInputPlugin.cxx
+4
-5
SmbclientInputPlugin.cxx
src/input/plugins/SmbclientInputPlugin.cxx
+3
-1
No files found.
Makefile.am
View file @
a73688a2
...
...
@@ -166,6 +166,7 @@ libmpd_a_SOURCES = \
src/queue/PlaylistTag.cxx
\
src/queue/PlaylistState.cxx src/queue/PlaylistState.hxx
\
src/queue/Listener.hxx
\
src/PluginUnavailable.hxx
\
src/ReplayGainConfig.cxx src/ReplayGainConfig.hxx
\
src/ReplayGainInfo.cxx src/ReplayGainInfo.hxx
\
src/DetachedSong.cxx src/DetachedSong.hxx
\
...
...
src/PluginUnavailable.hxx
0 → 100644
View file @
a73688a2
/*
* Copyright 2003-2016 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_PLUGIN_UNAVAILABLE_HXX
#define MPD_PLUGIN_UNAVAILABLE_HXX
#include <stdexcept>
/**
* An exception class which is used by plugin initializers to indicate
* that this plugin is unavailable. It will be disabled, and MPD can
* continue initialization.
*/
class
PluginUnavailable
final
:
public
std
::
runtime_error
{
public
:
explicit
PluginUnavailable
(
const
char
*
msg
)
:
std
::
runtime_error
(
msg
)
{}
};
#endif
src/input/Init.cxx
View file @
a73688a2
...
...
@@ -26,6 +26,7 @@
#include "config/ConfigOption.hxx"
#include "config/Block.hxx"
#include "Log.hxx"
#include "PluginUnavailable.hxx"
#include "util/RuntimeError.hxx"
#include <stdexcept>
...
...
@@ -59,6 +60,11 @@ input_stream_global_init(Error &error)
result
=
plugin
->
init
!=
nullptr
?
plugin
->
init
(
*
block
,
error
)
:
InputPlugin
::
InitResult
::
SUCCESS
;
}
catch
(
const
PluginUnavailable
&
e
)
{
FormatError
(
e
,
"Input plugin '%s' is unavailable"
,
plugin
->
name
);
continue
;
}
catch
(
const
std
::
runtime_error
&
e
)
{
std
::
throw_with_nested
(
FormatRuntimeError
(
"Failed to initialize input plugin '%s'"
,
plugin
->
name
));
...
...
@@ -73,16 +79,6 @@ input_stream_global_init(Error &error)
error
.
FormatPrefix
(
"Failed to initialize input plugin '%s': "
,
plugin
->
name
);
return
false
;
case
InputPlugin
:
:
InitResult
::
UNAVAILABLE
:
if
(
error
.
IsDefined
())
{
FormatError
(
error
,
"Input plugin '%s' is unavailable"
,
plugin
->
name
);
error
.
Clear
();
}
break
;
}
}
...
...
src/input/InputPlugin.hxx
View file @
a73688a2
...
...
@@ -52,13 +52,6 @@ struct InputPlugin {
* ready to be used.
*/
SUCCESS
,
/**
* The plugin is not available and shall be disabled.
* The #Error may be set describing the situation (to
* be logged).
*/
UNAVAILABLE
,
};
const
char
*
name
;
...
...
@@ -66,8 +59,8 @@ struct InputPlugin {
/**
* Global initialization. This method is called when MPD starts.
*
*
@return true on success, false if the plugin should b
e
*
disabled
*
Throws #PluginUnavailable if the plugin is not availabl
e
*
and shall be disabled.
*/
InitResult
(
*
init
)(
const
ConfigBlock
&
block
,
Error
&
error
);
...
...
src/input/plugins/CurlInputPlugin.cxx
View file @
a73688a2
...
...
@@ -35,6 +35,7 @@
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include "PluginUnavailable.hxx"
#include <assert.h>
#include <string.h>
...
...
@@ -533,15 +534,11 @@ CurlMulti::OnTimeout()
*/
static
InputPlugin
::
InitResult
input_curl_init
(
const
ConfigBlock
&
block
,
Error
&
error
)
input_curl_init
(
const
ConfigBlock
&
block
,
gcc_unused
Error
&
error
)
{
CURLcode
code
=
curl_global_init
(
CURL_GLOBAL_ALL
);
if
(
code
!=
CURLE_OK
)
{
error
.
Format
(
curl_domain
,
code
,
"curl_global_init() failed: %s"
,
curl_easy_strerror
(
code
));
return
InputPlugin
::
InitResult
::
UNAVAILABLE
;
}
if
(
code
!=
CURLE_OK
)
throw
PluginUnavailable
(
curl_easy_strerror
(
code
));
const
auto
version_info
=
curl_version_info
(
CURLVERSION_FIRST
);
if
(
version_info
!=
nullptr
)
{
...
...
@@ -576,8 +573,7 @@ input_curl_init(const ConfigBlock &block, Error &error)
if
(
multi
==
nullptr
)
{
curl_slist_free_all
(
http_200_aliases
);
curl_global_cleanup
();
error
.
Set
(
curl_domain
,
0
,
"curl_multi_init() failed"
);
return
InputPlugin
::
InitResult
::
UNAVAILABLE
;
throw
PluginUnavailable
(
"curl_multi_init() failed"
);
}
curl_multi
=
new
CurlMulti
(
io_thread_get
(),
multi
);
...
...
src/input/plugins/FfmpegInputPlugin.cxx
View file @
a73688a2
...
...
@@ -27,6 +27,7 @@
#include "lib/ffmpeg/Error.hxx"
#include "../InputStream.hxx"
#include "../InputPlugin.hxx"
#include "PluginUnavailable.hxx"
#include "util/StringCompare.hxx"
#include "util/Error.hxx"
...
...
@@ -73,15 +74,13 @@ input_ffmpeg_supported(void)
static
InputPlugin
::
InitResult
input_ffmpeg_init
(
gcc_unused
const
ConfigBlock
&
block
,
Error
&
error
)
gcc_unused
Error
&
error
)
{
FfmpegInit
();
/* disable this plugin if there's no registered protocol */
if
(
!
input_ffmpeg_supported
())
{
error
.
Set
(
ffmpeg_domain
,
"No protocol"
);
return
InputPlugin
::
InitResult
::
UNAVAILABLE
;
}
if
(
!
input_ffmpeg_supported
())
throw
PluginUnavailable
(
"No protocol"
);
return
InputPlugin
::
InitResult
::
SUCCESS
;
}
...
...
src/input/plugins/SmbclientInputPlugin.cxx
View file @
a73688a2
...
...
@@ -23,6 +23,7 @@
#include "lib/smbclient/Mutex.hxx"
#include "../InputStream.hxx"
#include "../InputPlugin.hxx"
#include "PluginUnavailable.hxx"
#include "util/StringCompare.hxx"
#include "util/Error.hxx"
...
...
@@ -73,7 +74,8 @@ input_smbclient_init(gcc_unused const ConfigBlock &block, gcc_unused Error &erro
try
{
SmbclientInit
();
}
catch
(
const
std
::
runtime_error
&
e
)
{
return
InputPlugin
::
InitResult
::
UNAVAILABLE
;
// TODO: use std::throw_with_nested()?
throw
PluginUnavailable
(
e
.
what
());
}
// TODO: create one global SMBCCTX here?
...
...
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