output_init: return GError on error
Do error handling with GError instead of aborting with g_error().
This commit is contained in:
parent
cb942eeb45
commit
f298fcf3a6
@ -77,6 +77,7 @@ audio_output_all_init(void)
|
||||
{
|
||||
const struct config_param *param = NULL;
|
||||
unsigned int i;
|
||||
GError *error = NULL;
|
||||
|
||||
notify_init(&audio_output_client_notify);
|
||||
|
||||
@ -93,18 +94,8 @@ audio_output_all_init(void)
|
||||
/* only allow param to be NULL if there just one audioOutput */
|
||||
assert(param || (num_audio_outputs == 1));
|
||||
|
||||
if (!audio_output_init(output, param)) {
|
||||
if (param)
|
||||
{
|
||||
g_error("problems configuring output device "
|
||||
"defined at line %i\n", param->line);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_error("No audio_output specified and unable to "
|
||||
"detect a default audio output device\n");
|
||||
}
|
||||
}
|
||||
if (!audio_output_init(output, param, &error))
|
||||
g_error("line %i: %s", param->line, error->message);
|
||||
|
||||
/* require output names to be unique: */
|
||||
for (j = 0; j < i; j++) {
|
||||
|
@ -19,6 +19,8 @@
|
||||
#ifndef MPD_OUTPUT_CONTROL_H
|
||||
#define MPD_OUTPUT_CONTROL_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
@ -27,8 +29,15 @@ struct audio_format;
|
||||
struct tag;
|
||||
struct config_param;
|
||||
|
||||
static inline GQuark
|
||||
audio_output_quark(void)
|
||||
{
|
||||
return g_quark_from_static_string("audio_output");
|
||||
}
|
||||
|
||||
bool
|
||||
audio_output_init(struct audio_output *ao, const struct config_param *param);
|
||||
audio_output_init(struct audio_output *ao, const struct config_param *param,
|
||||
GError **error);
|
||||
|
||||
bool
|
||||
audio_output_open(struct audio_output *ao,
|
||||
|
@ -42,7 +42,7 @@
|
||||
}
|
||||
|
||||
static const struct audio_output_plugin *
|
||||
audio_output_detect(void)
|
||||
audio_output_detect(GError **error)
|
||||
{
|
||||
const struct audio_output_plugin *plugin;
|
||||
unsigned i;
|
||||
@ -59,17 +59,19 @@ audio_output_detect(void)
|
||||
return plugin;
|
||||
}
|
||||
|
||||
g_set_error(error, audio_output_quark(), 0,
|
||||
"Unable to detect an audio device");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool
|
||||
audio_output_init(struct audio_output *ao, const struct config_param *param)
|
||||
audio_output_init(struct audio_output *ao, const struct config_param *param,
|
||||
GError **error)
|
||||
{
|
||||
const char *name = NULL;
|
||||
char *format = NULL;
|
||||
struct block_param *bp = NULL;
|
||||
const struct audio_output_plugin *plugin = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
if (param) {
|
||||
const char *type = NULL;
|
||||
@ -80,18 +82,18 @@ audio_output_init(struct audio_output *ao, const struct config_param *param)
|
||||
|
||||
plugin = audio_output_plugin_get(type);
|
||||
if (plugin == NULL) {
|
||||
g_error("couldn't find audio output plugin for type "
|
||||
"\"%s\" at line %i\n", type, param->line);
|
||||
g_set_error(error, audio_output_quark(), 0,
|
||||
"No such audio output plugin: %s",
|
||||
type);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
g_warning("No \"%s\" defined in config file\n",
|
||||
CONF_AUDIO_OUTPUT);
|
||||
|
||||
plugin = audio_output_detect();
|
||||
if (plugin == NULL) {
|
||||
g_warning("Unable to detect an audio device");
|
||||
plugin = audio_output_detect(error);
|
||||
if (plugin == NULL)
|
||||
return false;
|
||||
}
|
||||
|
||||
g_message("Successfully detected a %s audio device",
|
||||
plugin->name);
|
||||
@ -111,10 +113,9 @@ audio_output_init(struct audio_output *ao, const struct config_param *param)
|
||||
bool ret;
|
||||
|
||||
ret = audio_format_parse(&ao->config_audio_format, format,
|
||||
&error);
|
||||
error);
|
||||
if (!ret)
|
||||
g_error("error parsing format at line %i: %s",
|
||||
bp->line, error->message);
|
||||
return false;
|
||||
} else
|
||||
audio_format_clear(&ao->config_audio_format);
|
||||
|
||||
@ -124,14 +125,9 @@ audio_output_init(struct audio_output *ao, const struct config_param *param)
|
||||
|
||||
ao->data = ao_plugin_init(plugin,
|
||||
format ? &ao->config_audio_format : NULL,
|
||||
param, &error);
|
||||
if (ao->data == NULL) {
|
||||
g_warning("Failed to initialize \"%s\" [%s]: %s",
|
||||
ao->name, ao->plugin->name,
|
||||
error->message);
|
||||
g_error_free(error);
|
||||
param, error);
|
||||
if (ao->data == NULL)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user