conf: added config_get_block_unsigned()

Eliminate some more getBlockParam() invocations.
This commit is contained in:
Max Kellermann 2009-01-18 19:45:51 +01:00
parent a531a1e650
commit 65f2386b39
6 changed files with 33 additions and 39 deletions

View File

@ -25,6 +25,7 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#define MAX_STRING_SIZE MPD_PATH_MAX+80
@ -457,6 +458,27 @@ config_get_block_string(struct config_param *param, const char *name,
return bp->value;
}
unsigned
config_get_block_unsigned(struct config_param *param, const char *name,
unsigned default_value)
{
struct block_param *bp = getBlockParam(param, name);
long value;
char *endptr;
if (bp == NULL)
return default_value;
value = strtol(bp->value, &endptr, 0);
if (*endptr != 0)
g_error("Not a valid number in line %i", bp->line);
if (value < 0)
g_error("Not a positive number in line %i", bp->line);
return (unsigned)value;
}
bool
config_get_block_bool(struct config_param *param, const char *name,
bool default_value)

View File

@ -125,6 +125,10 @@ config_dup_block_string(struct config_param *param, const char *name,
return g_strdup(config_get_block_string(param, name, default_value));
}
unsigned
config_get_block_unsigned(struct config_param *param, const char *name,
unsigned default_value);
bool
config_get_block_bool(struct config_param *param, const char *name,
bool default_value);

View File

@ -90,16 +90,12 @@ static void freeAlsaData(AlsaData * ad)
static void
alsa_configure(AlsaData *ad, struct config_param *param)
{
struct block_param *bp;
ad->device = config_dup_block_string(param, "device", NULL);
ad->useMmap = config_get_block_bool(param, "use_mmap", false);
if ((bp = getBlockParam(param, "buffer_time")))
ad->buffer_time = atoi(bp->value);
if ((bp = getBlockParam(param, "period_time")))
ad->period_time = atoi(bp->value);
ad->buffer_time = config_get_block_unsigned(param, "buffer_time", 0);
ad->period_time = config_get_block_unsigned(param, "period_time", 0);
#ifdef SND_PCM_NO_AUTO_RESAMPLE
if (!config_get_block_bool(param, "auto_resample", true))

View File

@ -80,19 +80,10 @@ audioOutputAo_initDriver(struct audio_output *ao,
struct config_param *param)
{
ao_info *ai;
char *test;
AoData *ad = newAoData();
struct block_param *blockParam;
const char *value;
if ((blockParam = getBlockParam(param, "write_size"))) {
ad->writeSize = strtol(blockParam->value, &test, 10);
if (*test != '\0') {
g_error("\"%s\" is not a valid write size at line %i\n",
blockParam->value, blockParam->line);
}
} else
ad->writeSize = 1024;
ad->writeSize = config_get_block_unsigned(param, "write_size", 1024);
if (driverInitCount == 0) {
ao_initialize();

View File

@ -187,9 +187,6 @@ mpd_jack_init(struct audio_output *ao,
{
struct jack_data *jd;
const char *value;
struct block_param *bp;
char *endptr;
int val;
jd = mpd_jack_new();
jd->ao = ao;
@ -212,18 +209,8 @@ mpd_jack_init(struct audio_output *ao,
g_free(ports);
}
if ( (bp = getBlockParam(param, "ringbuffer_size")) ) {
errno = 0;
val = strtol(bp->value, &endptr, 10);
if ( errno == 0 && endptr != bp->value) {
jd->ringbuffer_size = val < 32768 ? 32768 : val;
g_debug("ringbuffer_size=%d", jd->ringbuffer_size);
} else {
g_error("%s is not a number; ringbuf_size=%d",
bp->value, jd->ringbuffer_size);
}
}
jd->ringbuffer_size =
config_get_block_unsigned(param, "ringbuffer_size", 32768);
return jd;
}

View File

@ -221,14 +221,8 @@ static void *my_shout_init_driver(struct audio_output *audio_output,
}
/* optional paramters */
block_param = getBlockParam(param, "timeout");
if (block_param) {
sd->timeout = (int)strtol(block_param->value, &test, 10);
if (*test != '\0' || sd->timeout <= 0) {
g_error("shout timeout is not a positive integer, "
"line %i\n", block_param->line);
}
}
sd->timeout = config_get_block_unsigned(param, "timeout",
DEFAULT_CONN_TIMEOUT);
value = config_get_block_string(param, "genre", NULL);
if (value != NULL && shout_set_genre(sd->shout_conn, value)) {