configure.ac: Add subheaders to Input/Sticker/Autodiscovery/Metadata and Misc.
[mpd-mk.git] / src / input_init.c
blob1438c3e52b7185fa2c2c3c07f891c4bb8867cdf1
1 /*
2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "config.h"
21 #include "input_init.h"
22 #include "input_plugin.h"
23 #include "input_registry.h"
24 #include "conf.h"
25 #include "glib_compat.h"
27 #include <string.h>
29 static inline GQuark
30 input_quark(void)
32 return g_quark_from_static_string("input");
35 /**
36 * Find the "input" configuration block for the specified plugin.
38 * @param plugin_name the name of the input plugin
39 * @return the configuration block, or NULL if none was configured
41 static const struct config_param *
42 input_plugin_config(const char *plugin_name, GError **error_r)
44 const struct config_param *param = NULL;
46 while ((param = config_get_next_param(CONF_INPUT, param)) != NULL) {
47 const char *name =
48 config_get_block_string(param, "plugin", NULL);
49 if (name == NULL) {
50 g_set_error(error_r, input_quark(), 0,
51 "input configuration without 'plugin' name in line %d",
52 param->line);
53 return NULL;
56 if (strcmp(name, plugin_name) == 0)
57 return param;
60 return NULL;
63 bool
64 input_stream_global_init(GError **error_r)
66 GError *error = NULL;
68 for (unsigned i = 0; input_plugins[i] != NULL; ++i) {
69 const struct input_plugin *plugin = input_plugins[i];
70 const struct config_param *param =
71 input_plugin_config(plugin->name, &error);
72 if (param == NULL && error != NULL) {
73 g_propagate_error(error_r, error);
74 return false;
77 if (!config_get_block_bool(param, "enabled", true))
78 /* the plugin is disabled in mpd.conf */
79 continue;
81 if (plugin->init == NULL || plugin->init(param, &error))
82 input_plugins_enabled[i] = true;
83 else {
84 g_propagate_prefixed_error(error_r, error,
85 "Failed to initialize input plugin '%s': ",
86 plugin->name);
87 return false;
91 return true;
94 void input_stream_global_finish(void)
96 for (unsigned i = 0; input_plugins[i] != NULL; ++i)
97 if (input_plugins_enabled[i] &&
98 input_plugins[i]->finish != NULL)
99 input_plugins[i]->finish();