aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-03-01 13:31:56 +0100
committerMax Kellermann <max@duempel.org>2009-03-01 13:31:56 +0100
commitf298fcf3a651b9c072f1fa7242b4ff30141c6fe5 (patch)
treee5a0b55fa7c4ec21ee02c696cee902fa95ce441e
parentcb942eeb45e15d6b471625629dcb324e625cfac7 (diff)
downloadmpd-f298fcf3a651b9c072f1fa7242b4ff30141c6fe5.tar.gz
mpd-f298fcf3a651b9c072f1fa7242b4ff30141c6fe5.tar.xz
mpd-f298fcf3a651b9c072f1fa7242b4ff30141c6fe5.zip
output_init: return GError on error
Do error handling with GError instead of aborting with g_error().
-rw-r--r--src/output_all.c15
-rw-r--r--src/output_control.h11
-rw-r--r--src/output_init.c34
3 files changed, 28 insertions, 32 deletions
diff --git a/src/output_all.c b/src/output_all.c
index 953a11bd5..e360fd5ae 100644
--- a/src/output_all.c
+++ b/src/output_all.c
@@ -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++) {
diff --git a/src/output_control.h b/src/output_control.h
index 390c2b889..a4287646c 100644
--- a/src/output_control.h
+++ b/src/output_control.h
@@ -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,
diff --git a/src/output_init.c b/src/output_init.c
index 4c052d943..c938d7eeb 100644
--- a/src/output_init.c
+++ b/src/output_init.c
@@ -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;
}