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
9b1fbdbc
Commit
9b1fbdbc
authored
Jan 24, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ConfigGlobal: add config_find_block()
Merge duplicate code.
parent
97391fd4
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
122 deletions
+38
-122
ConfigGlobal.cxx
src/config/ConfigGlobal.cxx
+17
-0
ConfigGlobal.hxx
src/config/ConfigGlobal.hxx
+11
-0
DecoderList.cxx
src/decoder/DecoderList.cxx
+1
-26
FilterConfig.cxx
src/filter/FilterConfig.cxx
+6
-34
Init.cxx
src/input/Init.cxx
+1
-34
PlaylistRegistry.cxx
src/playlist/PlaylistRegistry.cxx
+2
-28
No files found.
src/config/ConfigGlobal.cxx
View file @
9b1fbdbc
...
...
@@ -85,6 +85,23 @@ config_get_next_param(ConfigOption option, const struct config_param * last)
return
param
;
}
const
config_param
*
config_find_block
(
ConfigOption
option
,
const
char
*
key
,
const
char
*
value
)
{
const
config_param
*
param
=
nullptr
;
while
((
param
=
config_get_next_param
(
option
,
param
))
!=
nullptr
)
{
const
char
*
value2
=
param
->
GetBlockValue
(
key
);
if
(
value2
==
nullptr
)
FormatFatalError
(
"block without '%s' name in line %d"
,
key
,
param
->
line
);
if
(
strcmp
(
value2
,
value
)
==
0
)
return
param
;
}
return
nullptr
;
}
const
char
*
config_get_string
(
ConfigOption
option
,
const
char
*
default_value
)
{
...
...
src/config/ConfigGlobal.hxx
View file @
9b1fbdbc
...
...
@@ -53,6 +53,17 @@ config_get_param(enum ConfigOption option)
return
config_get_next_param
(
option
,
nullptr
);
}
/**
* Find a block with a matching attribute.
*
* @param option the blocks to search
* @param key the attribute name
* @param value the expected attribute value
*/
gcc_pure
const
config_param
*
config_find_block
(
ConfigOption
option
,
const
char
*
key
,
const
char
*
value
);
/* Note on gcc_pure: Some of the functions declared pure are not
really pure in strict sense. They have side effect such that they
validate parameter's value and signal an error if it's invalid.
...
...
src/decoder/DecoderList.cxx
View file @
9b1fbdbc
...
...
@@ -43,7 +43,6 @@
#include "plugins/MpcdecDecoderPlugin.hxx"
#include "plugins/FluidsynthDecoderPlugin.hxx"
#include "plugins/SidplayDecoderPlugin.hxx"
#include "system/FatalError.hxx"
#include "util/Macros.hxx"
#include <string.h>
...
...
@@ -126,30 +125,6 @@ decoder_plugin_from_name(const char *name)
});
}
/**
* Find the "decoder" configuration block for the specified plugin.
*
* @param plugin_name the name of the decoder plugin
* @return the configuration block, or nullptr if none was configured
*/
static
const
struct
config_param
*
decoder_plugin_config
(
const
char
*
plugin_name
)
{
const
struct
config_param
*
param
=
nullptr
;
while
((
param
=
config_get_next_param
(
CONF_DECODER
,
param
))
!=
nullptr
)
{
const
char
*
name
=
param
->
GetBlockValue
(
"plugin"
);
if
(
name
==
nullptr
)
FormatFatalError
(
"decoder configuration without 'plugin' name in line %d"
,
param
->
line
);
if
(
strcmp
(
name
,
plugin_name
)
==
0
)
return
param
;
}
return
nullptr
;
}
void
decoder_plugin_init_all
(
void
)
{
struct
config_param
empty
;
...
...
@@ -157,7 +132,7 @@ void decoder_plugin_init_all(void)
for
(
unsigned
i
=
0
;
decoder_plugins
[
i
]
!=
nullptr
;
++
i
)
{
const
DecoderPlugin
&
plugin
=
*
decoder_plugins
[
i
];
const
struct
config_param
*
param
=
decoder_plugin_config
(
plugin
.
name
);
config_find_block
(
CONF_DECODER
,
"plugin"
,
plugin
.
name
);
if
(
param
==
nullptr
)
param
=
&
empty
;
...
...
src/filter/FilterConfig.cxx
View file @
9b1fbdbc
...
...
@@ -31,45 +31,17 @@
#include <string.h>
/**
* Find the "filter" configuration block for the specified name.
*
* @param filter_template_name the name of the filter template
* @param error space to return an error description
* @return the configuration block, or nullptr if none was configured
*/
static
const
struct
config_param
*
filter_plugin_config
(
const
char
*
filter_template_name
,
Error
&
error
)
{
const
struct
config_param
*
param
=
nullptr
;
while
((
param
=
config_get_next_param
(
CONF_AUDIO_FILTER
,
param
))
!=
nullptr
)
{
const
char
*
name
=
param
->
GetBlockValue
(
"name"
);
if
(
name
==
nullptr
)
{
error
.
Format
(
config_domain
,
"filter configuration without 'name' name in line %d"
,
param
->
line
);
return
nullptr
;
}
if
(
strcmp
(
name
,
filter_template_name
)
==
0
)
return
param
;
}
error
.
Format
(
config_domain
,
"filter template not found: %s"
,
filter_template_name
);
return
nullptr
;
}
static
bool
filter_chain_append_new
(
Filter
&
chain
,
const
char
*
template_name
,
Error
&
error
)
{
const
struct
config_param
*
cfg
=
filter_plugin_config
(
template_name
,
error
);
if
(
cfg
==
nullptr
)
// The error has already been set, just stop.
config_find_block
(
CONF_AUDIO_FILTER
,
"name"
,
template_name
);
if
(
cfg
==
nullptr
)
{
error
.
Format
(
config_domain
,
"filter template not found: %s"
,
template_name
);
return
false
;
}
// Instantiate one of those filter plugins with the template name as a hint
Filter
*
f
=
filter_configured_new
(
*
cfg
,
error
);
...
...
src/input/Init.cxx
View file @
9b1fbdbc
...
...
@@ -22,7 +22,6 @@
#include "Registry.hxx"
#include "InputPlugin.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/ConfigOption.hxx"
#include "config/ConfigData.hxx"
...
...
@@ -30,35 +29,6 @@
#include <assert.h>
#include <string.h>
extern
constexpr
Domain
input_domain
(
"input"
);
/**
* Find the "input" configuration block for the specified plugin.
*
* @param plugin_name the name of the input plugin
* @return the configuration block, or nullptr if none was configured
*/
static
const
struct
config_param
*
input_plugin_config
(
const
char
*
plugin_name
,
Error
&
error
)
{
const
struct
config_param
*
param
=
nullptr
;
while
((
param
=
config_get_next_param
(
CONF_INPUT
,
param
))
!=
nullptr
)
{
const
char
*
name
=
param
->
GetBlockValue
(
"plugin"
);
if
(
name
==
nullptr
)
{
error
.
Format
(
input_domain
,
"input configuration without 'plugin' name in line %d"
,
param
->
line
);
return
nullptr
;
}
if
(
strcmp
(
name
,
plugin_name
)
==
0
)
return
param
;
}
return
nullptr
;
}
bool
input_stream_global_init
(
Error
&
error
)
{
...
...
@@ -72,11 +42,8 @@ input_stream_global_init(Error &error)
assert
(
plugin
->
open
!=
nullptr
);
const
struct
config_param
*
param
=
input_plugin_config
(
plugin
->
name
,
error
);
config_find_block
(
CONF_INPUT
,
"plugin"
,
plugin
->
name
);
if
(
param
==
nullptr
)
{
if
(
error
.
IsDefined
())
return
false
;
param
=
&
empty
;
}
else
if
(
!
param
->
GetBlockValue
(
"enabled"
,
true
))
/* the plugin is disabled in mpd.conf */
...
...
src/playlist/PlaylistRegistry.cxx
View file @
9b1fbdbc
...
...
@@ -37,7 +37,6 @@
#include "util/Macros.hxx"
#include "config/ConfigGlobal.hxx"
#include "config/ConfigData.hxx"
#include "system/FatalError.hxx"
#include "Log.hxx"
#include <assert.h>
...
...
@@ -73,32 +72,6 @@ static bool playlist_plugins_enabled[n_playlist_plugins];
playlist_plugins_for_each(plugin) \
if (playlist_plugins_enabled[playlist_plugin_iterator - playlist_plugins])
/**
* Find the "playlist" configuration block for the specified plugin.
*
* @param plugin_name the name of the playlist plugin
* @return the configuration block, or nullptr if none was configured
*/
static
const
struct
config_param
*
playlist_plugin_config
(
const
char
*
plugin_name
)
{
const
struct
config_param
*
param
=
nullptr
;
assert
(
plugin_name
!=
nullptr
);
while
((
param
=
config_get_next_param
(
CONF_PLAYLIST_PLUGIN
,
param
))
!=
nullptr
)
{
const
char
*
name
=
param
->
GetBlockValue
(
"name"
);
if
(
name
==
nullptr
)
FormatFatalError
(
"playlist configuration without 'plugin' name in line %d"
,
param
->
line
);
if
(
strcmp
(
name
,
plugin_name
)
==
0
)
return
param
;
}
return
nullptr
;
}
void
playlist_list_global_init
(
void
)
{
...
...
@@ -107,7 +80,8 @@ playlist_list_global_init(void)
for
(
unsigned
i
=
0
;
playlist_plugins
[
i
]
!=
nullptr
;
++
i
)
{
const
struct
playlist_plugin
*
plugin
=
playlist_plugins
[
i
];
const
struct
config_param
*
param
=
playlist_plugin_config
(
plugin
->
name
);
config_find_block
(
CONF_PLAYLIST_PLUGIN
,
"name"
,
plugin
->
name
);
if
(
param
==
nullptr
)
param
=
&
empty
;
else
if
(
!
param
->
GetBlockValue
(
"enabled"
,
true
))
...
...
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